@@ -2,8 +2,11 @@ import { app } from "electron";
22import { container } from "./di/container" ;
33import { MAIN_TOKENS } from "./di/tokens" ;
44import type { DeepLinkService } from "./services/deep-link/service" ;
5+ import { logger } from "./utils/logger" ;
56import { focusMainWindow } from "./window" ;
67
8+ const log = logger . scope ( "deep-links" ) ;
9+
710let pendingDeepLinkUrl : string | null = null ;
811
912function getDeepLinkService ( ) : DeepLinkService {
@@ -18,29 +21,37 @@ export function registerDeepLinkHandlers(): void {
1821 // Handle deep link URLs on macOS
1922 app . on ( "open-url" , ( event , url ) => {
2023 event . preventDefault ( ) ;
24+ log . info ( "open-url event received" , { url, appReady : app . isReady ( ) } ) ;
2125
2226 if ( ! app . isReady ( ) ) {
2327 pendingDeepLinkUrl = url ;
2428 return ;
2529 }
2630
2731 getDeepLinkService ( ) . handleUrl ( url ) ;
28- focusMainWindow ( ) ;
32+ focusMainWindow ( "open-url deep link" ) ;
2933 } ) ;
3034
3135 // Handle deep link URLs on Windows/Linux (second instance sends URL via command line)
3236 app . on ( "second-instance" , ( _event , commandLine ) => {
37+ log . info ( "second-instance event received" , {
38+ commandLine : commandLine . join ( " " ) ,
39+ argCount : commandLine . length ,
40+ } ) ;
41+
3342 const url = commandLine . find (
3443 ( arg ) =>
3544 arg . startsWith ( "posthog-code://" ) ||
3645 arg . startsWith ( "twig://" ) ||
3746 arg . startsWith ( "array://" ) ,
3847 ) ;
3948 if ( url ) {
49+ log . info ( "Deep link URL found in second-instance args" , { url } ) ;
4050 getDeepLinkService ( ) . handleUrl ( url ) ;
51+ focusMainWindow ( "second-instance deep link" ) ;
52+ } else {
53+ log . warn ( "second-instance fired with no deep link URL, ignoring focus" ) ;
4154 }
42-
43- focusMainWindow ( ) ;
4455 } ) ;
4556}
4657
0 commit comments