Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force single instance for App #214

Open
JohannesMerkt opened this issue Apr 25, 2022 · 0 comments
Open

Force single instance for App #214

JohannesMerkt opened this issue Apr 25, 2022 · 0 comments

Comments

@JohannesMerkt
Copy link
Collaborator

JohannesMerkt commented Apr 25, 2022

The app can be opened multiple times this can cause unexpected issues. Ports for the overlay extensions cant be used twice. Lock this into one instance.

This is how it should be done:

const { app } = require('electron')
let myWindow = null
    
const gotTheLock = app.requestSingleInstanceLock()
    
if (!gotTheLock) {
  app.quit()
} else {
  app.on('second-instance', (event, commandLine, workingDirectory) => {
    // Someone tried to run a second instance, we should focus our window.
    if (myWindow) {
      if (myWindow.isMinimized()) myWindow.restore()
      myWindow.focus()
    }
  })
    
  // Create myWindow, load the rest of the app, etc...
  app.on('ready', () => {
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants