logoalt Hacker News

hombre_fatallast Friday at 7:53 AM5 repliesview on HN

Which desktop?

It's not true for AppKit, SwiftUI, GTK, Qt, WinUI, or Electron, and I'm not sure what's left.


Replies

okanatyesterday at 10:37 PM

I don't know much about macOS. I only used other people's stuff and navigating it is really hard for me.

You're wrong about GTK, Qt, WinUI and Electron though. They default to "do nothing" which eliminates the ability to even know that another instance exists. You have to manually program that.

dunhamyesterday at 3:20 PM

Electron requires effort to get single instance. I've had to implement it. You need to call this:

https://www.electronjs.org/docs/latest/api/app#apprequestsin...

and handle this event:

https://www.electronjs.org/docs/latest/api/app#event-second-...

I believe macos is the only OS that enforces single instance by default. If you start xterm five times on linux, you get five independent xterm processes.

tom_yesterday at 3:17 PM

It's standard for Windows. Double click a .exe, and a new copy loads and runs. If it wants to quit because there's an existing instance running, the code has to arrange for that itself. (It's possible Qt does this for you by default. Depending on the app, this can simplify some things, sometimes! Maybe WinUI is the same.)

It looks like macOS Finder tries to make it difficult to run two copies of a .app simultaneously, so I imagine many programs don't check for this case, but this is Hacker News, so we can use our hacker skills to try and do what they don't want us to: find the exe inside the bundle and run it directly from Finder, or run it from the terminal using its path. (This works for me with Ptacek's mdv app. Two copies of it end up in the dock.)

annapannalast Friday at 8:41 AM

What? 99% of my programs I can open more than one window by just executing the program as normal multiple times, the only ones that enforce a kind of singleton execution are things that also acts as a kind of server, one example is Everything search, but it has a "Open new Search window" for multiple windows. And that is the default, you have to explicit code in a lock/global mutex thing to block multiple instances.

vscode, electron app, no problem opening multiple windows. Geany, gtk app, no problem opening multiple windows.

Can you give an example where this doesn't work?

show 2 replies
orbital-decaylast Friday at 3:04 PM

Huh? None of these force single-instance by default

show 1 reply