Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions src/desktop-metrics.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<meta name="robots" content="noindex, nofollow">
<title>Desktop Metrics logger with Google Analytics</title>
<script>
// Set __ELECTRON__ flag like index.html does
if(window.electronAppAPI) {
window.__ELECTRON__ = true;
}

const SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY = "SAVED_GOOGLE_ANALYTICS_DESKTOP_KEY";
let gaReady = false, loadedGoogleAnalyticsID;

Expand All @@ -20,8 +25,10 @@
let gaFocusCallback, focusCallbackDone;
window.savedEventListener = window.addEventListener;
savedEventListener('focus', (focusEvent)=>{
gaFocusCallback.call(this, focusEvent);
focusCallbackDone = true;
if (gaFocusCallback) {
gaFocusCallback.call(this, focusEvent);
focusCallbackDone = true;
}
});

window.addEventListener = function (eventName, fn, globalEvFlag) {
Expand Down Expand Up @@ -118,17 +125,25 @@
setTimeout(reloadOnce, 1000);
}
}
window.__TAURI__.event.listen("health", processRequest);
setInterval(async ()=>{
// close window if the metrics hidden window and file drop window is the only one around.
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');
if(allTauriWindowsLabels.length === 2 || allTauriWindowsLabels.length === 1){
window.__TAURI__.window.getCurrent().close();
}
}, 1000);

if(window.__TAURI__) {
window.__TAURI__.event.listen("health", processRequest);
setInterval(async ()=>{
// close window if the metrics hidden window and file drop window is the only one around.
const allTauriWindowsLabels = await window.__TAURI__.invoke('_get_window_labels');
if(allTauriWindowsLabels.length === 2 || allTauriWindowsLabels.length === 1){
window.__TAURI__.window.getCurrent().close();
}
}, 1000);
} else if(window.__ELECTRON__) {
window.electronAPI.onHealthMetric((payload) => {
processRequest({ payload });
});
// No cleanup needed - Electron app exits when main windows close
}
</script>
</head>
<body>
Phoenix Desktop Metrics emitter to GA.
</body>
</html>
</html>
8 changes: 6 additions & 2 deletions src/utils/Metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,14 @@ define(function (require, exports, module) {

function _sendNativeGAEvent(analyticsID, customUserID, events=[]) {
if(window.__TAURI__){
return _sendTauriGAEvent(analyticsID, customUserID, events=[]);
return _sendTauriGAEvent(analyticsID, customUserID, events);
}
if(window.__ELECTRON__){
// todo electron send event to metrics window with electron
window.electronAPI.sendHealthMetric({
analyticsID: analyticsID,
customUserID: customUserID,
events: events
});
return;
}
console.error("Metrics send event failed. Unknown native platform");
Expand Down
Loading