Javascript Electron没有终止应用程序进程,即使使用app.quit()也是如此
我的electron应用程序有一个系统托盘菜单,除右键单击系统托盘中的图标以完全退出应用程序以终止进程外,其他一切都正常工作。系统什么都不做。 如果用户不希望应用程序运行,我将尝试完全终止该进程 我已经试着把“app.quit()”放在标题中,但是应用程序什么都不做Javascript Electron没有终止应用程序进程,即使使用app.quit()也是如此,javascript,electron,exit,Javascript,Electron,Exit,我的electron应用程序有一个系统托盘菜单,除右键单击系统托盘中的图标以完全退出应用程序以终止进程外,其他一切都正常工作。系统什么都不做。 如果用户不希望应用程序运行,我将尝试完全终止该进程 我已经试着把“app.quit()”放在标题中,但是应用程序什么都不做 function createWindow () { // Create the browser window. win = new BrowserWindow({ width: 350, height: 550, resi
function createWindow () {
// Create the browser window.
win = new BrowserWindow({ width: 350, height: 550, resizable: true})
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
}
//position the electron window
var positioner = new Positioner(win)
positioner.move('bottomRight')
//logo for the task bar
win.setIcon('logo/logo.png');
win.on('minimize',function(event) {
event.preventDefault();
win.hide();
});
//clicking 'x' will close the app, but the app will still run in system tray (intended)
win.on('close', function(event) {
event.preventDefault();
win.hide();
})
}
//function to show/hide app when right clicking on the system tray and selecting "show/hide"
function toggleWindow() {
if (win.isVisible()) {
win.webContents.send('setVisible', false);
setTimeout(function () {
win.hide();
}, 300);
}
else {
win.show();
win.webContents.send('setVisible', true);
}
}
/**
* setting bottom right tray menu icon
* added left/right click events for system tray
*/
let tray = null
app.on('ready', () => {
tray = new Tray(path.join(__dirname, '../logo/tray_logo.png'))
tray.on('click', function handleClicked () {
toggleWindow();
})
const contextMenu = Menu.buildFromTemplate([
{ label: 'Show/Hide', type: 'normal', click: function () { toggleWindow(); } },
{ label: 'Exit', type: 'normal', click: function() { } } //exit is not working. I've tried app.quit();
])
tray.setToolTip('Activity')
tray.setContextMenu(contextMenu)
})
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
您可以检查
app
是否在该函数的范围内定义。您可以检查app
是否在该函数的范围内定义