Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: css transparent background being lost (#32593)
- Loading branch information
1 parent
86f8fae
commit 3768a7b
Showing
10 changed files
with
836 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
spec-main/fixtures/apps/background-color-transparent/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!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> |
59 changes: 59 additions & 0 deletions
59
spec-main/fixtures/apps/background-color-transparent/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
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: { | ||
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; | ||
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(); | ||
}); |
4 changes: 4 additions & 0 deletions
4
spec-main/fixtures/apps/background-color-transparent/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "background-color-transparent", | ||
"main": "main.js" | ||
} |
9 changes: 9 additions & 0 deletions
9
spec-main/fixtures/apps/background-color-transparent/renderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { ipcRenderer } = require('electron'); | ||
|
||
window.setTimeout(async (_) => { | ||
document.body.style.background = 'transparent'; | ||
|
||
window.setTimeout(async (_) => { | ||
ipcRenderer.send('set-transparent'); | ||
}, 2000); | ||
}, 3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.