From 72a14ba9ac0bf7f40b09aaf9efc1bd63178fb069 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Fri, 12 Jul 2024 09:59:08 -0500 Subject: [PATCH] Mac: Fix signal link handling when app is not open Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com> --- app/main.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/main.ts b/app/main.ts index 37a1bad0c7..c752dd431b 100644 --- a/app/main.ts +++ b/app/main.ts @@ -179,6 +179,8 @@ nativeThemeNotifier.initialize(); let appStartInitialSpellcheckSetting = true; +let macInitialOpenUrlRoute: ParsedSignalRoute | undefined; + const cliParser = createParser({ allowUnknown: true, options: [ @@ -281,10 +283,19 @@ if (!process.mas) { return true; }); + // This event is received in macOS packaged builds. app.on('open-url', (event, incomingHref) => { event.preventDefault(); const route = parseSignalRoute(incomingHref); + if (route != null) { + // When the app isn't open and you click a signal link to open the app, then + // this event will emit before mainWindow is ready. We save the value for later. + if (mainWindow == null || !mainWindow.webContents) { + macInitialOpenUrlRoute = route; + return; + } + handleSignalRoute(route); } }); @@ -1083,12 +1094,17 @@ async function readyForUpdates() { isReadyForUpdates = true; - // First, install requested sticker pack + // First, handle requested signal URLs const incomingHref = maybeGetIncomingSignalRoute(process.argv); if (incomingHref) { handleSignalRoute(incomingHref); + } else if (macInitialOpenUrlRoute) { + handleSignalRoute(macInitialOpenUrlRoute); } + // Discard value even if we don't handle a saved URL. + macInitialOpenUrlRoute = undefined; + // Second, start checking for app updates try { strictAssert(