我们有一个电子客户端应用程序,必须通过公司范围的软件管理系统进行部署和更新。
目前,在安装更新之前,正在运行的Electron客户端应用程序被简单地“杀死”。
在Windows10下,有没有办法告诉Electron客户端正常关闭(内部应用关闭事件或另一个事件应该运行)
发布于 2021-04-15 22:56:03
对于windows,Electron可以在后台进程中处理graceful-exit,对于Linux,可以在后台进程中处理SIGTERM。
要“礼貌地”要求应用程序关闭:
// 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') {
console.log('if you see this message - all windows was closed')
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
createWindow()
})
// Exit cleanly on request from parent process.
if (process.platform === 'win32') {
// this message usually fires in dev-mode from the parent process
process.on('message', (data) => {
if (data === 'graceful-exit') {
console.log('if you see this message - graceful-exit fired')
app.quit()
}
})
} else {
process.on('SIGTERM', () => {
console.log('if you see this message - SIGTERM fired')
app.quit()
})
}https://stackoverflow.com/questions/67109366
复制相似问题