How to Prevent Multiple Instances of the Same Window from Opening in MACos

Stop the same window from opening twice OS X app

There is actually no code required for this and there is a simple solution.

  1. In your storyboard, select the destination VC that you are segueing to.
  2. Open the attributes inspector and change Presentation from Multiple to Single.

Prevent NSMenu from creating multiple instances of same NSWindow when clicked

  1. Select destination window controller
  2. Click attribute inspector and select under Presentation "Single" instead of "Multiple"

Single window instance

Prevent multiple users from running application simultaneously on macOS

Add LSMultipleInstancesProhibited to the Info.plist file.

<key>LSMultipleInstancesProhibited</key>
<true/>

See this answer and Apple's documentation.

How to prevent displaying window on application startup osx

Select NSWindow and just turn off Visible At Launch.

If you want to show the window, do it manually as follows.

- (void)applicationWillFinishLaunching:(NSNotification *)notification {
/* Do whatever necessary before the window appears */
[window setIsVisible:YES];
}

Personally, I never have the Visible-At-Launch switch on.

Sample Image

How to prevent multiple instances in Electron

There is a new API now: requestSingleInstanceLock

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', () => {
})
}



Related Topics



Leave a reply



Submit