Skip to content

Commit

Permalink
防止多开
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 31, 2022
1 parent 936dee9 commit 7841f54
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions electron/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ if (fs.existsSync(devloadCachePath)) {
devloadUrl = fs.readFileSync(devloadCachePath, 'utf8')
}

/**
* 创建主窗口
*/
function createMainWindow() {
mainWindow = new BrowserWindow({
width: 1280,
Expand Down Expand Up @@ -61,6 +64,7 @@ function createMainWindow() {
}

/**
* 创建子窗口
* @param args {path, hash, title, titleFixed, force, userAgent, config, webPreferences}
*/
function createSubWindow(args) {
Expand Down Expand Up @@ -132,12 +136,25 @@ function createSubWindow(args) {
}
}

app.whenReady().then(() => {
createMainWindow()

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
const getTheLock = app.requestSingleInstanceLock()
if (!getTheLock) {
app.quit()
} else {
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore()
}
mainWindow.focus()
mainWindow.show()
}
})
app.on('ready', createMainWindow)
}

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
})

app.on('window-all-closed', () => {
Expand Down

0 comments on commit 7841f54

Please sign in to comment.