test: remove redundant color diffing dependency (#33215)
This commit is contained in:
parent
b3fd5eb258
commit
e8ae0571b8
9 changed files with 93 additions and 572 deletions
|
@ -1,15 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>test-color-window</title>
|
||||
<style>
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body id="body">
|
||||
<script src="./renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,61 +0,0 @@
|
|||
const { app, BrowserWindow, desktopCapturer, ipcMain } = require('electron');
|
||||
const getColors = require('get-image-colors');
|
||||
|
||||
const colors = {};
|
||||
|
||||
// Fetch the test window.
|
||||
const getWindow = async () => {
|
||||
const sources = await desktopCapturer.getSources({ types: ['window'] });
|
||||
const filtered = sources.filter(s => s.name === 'test-color-window');
|
||||
|
||||
if (filtered.length === 0) {
|
||||
throw new Error('Could not find test window');
|
||||
}
|
||||
|
||||
return filtered[0];
|
||||
};
|
||||
|
||||
async function createWindow () {
|
||||
const mainWindow = new BrowserWindow({
|
||||
frame: false,
|
||||
transparent: true,
|
||||
vibrancy: 'under-window',
|
||||
webPreferences: {
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true
|
||||
}
|
||||
});
|
||||
|
||||
await mainWindow.loadFile('index.html');
|
||||
|
||||
// Get initial green background color.
|
||||
const window = await getWindow();
|
||||
const buf = window.thumbnail.toPNG();
|
||||
const result = await getColors(buf, { count: 1, type: 'image/png' });
|
||||
colors.green = result[0].hex();
|
||||
}
|
||||
|
||||
ipcMain.on('set-transparent', async () => {
|
||||
// Get updated background color.
|
||||
const window = await getWindow();
|
||||
const buf = window.thumbnail.toPNG();
|
||||
const result = await getColors(buf, { count: 1, type: 'image/png' });
|
||||
colors.transparent = result[0].hex();
|
||||
|
||||
const { green, transparent } = colors;
|
||||
console.log({ green, transparent });
|
||||
process.exit(green === transparent ? 1 : 0);
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
});
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"name": "electron-test-background-color-transparent",
|
||||
"main": "main.js"
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
const { ipcRenderer } = require('electron');
|
||||
|
||||
window.setTimeout(async (_) => {
|
||||
document.body.style.background = 'transparent';
|
||||
|
||||
window.setTimeout(async (_) => {
|
||||
ipcRenderer.send('set-transparent');
|
||||
}, 2000);
|
||||
}, 3000);
|
Loading…
Add table
Add a link
Reference in a new issue