Skip to content

Instantly share code, notes, and snippets.

@vanowm
Last active January 22, 2021 03:10
Show Gist options
  • Save vanowm/9112b8034269a0cbd67eebccd1f99a7a to your computer and use it in GitHub Desktop.
Save vanowm/9112b8034269a0cbd67eebccd1f99a7a to your computer and use it in GitHub Desktop.
mainWindow.setIcon() doesn't work when executed while window is in "attention" state (https://github.com/electron/electron/issues/27321)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
</body>
</html>
// Modules to control application life and create native browser window
const {app, BrowserWindow, Notification} = require('electron')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
}
})
mainWindow.loadFile('index.html')
//make sure window is not in focus, this will leave it in "attention" state later
mainWindow.blur();
//display notificaiton
Notification().show();
//start flashing
mainWindow.flashFrame(true);
//wait until flashing is finished and window remains in "attention" state
setTimeout(function()
{
//change window icon
mainWindow.setIcon("c:\\icon.ico"); //full path to an image
}, 7000)
}
app.whenReady().then(createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
@vanowm
Copy link
Author

vanowm commented Jan 19, 2021

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment