首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从外部正常关闭Electron Client

从外部正常关闭Electron Client
EN

Stack Overflow用户
提问于 2021-04-15 21:26:46
回答 1查看 95关注 0票数 0

我们有一个电子客户端应用程序,必须通过公司范围的软件管理系统进行部署和更新。

目前,在安装更新之前,正在运行的Electron客户端应用程序被简单地“杀死”。

在Windows10下,有没有办法告诉Electron客户端正常关闭(内部应用关闭事件或另一个事件应该运行)

EN

回答 1

Stack Overflow用户

发布于 2021-04-15 22:56:03

对于windows,Electron可以在后台进程中处理graceful-exit,对于Linux,可以在后台进程中处理SIGTERM

要“礼貌地”要求应用程序关闭:

  • 使用不带/f - detailstaskkill。(Windows)
  • 使用pkill -TERM <proc-name>代替kill details (linux)

代码语言:javascript
复制
// 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()
  })
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67109366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档