@@ -16,38 +16,37 @@ import { Label } from "@/components/ui/label";
1616import { Popover } from "@/components/ui/popover" ;
1717import { api , type Session } from "@/lib/api" ;
1818import { cn } from "@/lib/utils" ;
19+ import { listen as tauriListen } from "@tauri-apps/api/event" ;
1920
20- // Conditional imports for Tauri APIs
21- let tauriListen : any ;
2221type UnlistenFn = ( ) => void ;
2322
24- try {
25- if ( typeof window !== 'undefined' && window . __TAURI__ ) {
26- tauriListen = require ( "@tauri-apps/api/event" ) . listen ;
27- }
28- } catch ( e ) {
29- console . log ( '[ClaudeCodeSession] Tauri APIs not available, using web mode' ) ;
30- }
23+ // Runtime check for Tauri environment (must be function to check at call time)
24+ const isTauriEnv = ( ) => typeof window !== 'undefined' && ! ! ( window . __TAURI__ || window . __TAURI_INTERNALS__ ) ;
3125
32- // Web-compatible replacements
33- const listen = tauriListen || ( ( eventName : string , callback : ( event : any ) => void ) => {
26+ // Web-compatible fallback for non-Tauri environments
27+ const webListen = ( eventName : string , callback : ( event : any ) => void ) => {
3428 console . log ( '[ClaudeCodeSession] Setting up DOM event listener for:' , eventName ) ;
3529
36- // In web mode, listen for DOM events
3730 const domEventHandler = ( event : any ) => {
3831 console . log ( '[ClaudeCodeSession] DOM event received:' , eventName , event . detail ) ;
39- // Simulate Tauri event structure
4032 callback ( { payload : event . detail } ) ;
4133 } ;
4234
4335 window . addEventListener ( eventName , domEventHandler ) ;
4436
45- // Return unlisten function
4637 return Promise . resolve ( ( ) => {
4738 console . log ( '[ClaudeCodeSession] Removing DOM event listener for:' , eventName ) ;
4839 window . removeEventListener ( eventName , domEventHandler ) ;
4940 } ) ;
50- } ) ;
41+ } ;
42+
43+ // Dynamic listen function that checks environment at runtime
44+ const listen = ( eventName : string , callback : ( event : any ) => void ) => {
45+ if ( isTauriEnv ( ) ) {
46+ return tauriListen ( eventName , callback ) ;
47+ }
48+ return webListen ( eventName , callback ) ;
49+ } ;
5150import { StreamMessage } from "./StreamMessage" ;
5251import { FloatingPromptInput , type FloatingPromptInputRef } from "./FloatingPromptInput" ;
5352import { ErrorBoundary } from "./ErrorBoundary" ;
0 commit comments