fix(electron): deep link handling without running instance (#8661)

fix AF-1586
This commit is contained in:
pengx17
2024-11-01 07:23:38 +00:00
parent 33088500e4
commit 070f5fae49
3 changed files with 21 additions and 5 deletions
@@ -20,6 +20,8 @@ export const config = (): BuildOptions => {
'process.env.GITHUB_SHA': process.env.GITHUB_SHA, 'process.env.GITHUB_SHA': process.env.GITHUB_SHA,
'process.env.SENTRY_RELEASE': process.env.SENTRY_RELEASE, 'process.env.SENTRY_RELEASE': process.env.SENTRY_RELEASE,
'process.env.SENTRY_DSN': process.env.SENTRY_DSN, 'process.env.SENTRY_DSN': process.env.SENTRY_DSN,
'process.env.DEV_SERVER_URL': process.env.DEV_SERVER_URL,
'process.env.NODE_ENV': process.env.NODE_ENV,
REPLACE_ME_BUILD_ENV: process.env.BUILD_TYPE ?? 'stable', REPLACE_ME_BUILD_ENV: process.env.BUILD_TYPE ?? 'stable',
...Object.entries( ...Object.entries(
getBuildConfig({ getBuildConfig({
@@ -57,6 +57,18 @@ export function setupDeepLink(app: App) {
}) })
.catch(e => console.error('Failed to restore or create window:', e)); .catch(e => console.error('Failed to restore or create window:', e));
}); });
app.on('ready', () => {
// app may be brought up without having a running instance
// need to read the url from the command line
const url = process.argv.at(-1);
logger.log('url from argv', process.argv, url);
if (url?.startsWith(`${protocol}://`)) {
handleAffineUrl(url).catch(e => {
logger.error('failed to handle affine url', e);
});
}
});
} }
async function handleAffineUrl(url: string) { async function handleAffineUrl(url: string) {
@@ -58,10 +58,12 @@ export function registerEvents() {
} }
app.on('before-quit', () => { app.on('before-quit', () => {
// subscription on quit sometimes crashes the app // subscription on quit sometimes crashes the app
try { unsubs.forEach(unsub => {
unsubs.forEach(unsub => unsub()); try {
} catch (err) { unsub();
logger.error('unsubscribe error', err); } catch (err) {
} logger.warn('unsubscribe error on quit', err);
}
});
}); });
} }