Add url scheme handler

No yet confirmed for Windows/Linux
This commit is contained in:
kPherox 2019-04-29 23:49:56 +09:00
parent 60db0c13a7
commit a2cac44a81
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D

View File

@ -30,9 +30,17 @@ export default class Application {
private constructor() { private constructor() {
this.isDarkMode = systemPreferences.isDarkMode() this.isDarkMode = systemPreferences.isDarkMode()
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
return
}
app.setAsDefaultProtocolClient('thedesk')
app.on('window-all-closed', () => this.onWindowAllClosed()) app.on('window-all-closed', () => this.onWindowAllClosed())
app.on('ready', () => this.onReady()) app.on('will-finish-launching', () => this.onWillFinishLaunching())
app.on('activate', () => this.onActivated()) app.on('ready', (launchInfo: any) => this.onReady())
app.on('activate', (event: Event, hasVisibleWindows: boolean) => this.onActivated())
systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => { systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
this.isDarkMode = systemPreferences.isDarkMode() this.isDarkMode = systemPreferences.isDarkMode()
@ -78,6 +86,23 @@ export default class Application {
} }
} }
private onWillFinishLaunching() {
app.on('open-url', (event: Event, url: string) => {
// On macOS: url = thedesk://login?code=xxx
Application.handleOpenURL(event, url)
})
app.on('second-instance', (event: Event, argv: string[], workingDirectory: string) => {
// On Windows/Linux: argv = ここをmacOSに合わせるかこちらに合わせるか
Application.handleOpenURL(event, argv[1])
})
}
private static handleOpenURL(event: Event, url: string) {
if (Window.windowMap.has('main')) {
Window.windowMap.get('main')!.webContents.send("open-url-scheme", url)
}
}
public static openUrl(event: Event, url: string) { public static openUrl(event: Event, url: string) {
shell.openExternal(url, { shell.openExternal(url, {
activate: false activate: false