javascript - 只允许两个 Electron Main Process 实例,但不能更多?
问题描述
当用户第二次运行可执行文件时,我想允许 Electron 启动第二个main
进程,但如果它是第三个实例,则退出该进程。
我有以下代码用于处理与第一个不同的应用程序的第二个实例,但我不确定如何检测它是否是 Electron 3 的第三个实例。
电子主流程:Index.js
const { app } = require('electron')
const gotTheLock = app.requestSingleInstanceLock();
if (gotTheLock) {
app.on('second-instance', (argv, workingDirectory) => {
// Do some things
})
} else {
// If instance does not have lock -
// require this file in the first instance without lock
require('./host');
// Otherwise exit the new instance
// HOW CAN THIS BE ACHIEVED????
}
解决方案
推荐阅读
- jupyter-notebook - 即使在编辑 Jupyter Notebook 配置文件并重新启动它之后,默认目录也不会改变??有什么解决办法吗?
- reactive-programming - 将 Reactive Mongo 与 Webflux 一起使用时找不到 Bean 错误
- c# - 如何将一串数字“12345678”格式化为“1,23,45,678”
- java - Junit5 jpa存储库空指针异常
- django - django中视频流的流值和检测到的车牌号
- java - 我想在我的改造帖子请求中添加一个不记名令牌
- excel - 做while vba(需懂”)
- tfs - 在仅应用程序层向导上配置 TFS 2015
- azure - AzureResourceManagerTemplateDeployment 在部署作业中执行时找不到使用模式的模板
- xpath - xpath:如何仅选择当前子节点附近的父兄弟姐妹?