admin管理员组文章数量:1356429
I'm trying to keep my electron app from being able to start more than one window at a time. I've already tried this, but it makes the first window opened close itself instead of the second window opened, and it pletely stops working for the third window:
app.requestSingleInstanceLock();
app.on('second-instance', () => {
app.quit();
});
The older app.makeSingleInstance
also throws an error since it's deprecated. What should I do instead?
I'm trying to keep my electron app from being able to start more than one window at a time. I've already tried this, but it makes the first window opened close itself instead of the second window opened, and it pletely stops working for the third window:
app.requestSingleInstanceLock();
app.on('second-instance', () => {
app.quit();
});
The older app.makeSingleInstance
also throws an error since it's deprecated. What should I do instead?
1 Answer
Reset to default 7Update: the example in the docs looks like the best pattern to follow! I.e. call app.quit()
when app.requestSingleInstanceLock()
returns false
From the docs:
This event will be emitted inside the primary instance of your application when a second instance has been executed and calls app.requestSingleInstanceLock().
I.e. this is why app.quit()
shuts the first window.
... Usually applications respond to this by making their primary window focused and non-minimized.
So if win
is the instance of BrowserWindow
that your main process opened, you could do:
win.show()
win.focus()
I believe you could also do nothing in the 'second-instance' handler: the event is just for information, telling you that the user has tried to open your app a second time.
本文标签: javascriptHow do you force an electron app to have a single instanceStack Overflow
版权声明:本文标题:javascript - How do you force an electron app to have a single instance? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744057123a2583456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论