From dac8c5b2132ae07833525f7810eba51b04dc40e2 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 27 Jun 2023 07:17:06 -0700 Subject: [PATCH] Usage track now internal to tracking Summary: Usage tracking comes from Electron's `main.tsx`. There's a timer that dispatches an IPC event every 60 seconds. This is all good for Electron builds. For non-electron builds, there's no such thing as IPC. So, react to the IPC event whenever necessary but also handle the interval internally such that usage is tracked independently of explicit callers. Reviewed By: antonk52 Differential Revision: D47053404 fbshipit-source-id: f17694e65eed18678b45a2e815813bafab69c3f1 --- desktop/flipper-ui-core/src/dispatcher/tracking.tsx | 13 +++++++++---- desktop/static/main.tsx | 7 ------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/desktop/flipper-ui-core/src/dispatcher/tracking.tsx b/desktop/flipper-ui-core/src/dispatcher/tracking.tsx index e38b7ddac..e78f5a34b 100644 --- a/desktop/flipper-ui-core/src/dispatcher/tracking.tsx +++ b/desktop/flipper-ui-core/src/dispatcher/tracking.tsx @@ -71,7 +71,6 @@ export function emitBytesReceived(plugin: string, bytes: number) { bytesReceivedEmitter.emit('bytesReceived', plugin, bytes); } } - export default (store: Store, logger: Logger) => { const renderHost = getRenderHostInstance(); sideEffect( @@ -142,12 +141,14 @@ export default (store: Store, logger: Logger) => { ); } - renderHost.onIpcEvent('trackUsage', (...args: any[]) => { + const trackUsage = (...args: any[]) => { let state: State; try { state = store.getState(); } catch (e) { - // if trackUsage is called (indirectly) through a reducer, this will utterly die Flipper. Let's prevent that and log an error instead + // If trackUsage is called (indirectly) through a reducer, + // this will utterly kill Flipper. + // Let's prevent that and log an error instead. console.error( 'trackUsage triggered indirectly as side effect of a reducer', e, @@ -241,7 +242,11 @@ export default (store: Store, logger: Logger) => { largeFrameDrops = 0; logger.track('usage', 'ping', info); - }); + }; + + renderHost.onIpcEvent('trackUsage', trackUsage); + + setInterval(trackUsage, 60 * 1000); }; export function computeUsageSummary( diff --git a/desktop/static/main.tsx b/desktop/static/main.tsx index df44dfcac..c07e53b74 100644 --- a/desktop/static/main.tsx +++ b/desktop/static/main.tsx @@ -118,13 +118,6 @@ let deeplinkURL: string | undefined = argv.url; let filePath: string | undefined = argv.file; let didMount = false; -// tracking -setInterval(() => { - if (win) { - win.webContents.send('trackUsage'); - } -}, 60 * 1000); - // check if we already have an instance of this app open const gotTheLock = app.requestSingleInstanceLock();