Election v8.0.0; macOS 10.14.5
Has anyone had success getting an icon to display with dialog.showMessageBox
in the renderer
process?
I'm able to get the icon to work from the main
process but not from a renderer
process. Same with Notifications
– no icon but no errors. I can console.log the nativeImage
so I know it is getting created but I'm still getting the default Electron icon.
I could probably do a workaround by messaging main
, displaying the showMessageBox
, sending back the result, etc. but that is more spaghetti code than I'd like.
const iconPath = upath.toUnix(upath.join(__dirname, "assets", "icon.png"));
//debuging:
var fileExists = fs.existsSync(iconPath)
console.log('fileExists', fileExists);
const dialogIcon = nativeImage.createFromPath(iconPath);
//debuging:
console.log('dialogIcon', dialogIcon);
var options = {
type: 'question',
buttons: ['&Yes', '&No'],
title: 'Delete Event',
icon: dialogIcon,
normalizeAccessKeys: true,
message: 'Permanently delete event?'
};
const win = BrowserWindow.getFocusedWindow();
dialog.showMessageBox(win, options)
.then((choice) => {
if (choice.response === 0) {
// do something
}
}).catch(err => {
console.log('ERROR', err);
});
So in order to use a nativeImage
with the dialog
module in a render
process, the nativeImage
needs to be accessed through remote
even though nativeImage
is available to both main
and render
contexts:
const { ipcRenderer, remote } = require('electron');
Wrong:
const { ipcRenderer, remote, nativeImage } = require('electron');
Right:
const { BrowserWindow, dialog, nativeImage } = require('electron').remote;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With