Skip to content

Commit

Permalink
chore(telemetry): remove window telemetry events COMPASS-7964 (#5847)
Browse files Browse the repository at this point in the history
chore: remove window telemetry events COMPASS-7964

Co-authored-by: Rhys <[email protected]>
  • Loading branch information
mcasimir and Anemy authored Jun 5, 2024
1 parent 6a236ec commit e06478a
Showing 1 changed file with 1 addition and 65 deletions.
66 changes: 1 addition & 65 deletions packages/compass/src/main/window-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand Down Expand Up @@ -221,67 +220,6 @@ async function onAppReady() {
}
}

function trackWindowEvents(electronApp: App) {
// Map of [Window id] -> [opening timestamp in milliseconds]
const windowFocusedAt = new Map<number, number>();
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<void> | null = null;

Expand All @@ -300,8 +238,6 @@ class CompassWindowManager {
}
});

trackWindowEvents(electronApp);

compassApp.on('show-connect-window', () => {
showConnectWindow(compassApp);
});
Expand Down

0 comments on commit e06478a

Please sign in to comment.