Single Instance + argv Forwarding
Typical flow: user double-clicks the app icon while it’s already open. You want:
- The second launch exits silently (no duplicate window).
- The primary window focuses + unminimizes.
- The primary receives the launch argv (e.g. a file path).
Install the required plugin:
tynd add single-instanceimport { app } from "@tynd/core/client";import { singleInstance } from "@tynd/plugin-single-instance/client";
const { acquired } = await singleInstance.acquire("com.example.myapp");if (!acquired) { // Second instance — host already forwarded argv+cwd and focused the primary. await app.exit(0);}
// Only the primary reaches here. Handle forwarded launches:singleInstance.onSecondLaunch(({ argv, cwd }) => { // First argv entry is the exe path; look at argv[1..] for args const file = argv.slice(1).find((a) => a.endsWith(".myapp")); if (file) { openFile(file); }});Host auto-focus + unminimize is built in — no IPC round-trip needed. Your code only handles what to do with the forwarded args.
Combine with deep links
Section titled “Combine with deep links”singleInstance.onOpenUrl((url) => { // Fires on cold start (argv has the URL) AND duplicate launch (forwarded) const parsed = new URL(url); router.navigate(parsed.pathname);});onOpenUrl and onSecondLaunch can coexist — the URL-scheme detection happens in the host, custom-scheme URLs fire onOpenUrl, plain paths fire onSecondLaunch.
Use stable, reverse-DNS ids
Section titled “Use stable, reverse-DNS ids”singleInstance.acquire("com.example.myapp"); // ✓singleInstance.acquire("MyApp-v1.0.0"); // ✗ — version breaks upgrade UXRelated: Single Instance guide · singleInstance API.