码迷,mamicode.com
首页 > 其他好文 > 详细

electron限制只启动一个应用

时间:2019-07-11 12:41:38      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:lin   ons   director   sse   zed   create   tor   load   cto   

// ==========================================================
// 限制只可以打开一个应用,2.x的文档
// const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
//   // Someone tried to run a second instance, we should focus our window.
//   if (mainWindow) {
//     if (mainWindow.isMinimized()) mainWindow.restore()
//     mainWindow.focus()
//     mainWindow.show()
//   }
// })

// if (isSecondInstance) {
//   app.quit()
// }
// Create myWindow, load the rest of the app, etc...

// 限制只可以打开一个应用, 4.x的文档
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
  app.quit()
} else {
  app.on('second-instance', (event, commandLine, workingDirectory) => {
    // 当运行第二个实例时,将会聚焦到mainWindow这个窗口
    if (mainWindow) {
      if (mainWindow.isMinimized()) mainWindow.restore()
      mainWindow.focus()
      mainWindow.show()
    }
  })
  // 创建 myWindow, 加载应用的其余部分, etc...
  // app.on('ready', () => {
  // })
}
// ==========================================================

electron限制只启动一个应用

标签:lin   ons   director   sse   zed   create   tor   load   cto   

原文地址:https://www.cnblogs.com/ybixian/p/11169027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!