2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: allow post start start incase ids not set

This commit is contained in:
18alantom 2022-03-09 16:24:42 +05:30
parent 78397648d1
commit 11f192f22a
2 changed files with 21 additions and 11 deletions

View File

@ -14,7 +14,7 @@ export function getId(): string {
export function getLocale(): Locale {
// @ts-ignore
const country: string = frappe.AccountingSettings.country;
const country: string = frappe.AccountingSettings?.country ?? '';
const language: string = config.get('language') as string;
return { country, language };
@ -76,7 +76,11 @@ export function getInstanceId(): UniqueId {
const files = config.get(ConfigKeys.Files) as ConfigFile[];
// @ts-ignore
const companyName = frappe.AccountingSettings.companyName;
const companyName = frappe.AccountingSettings?.companyName;
if (companyName === undefined) {
return '';
}
const file = files.find((f) => f.companyName === companyName);
if (file === undefined) {

View File

@ -1,3 +1,4 @@
import { cloneDeep } from 'lodash';
import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers';
import { Noun, Telemetry, Verb } from './types';
@ -6,14 +7,11 @@ class TelemetryManager {
#telemetryObject: Partial<Telemetry> = {};
start() {
if (this.#started) {
return;
}
this.#telemetryObject.locale = getLocale();
this.#telemetryObject.deviceId = getDeviceId();
this.#telemetryObject.instanceId = getInstanceId();
this.#telemetryObject.openTime = new Date().valueOf();
this.#telemetryObject.timeline = [];
this.#telemetryObject.locale ||= getLocale();
this.#telemetryObject.deviceId ||= getDeviceId();
this.#telemetryObject.instanceId ||= getInstanceId();
this.#telemetryObject.openTime ||= new Date().valueOf();
this.#telemetryObject.timeline ??= [];
this.#started = true;
}
@ -29,10 +27,18 @@ class TelemetryManager {
this.#telemetryObject.timeline.push({ time, verb, noun, more });
}
async stop() {
// Will set ids if not set.
this.start();
this.#telemetryObject.counts = await getCounts();
this.#telemetryObject.closeTime = new Date().valueOf();
}
get telemetryObject(): Readonly<Partial<Telemetry>> {
return cloneDeep(this.#telemetryObject);
}
}
export const telemetryManager = new TelemetryManager();
export default new TelemetryManager();