From e06478a4bcfcc41b61a4b2967bb8cc67c1df5f1a Mon Sep 17 00:00:00 2001 From: Maurizio Casimirri Date: Wed, 5 Jun 2024 10:00:15 +0200 Subject: [PATCH] chore(telemetry): remove window telemetry events COMPASS-7964 (#5847) chore: remove window telemetry events COMPASS-7964 Co-authored-by: Rhys --- packages/compass/src/main/window-manager.ts | 66 +-------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/packages/compass/src/main/window-manager.ts b/packages/compass/src/main/window-manager.ts index 7dc3c31b773..8a4ca2c671d 100644 --- a/packages/compass/src/main/window-manager.ts +++ b/packages/compass/src/main/window-manager.ts @@ -10,7 +10,6 @@ import { once } from 'events'; import type { BrowserWindowConstructorOptions, FindInPageOptions, - App, } from 'electron'; import { app as electronApp, shell, BrowserWindow } from 'electron'; import { enable } from '@electron/remote/main'; @@ -24,7 +23,7 @@ import { registerMongoDbUrlForBrowserWindow, } from './auto-connect'; -const { track, debug } = createLoggerAndTelemetry('COMPASS-WINDOW-MANAGER'); +const { debug } = createLoggerAndTelemetry('COMPASS-WINDOW-MANAGER'); const earlyOpenUrls: string[] = []; function earlyOpenUrlListener( @@ -221,67 +220,6 @@ async function onAppReady() { } } -function trackWindowEvents(electronApp: App) { - // Map of [Window id] -> [opening timestamp in milliseconds] - const windowFocusedAt = new Map(); - let sessionStartedAt: number | undefined = undefined; - let openWindows = 0; - - electronApp.on('browser-window-created', (event, win) => { - openWindows++; - track('Window Open', { - number_of_windows_open: openWindows, - }); - - win.once('closed', () => { - openWindows--; - track('Window Closed', { - number_of_windows_open: openWindows, - }); - }); - }); - - electronApp.on('browser-window-focus', (event, win) => { - const now = Date.now(); - sessionStartedAt ??= now; - windowFocusedAt.set(win.webContents.id, now); - track('Window Focused', { - number_of_windows_open: openWindows, - }); - }); - - electronApp.on('browser-window-blur', (event, win) => { - if (win.webContents.isDevToolsFocused()) { - return; - } - - // causes focus to be emitted after blur, allowing us to track - // when the focus moves from a Compass window to the other - setTimeout(() => { - const focusAt = windowFocusedAt.get(win.webContents.id); - const movedToOtherCompassWin = windowFocusedAt.size === 2; - windowFocusedAt.delete(win.webContents.id); - - if (focusAt) { - const now = Date.now(); - track('Window Blurred', { - session_duration_secs: Math.round((now - focusAt) / 1000), - focus_to_other_compass_window: movedToOtherCompassWin, - number_of_windows_open: openWindows, - }); - - if (sessionStartedAt && !movedToOtherCompassWin) { - track('Application Blurred', { - session_duration_secs: Math.round((now - sessionStartedAt) / 1000), - number_of_windows_open: openWindows, - }); - sessionStartedAt = undefined; - } - } - }); - }); -} - class CompassWindowManager { private static initPromise: Promise | null = null; @@ -300,8 +238,6 @@ class CompassWindowManager { } }); - trackWindowEvents(electronApp); - compassApp.on('show-connect-window', () => { showConnectWindow(compassApp); });