Fix #486 : --tray flag crashes nativefied app under Windows (PR #495)

This commit is contained in:
omouren 2017-11-26 05:27:19 +01:00 committed by Ronan Jouchet
parent 8963544afa
commit 1c8d04e532
3 changed files with 14 additions and 6 deletions

View File

@ -7,7 +7,7 @@ import createMenu from './../menu/menu';
import initContextMenu from './../contextMenu/contextMenu'; import initContextMenu from './../contextMenu/contextMenu';
const { const {
isOSX, linkIsInternal, getCssToInject, shouldInjectCss, isOSX, linkIsInternal, getCssToInject, shouldInjectCss, getAppIcon,
} = helpers; } = helpers;
const ZOOM_INTERVAL = 0.1; const ZOOM_INTERVAL = 0.1;
@ -86,7 +86,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
zoomFactor: options.zoom, zoomFactor: options.zoom,
}, },
// after webpack path here should reference `resources/app/` // after webpack path here should reference `resources/app/`
icon: path.join(__dirname, '../', '/icon.png'), icon: getAppIcon(),
// set to undefined and not false because explicitly setting to false will disable full screen // set to undefined and not false because explicitly setting to false will disable full screen
fullscreen: options.fullScreen || undefined, fullscreen: options.fullScreen || undefined,
}); });

View File

@ -1,9 +1,11 @@
import path from 'path'; import helpers from './../../helpers/helpers';
const { const {
app, Tray, Menu, ipcMain, app, Tray, Menu, ipcMain, nativeImage,
} = require('electron'); } = require('electron');
const { getAppIcon } = helpers;
/** /**
* *
* @param {{}} inpOptions AppArgs from nativefier.json * @param {{}} inpOptions AppArgs from nativefier.json
@ -14,8 +16,9 @@ function createTrayIcon(inpOptions, mainWindow) {
const options = Object.assign({}, inpOptions); const options = Object.assign({}, inpOptions);
if (options.tray) { if (options.tray) {
const iconPath = path.join(__dirname, '../', '/icon.png'); const iconPath = getAppIcon();
const appIcon = new Tray(iconPath); const nimage = nativeImage.createFromPath(iconPath);
const appIcon = new Tray(nimage);
const onClick = () => { const onClick = () => {
if (mainWindow.isVisible()) { if (mainWindow.isVisible()) {

View File

@ -55,6 +55,10 @@ function debugLog(browserWindow, message) {
console.log(message); console.log(message);
} }
function getAppIcon() {
return path.join(__dirname, '../', `/icon.${isWindows() ? 'ico' : 'png'}`);
}
export default { export default {
isOSX, isOSX,
isLinux, isLinux,
@ -63,4 +67,5 @@ export default {
getCssToInject, getCssToInject,
debugLog, debugLog,
shouldInjectCss, shouldInjectCss,
getAppIcon,
}; };