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

View File

@@ -20,6 +20,8 @@ export const config = (): BuildOptions => {
'process.env.GITHUB_SHA': process.env.GITHUB_SHA,
'process.env.SENTRY_RELEASE': process.env.SENTRY_RELEASE,
'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',
...Object.entries(
getBuildConfig({

View File

@@ -57,6 +57,18 @@ export function setupDeepLink(app: App) {
})
.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) {

View File

@@ -58,10 +58,12 @@ export function registerEvents() {
}
app.on('before-quit', () => {
// subscription on quit sometimes crashes the app
try {
unsubs.forEach(unsub => unsub());
} catch (err) {
logger.error('unsubscribe error', err);
}
unsubs.forEach(unsub => {
try {
unsub();
} catch (err) {
logger.warn('unsubscribe error on quit', err);
}
});
});
}