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
This commit is contained in:
Johannes Millan 2026-03-05 14:02:49 +01:00
parent 49d24bfec0
commit 0ea0ba143f
3 changed files with 8 additions and 12 deletions

View file

@ -47,6 +47,8 @@ linux:
# Fix for issue #5259: Set executable name without spaces for snap compatibility
executableName: superproductivity
category: Office;ProjectManagement
mimeTypes:
- x-scheme-handler/superproductivity
desktop:
entry:
StartupWMClass: superproductivity

View file

@ -1,4 +1,5 @@
import { app } from 'electron';
import { PROTOCOL_PREFIX } from './protocol-handler';
import { startApp } from './start-app';
const IS_MAC = process.platform === 'darwin';
@ -8,7 +9,10 @@ if (!IS_MAC) {
// because of https://github.com/electron/electron/issues/14094
const isLockObtained = app.requestSingleInstanceLock();
if (!isLockObtained) {
console.log('EXITING due to failed single instance lock');
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 {

View file

@ -51,19 +51,9 @@ let mainWin: BrowserWindow;
let idleTimeHandler: IdleTimeHandler;
export const startApp = (): void => {
// Initialize protocol handling
// Initialize protocol handling (registers second-instance listener for URL forwarding)
initializeProtocolHandling(IS_DEV, app, () => mainWin);
// Handle single instance lock (not needed on macOS - OS handles it natively,
// and the singleton socket is blocked by the App Store sandbox)
if (!IS_MAC) {
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
return;
}
}
// LOAD IPC STUFF
initIpcInterfaces();