Skip to content

Commit e575df1

Browse files
🔧 refactor: improve deep link handling in Electron app for Windows
Streamlined the handling of deep links within the Electron application, enhancing error handling and code readability. - Encapsulated deep link processing in a try-catch block to gracefully handle parsing errors. - Simplified event parameter handling by prefixing unused parameters with an underscore, improving code clarity
1 parent 6df85f3 commit e575df1

1 file changed

Lines changed: 25 additions & 41 deletions

File tree

‎apps/desktop/electron/main.ts‎

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ const gotTheLock = app.requestSingleInstanceLock();
10521052
if (!gotTheLock) {
10531053
app.quit();
10541054
} else {
1055-
app.on('second-instance', (event, commandLine, workingDirectory) => {
1055+
app.on('second-instance', (_event, commandLine, _workingDirectory) => {
10561056
// Someone tried to run a second instance, we should focus our window.
10571057
if (mainWindow) {
10581058
if (mainWindow.isMinimized()) mainWindow.restore();
@@ -1069,47 +1069,31 @@ if (!gotTheLock) {
10691069
}
10701070

10711071
function handleDeepLink(url: string) {
1072-
console.log(`Deep link URL: ${url}`);
1073-
// Parse and handle the deep link URL
1074-
// For example, extract the deviceCode and do something with it
1075-
const parsedUrl = new URL(url);
1076-
const deviceCode = parsedUrl.searchParams.get('deviceCode');
1077-
console.log(`Device code: ${deviceCode}`);
1078-
1079-
// Ensure mainWindow is available and send the device code to it
1080-
if (mainWindow) {
1081-
mainWindow.webContents.send('device-code', deviceCode);
1072+
try {
1073+
console.log(`Deep link URL: ${url}`);
1074+
// Parse and handle the deep link URL
1075+
const parsedUrl = new URL(url);
1076+
const deviceCode = parsedUrl.host.split('=')[1];
1077+
console.log(`Device code: ${deviceCode}`);
1078+
1079+
Sentry.captureMessage(`Device code added: ${deviceCode}, parsedUrl: ${JSON.stringify(parsedUrl)}`);
1080+
1081+
// Write the device code to a file in the sessionData directory
1082+
writeFilePromise(deviceCodeFilePath, deviceCode).then(() => {
1083+
console.log('Device code saved successfully!');
1084+
});
1085+
1086+
// Send the device code to the renderer process
1087+
if (mainWindow) {
1088+
mainWindow.webContents.send('device-code', deviceCode);
1089+
}
1090+
} catch (error: any) {
1091+
console.log(error)
1092+
Sentry.captureException(new Error(`Failed to handle deep link: ${error?.message}`), {
1093+
tags: { module: "handleDeepLink" },
1094+
extra: { error, url }
1095+
});
10821096
}
10831097
}
10841098

1085-
// app.on('open-url', (event, url) => {
1086-
// try {
1087-
// // Prevent the default behavior
1088-
// event.preventDefault();
1089-
1090-
// // Parse the URL
1091-
// const parsedUrl = new URL(url);
1092-
// const deviceCode = parsedUrl.host.split('=')[1];
1093-
// // Log the device code
1094-
// console.log(`Device code: ${deviceCode}`);
1095-
// Sentry.captureMessage(`Device code added: ${deviceCode}, parsedUrl: ${JSON.stringify(parsedUrl)}`);
1096-
1097-
// // Write the device code to a file in the sessionData directory
1098-
// writeFilePromise(deviceCodeFilePath, deviceCode).then(() => {
1099-
// console.log('Device code saved successfully!');
1100-
// });
1101-
1102-
// // Send the device code to the renderer process
1103-
// if (mainWindow) {
1104-
// mainWindow.webContents.send('device-code', deviceCode);
1105-
// }
1106-
// } catch (error: any) {
1107-
// console.log(error)
1108-
// Sentry.captureException(new Error(`Failed to open url: ${error?.message}`), {
1109-
// tags: { module: "openUrl" },
1110-
// extra: { error }
1111-
// });
1112-
// }
1113-
// });
1114-
11151099
app.whenReady().then(createWindow)

0 commit comments

Comments
 (0)