Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Preventing multiple same ElectronJS apps to run at single time

Posted on February 20, 2019August 4, 2020 by Habibie

I am building an EelectronJS app and successfully release it as an executable Windows program.

But the problem is when the app is already running, if I double-click again that .exe file, the second window of this app is running, but buggy. I don’t want it. So here is the solution:

This main.js file is my solution when I need to prevent multiple instances of ElectronJS app to run at same time.

const { app, BrowserWindow } = require('electron')

const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
	app.quit()
} else {
	app.on('ready', createWindow)
}

function createWindow () {
	// Create the browser window.
	let win = new BrowserWindow({ width: 1024, height: 720 })
	
	// and load the index.html of the app.
	win.loadFile('index.html')
	
}

app.on('window-all-closed', () => {
  app.quit()
})

Post Views: 444
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme