File size: 929 Bytes
8c29c68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** Electron single-instance ownership before any Desktop profile lifecycle begins. */
/** Minimal Electron application operations needed for instance ownership. */
export interface DesktopSingleInstanceApplication {
requestSingleInstanceLock(): boolean
quit(): void
on(event: 'second-instance', listener: () => void): unknown
}
/**
* Claim the process-lifetime Desktop lock and route later launches to the owner.
* @param application - Electron application singleton.
* @param focusOwner - focus or recreate the primary window after a later launch.
* @returns true only in the process that may access the Desktop profile.
*/
export function claimDesktopSingleInstance(
application: DesktopSingleInstanceApplication,
focusOwner: () => void,
): boolean {
if (!application.requestSingleInstanceLock()) {
application.quit()
return false
}
application.on('second-instance', focusOwner)
return true
}
|