()
| 46 | let pendingDeepLinkUrl = null; |
| 47 | |
| 48 | function setupProtocolHandling() { |
| 49 | // Protocol registration - must be done before app is ready |
| 50 | try { |
| 51 | if (!app.isDefaultProtocolClient('pickleglass')) { |
| 52 | const success = app.setAsDefaultProtocolClient('pickleglass'); |
| 53 | if (success) { |
| 54 | console.log('[Protocol] Successfully set as default protocol client for pickleglass://'); |
| 55 | } else { |
| 56 | console.warn('[Protocol] Failed to set as default protocol client - this may affect deep linking'); |
| 57 | } |
| 58 | } else { |
| 59 | console.log('[Protocol] Already registered as default protocol client for pickleglass://'); |
| 60 | } |
| 61 | } catch (error) { |
| 62 | console.error('[Protocol] Error during protocol registration:', error); |
| 63 | } |
| 64 | |
| 65 | // Handle protocol URLs on Windows/Linux |
| 66 | app.on('second-instance', (event, commandLine, workingDirectory) => { |
| 67 | console.log('[Protocol] Second instance command line:', commandLine); |
| 68 | |
| 69 | focusMainWindow(); |
| 70 | |
| 71 | let protocolUrl = null; |
| 72 | |
| 73 | // Search through all command line arguments for a valid protocol URL |
| 74 | for (const arg of commandLine) { |
| 75 | if (arg && typeof arg === 'string' && arg.startsWith('pickleglass://')) { |
| 76 | // Clean up the URL by removing problematic characters |
| 77 | const cleanUrl = arg.replace(/[\\₩]/g, ''); |
| 78 | |
| 79 | // Additional validation for Windows |
| 80 | if (process.platform === 'win32') { |
| 81 | // On Windows, ensure the URL doesn't contain file path indicators |
| 82 | if (!cleanUrl.includes(':') || cleanUrl.indexOf('://') === cleanUrl.lastIndexOf(':')) { |
| 83 | protocolUrl = cleanUrl; |
| 84 | break; |
| 85 | } |
| 86 | } else { |
| 87 | protocolUrl = cleanUrl; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (protocolUrl) { |
| 94 | console.log('[Protocol] Valid URL found from second instance:', protocolUrl); |
| 95 | handleCustomUrl(protocolUrl); |
| 96 | } else { |
| 97 | console.log('[Protocol] No valid protocol URL found in command line arguments'); |
| 98 | console.log('[Protocol] Command line args:', commandLine); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 | // Handle protocol URLs on macOS |
| 103 | app.on('open-url', (event, url) => { |
| 104 | event.preventDefault(); |
| 105 | console.log('[Protocol] Received URL via open-url:', url); |
no test coverage detected