55 < meta name ="robots " content ="noindex, nofollow ">
66 < title > Desktop Metrics logger with Google Analytics</ title >
77 < script >
8+ // Set __ELECTRON__ flag like index.html does
9+ if ( window . electronAppAPI ) {
10+ window . __ELECTRON__ = true ;
11+ }
12+
813 const SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY = "SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY" ;
914 let gaReady = false , loadedGoogleAnalyticsID ;
1015
2025 let gaFocusCallback , focusCallbackDone ;
2126 window . savedEventListener = window . addEventListener ;
2227 savedEventListener ( 'focus' , ( focusEvent ) => {
23- gaFocusCallback . call ( this , focusEvent ) ;
24- focusCallbackDone = true ;
28+ if ( gaFocusCallback ) {
29+ gaFocusCallback . call ( this , focusEvent ) ;
30+ focusCallbackDone = true ;
31+ }
2532 } ) ;
2633
2734 window . addEventListener = function ( eventName , fn , globalEvFlag ) {
118125 setTimeout ( reloadOnce , 1000 ) ;
119126 }
120127 }
121- window . __TAURI__ . event . listen ( "health" , processRequest ) ;
122- setInterval ( async ( ) => {
123- // close window if the metrics hidden window and file drop window is the only one around.
124- const allTauriWindowsLabels = await window . __TAURI__ . invoke ( '_get_window_labels' ) ;
125- if ( allTauriWindowsLabels . length === 2 || allTauriWindowsLabels . length === 1 ) {
126- window . __TAURI__ . window . getCurrent ( ) . close ( ) ;
127- }
128- } , 1000 ) ;
128+
129+ if ( window . __TAURI__ ) {
130+ window . __TAURI__ . event . listen ( "health" , processRequest ) ;
131+ setInterval ( async ( ) => {
132+ // close window if the metrics hidden window and file drop window is the only one around.
133+ const allTauriWindowsLabels = await window . __TAURI__ . invoke ( '_get_window_labels' ) ;
134+ if ( allTauriWindowsLabels . length === 2 || allTauriWindowsLabels . length === 1 ) {
135+ window . __TAURI__ . window . getCurrent ( ) . close ( ) ;
136+ }
137+ } , 1000 ) ;
138+ } else if ( window . __ELECTRON__ ) {
139+ window . electronAPI . onHealthMetric ( ( payload ) => {
140+ processRequest ( { payload } ) ;
141+ } ) ;
142+ // No cleanup needed - Electron app exits when main windows close
143+ }
129144 </ script >
130145</ head >
131146< body >
132147Phoenix Desktop Metrics emitter to GA.
133148</ body >
134- </ html >
149+ </ html >
0 commit comments