Repository navigation
Description
Context
Since #31, nsgo.Run on Windows and Linux claims one instance per app ID before it starts the engine: internal/platform/linux/linux.go:253-259 and internal/platform/windows/windows.go:553-559 call claimInstance(opts.ID, engine.LaunchFiles()), and a launch that finds the lock held hands its files to the owner and returns. The ID is always core.App().ID (nsgo.go:40), the id of nsgo.yaml; only a test's window (opts.test) skips the claim. The lock is per user and host: $XDG_RUNTIME_DIR (or a private directory in the temporary one) on Linux, a named mutex and pipe on Windows. macOS does not do this for an executable started directly, only for a bundle LaunchServices opens.
There is no way for an app to run a second copy on purpose, or to scope the lock to something narrower than the app ID.
Why it matters
Kando (github.com/yldm-tech/kando), a video player built with NSGo, has a command line (kando add <url>, an MCP server) that talks to the running app over a Unix socket, and starts the app when nothing answers. With KANDO_SOCKET set, the command line starts a copy of its own that listens on that socket: tests and isolated runs use it (for example, a run with its own HOME for screenshots) while the user's own Kando keeps running.
On Windows and Linux that copy now hands its launch to the user's running Kando and exits; the command line then waits on a socket nobody listens on and times out. The same applies to any app that runs isolated copies for tests, demos, profiles or portable installs. With MyGo, Kando decided this itself (RequestSingleInstanceLock returned false and the app chose to continue).
Reproduction
- An app with an
idinnsgo.yamlwhose main logs its PID andos.Getenv("PROFILE"), run withnsgo.Run(App). - On Linux or Windows, start it, then start it again with
PROFILE=b(or a differentHOME/%APPDATA%). - The second process exits immediately; the first hears
OnReopen. There is no option that lets the second one run.
Proposal
A run option that scopes the claim, for example nsgo.InstanceKey(key string): the lock and the handoff socket or pipe are named after the app ID plus key, so launches with the same key still reach one instance, and a different key runs its own. An empty key keeps today's behaviour. Kando would pass os.Getenv("KANDO_SOCKET"). If disabling the claim entirely is wanted as well, nsgo.InstanceKey with a per-process value already does it, or a separate nsgo.MultipleInstances() can say so explicitly.
On macOS the option would have nothing to change for bundles LaunchServices opens; it should be documented as Windows and Linux only.
Acceptance
- On Windows and Linux, two launches with different instance keys both run; two with the same key still hand over to one instance, files included.
- Without the option, behaviour is unchanged.
-
docs/architecture/application.md§Lifecycle documents the option.
Activity
fix: use NSGo's windows and one instance on Windows and Linux, and ch…
docs: bring the READMEs in line with the NSGo build
docs: bring the READMEs in line with the NSGo build (#123)