super-productivity/electron/main.ts
Johannes Millan 0ea0ba143f fix(electron): improve protocol URL handling and register URL scheme on Linux
Suppress noisy "EXITING due to failed single instance lock" message when
a second instance is launched via xdg-open for protocol URL handling.
Register superproductivity:// as a MIME type handler in the .desktop file
so Linux users no longer need manual xdg-settings configuration.
Remove duplicate requestSingleInstanceLock() call in start-app.ts.

Closes #173
2026-03-05 16:45:05 +01:00

24 lines
784 B
TypeScript

import { app } from 'electron';
import { PROTOCOL_PREFIX } from './protocol-handler';
import { startApp } from './start-app';
const IS_MAC = process.platform === 'darwin';
if (!IS_MAC) {
// make it a single instance by closing other instances but allow for dev mode
// because of https://github.com/electron/electron/issues/14094
const isLockObtained = app.requestSingleInstanceLock();
if (!isLockObtained) {
const hasProtocolUrl = process.argv.some((arg) => arg.startsWith(PROTOCOL_PREFIX));
if (!hasProtocolUrl) {
console.log('Another instance is already running. Exiting.');
}
// Force immediate exit without waiting for graceful shutdown
process.exit(0);
} else {
console.log('Start app...');
startApp();
}
} else {
startApp();
}