MCPcopy Index your code
hub / github.com/gitify-app/gitify / preventSecondInstance

Function preventSecondInstance

src/main/lifecycle/startup.ts:64–85  ·  view source on GitHub ↗

* Enforce a single application instance. If a second instance is launched, * any protocol URL in the command line is forwarded to the existing instance. * * @param mb - The menubar instance to show when a second instance is detected. * @param protocol - The custom protocol string to extract from

(mb: Menubar, protocol: string)

Source from the content-addressed store, hash-verified

62 * @param protocol - The custom protocol string to extract from command line args.
63 */
64function preventSecondInstance(mb: Menubar, protocol: string): void {
65 const gotTheLock = app.requestSingleInstanceLock();
66
67 if (!gotTheLock) {
68 logWarn('main:gotTheLock', 'Second instance detected, quitting');
69 app.quit();
70 return;
71 }
72
73 app.on('second-instance', (_event, commandLine) => {
74 logInfo(
75 'main:second-instance',
76 'Second instance was launched. Extracting command to forward',
77 );
78
79 const url = commandLine.find((arg) => arg.startsWith(`${protocol}://`));
80
81 if (url) {
82 handleProtocolURL(mb, url, protocol);
83 }
84 });
85}

Callers 1

initializeAppLifecycleFunction · 0.85

Calls 3

logWarnFunction · 0.90
logInfoFunction · 0.90
handleProtocolURLFunction · 0.85

Tested by

no test coverage detected