Skip to content

Commit 7c1e6de

Browse files
committed
fix: track exit timeout
1 parent 34510b5 commit 7c1e6de

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

package-lock.json

Lines changed: 17 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"moment": "^2.30.1",
127127
"p-queue": "^6.6.2",
128128
"p-retry": "^4.6.2",
129+
"p-timeout": "^4.1.0",
129130
"promisify-child-process": "^4.1.2",
130131
"sha": "^3.0.0",
131132
"source-map-support": "^0.5.21",

src/main/utils/track.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { v4 as uuidv4 } from 'uuid';
22
import got from 'got';
33
import { app, nativeTheme, screen } from 'electron';
44
import os from 'os';
5+
import pTimeout from 'p-timeout';
56
import { appConf } from './store';
67
import { logMain } from './logger';
78

@@ -121,7 +122,7 @@ class Analytics {
121122
`${this.baseURL}${this.collectURL}?measurement_id=${this.trackingId}&api_secret=${this.secretKey}`,
122123
{
123124
json: payload,
124-
timeout: 10 * 1000,
125+
timeout: 30 * 1000,
125126
},
126127
);
127128
}
@@ -183,11 +184,14 @@ class Tracker {
183184
async beforeExit() {
184185
logMain.info('[track.beforeExit]');
185186
if (this.lastPageView) {
186-
await this._event('page_view', {
187-
page_location: this.lastPageView.page_location,
188-
page_title: this.lastPageView.page_title,
189-
engagement_time_msec: Date.now() - this.lastPageView._ts,
190-
});
187+
await pTimeout(
188+
this._event('page_view', {
189+
page_location: this.lastPageView.page_location,
190+
page_title: this.lastPageView.page_title,
191+
engagement_time_msec: Date.now() - this.lastPageView._ts,
192+
}),
193+
1000,
194+
);
191195
}
192196
}
193197

0 commit comments

Comments
 (0)