mirror of
https://github.com/frappe/books.git
synced 2024-11-12 16:36:27 +00:00
incr: capture telemetryobject on unload
This commit is contained in:
parent
132edff44b
commit
f6219f956c
@ -96,7 +96,9 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
// second init with currency, normal usage
|
||||
await callInitializeMoneyMaker();
|
||||
|
||||
telemetry.start();
|
||||
await telemetry.setCount();
|
||||
return { connectionSuccess: true, reason: '' };
|
||||
}
|
||||
|
||||
|
11
src/main.js
11
src/main.js
@ -8,6 +8,7 @@ import config from './config';
|
||||
import { getErrorHandled, handleError } from './errorHandling';
|
||||
import { IPC_CHANNELS, IPC_MESSAGES } from './messages';
|
||||
import router from './router';
|
||||
import telemetry from './telemetry/telemetry';
|
||||
import { outsideClickDirective } from './ui';
|
||||
import { setLanguageMap, showToast, stringifyCircular } from './utils';
|
||||
(async () => {
|
||||
@ -135,4 +136,14 @@ function registerIpcRendererListeners() {
|
||||
error.name = 'Updation Error';
|
||||
handleError(true, error);
|
||||
});
|
||||
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (document.visibilityState !== 'hidden') {
|
||||
return;
|
||||
}
|
||||
|
||||
const telemetryData = telemetry.stop();
|
||||
console.log(telemetryData);
|
||||
// navigator.sendBeacon('', telemetryData)
|
||||
});
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class TelemetryManager {
|
||||
#telemetryObject: Partial<Telemetry> = {};
|
||||
|
||||
start() {
|
||||
this.#telemetryObject.locale ||= getLocale();
|
||||
this.#telemetryObject.locale = getLocale();
|
||||
this.#telemetryObject.deviceId ||= getDeviceId();
|
||||
this.#telemetryObject.instanceId ||= getInstanceId();
|
||||
this.#telemetryObject.openTime ||= new Date().valueOf();
|
||||
@ -49,18 +49,28 @@ class TelemetryManager {
|
||||
this.#telemetryObject.errors[name] += 1;
|
||||
}
|
||||
|
||||
async stop() {
|
||||
async setCount() {
|
||||
this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {};
|
||||
}
|
||||
|
||||
stop() {
|
||||
// Will set ids if not set.
|
||||
this.start();
|
||||
|
||||
//@ts-ignore
|
||||
this.#telemetryObject.version = frappe.store.appVersion ?? '';
|
||||
this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {};
|
||||
this.#telemetryObject.closeTime = new Date().valueOf();
|
||||
|
||||
const telemetryObject = this.#telemetryObject;
|
||||
|
||||
this.#started = false;
|
||||
this.#telemetryObject = {};
|
||||
|
||||
if (config.get(ConfigKeys.Telemetry) === TelemetrySetting.dontLogAnything) {
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
return JSON.stringify(telemetryObject);
|
||||
}
|
||||
|
||||
get telemetryObject(): Readonly<Partial<Telemetry>> {
|
||||
|
Loading…
Reference in New Issue
Block a user