diff --git a/fyo/telemetry/helpers.ts b/fyo/telemetry/helpers.ts index 0d5539f1..caa9860c 100644 --- a/fyo/telemetry/helpers.ts +++ b/fyo/telemetry/helpers.ts @@ -25,11 +25,17 @@ export function getDeviceId(fyo: Fyo): UniqueId { return deviceId; } -export function getInstanceId(fyo: Fyo): UniqueId { - const files = (fyo.config.get(ConfigKeys.Files) ?? []) as ConfigFile[]; - const instanceId = fyo.singles.SystemSettings!.instanceId as string; +export async function getInstanceId(fyo: Fyo): Promise { + const instanceId = (await fyo.getValue( + ModelNameEnum.SystemSettings, + 'instanceId' + )) as string; + const companyName = (await fyo.getValue( + ModelNameEnum.AccountingSettings, + 'companyName' + )) as string; const dbPath = fyo.db.dbPath!; - const companyName = fyo.singles.AccountingSettings!.companyName as string; + const files = (fyo.config.get(ConfigKeys.Files) ?? []) as ConfigFile[]; let file = files.find((f) => f.id === instanceId); diff --git a/fyo/telemetry/telemetry.ts b/fyo/telemetry/telemetry.ts index 46ccfc1f..0d8b913a 100644 --- a/fyo/telemetry/telemetry.ts +++ b/fyo/telemetry/telemetry.ts @@ -65,8 +65,8 @@ export class TelemetryManager { async start(openCount?: number) { this.#telemetryObject.country ||= getCountry(this.fyo); this.#telemetryObject.language ??= getLanguage(this.fyo); - this.#telemetryObject.device ||= getDeviceId(this.fyo); - this.#telemetryObject.instance ||= getInstanceId(this.fyo); + this.#telemetryObject.deviceId ||= getDeviceId(this.fyo); + this.#telemetryObject.instanceId ||= await getInstanceId(this.fyo); this.#telemetryObject.version ||= await getVersion(this.fyo); this.#started = true; @@ -91,7 +91,7 @@ export class TelemetryManager { } log(verb: Verb, noun: Noun, more?: Record) { - if (!this.#started) { + if (!this.#started && this.fyo.db.isConnected) { this.start().then(() => this.#sendBeacon(verb, noun, more)); return; } @@ -131,8 +131,8 @@ export class TelemetryManager { return { country: this.#telemetryObject.country!, language: this.#telemetryObject.language!, - device: this.#telemetryObject.device!, - instance: this.#telemetryObject.instance!, + deviceId: this.#telemetryObject.deviceId!, + instanceId: this.#telemetryObject.instanceId!, version: this.#telemetryObject.version!, openCount: this.#telemetryObject.openCount!, timestamp: DateTime.now().toMillis().toString(), @@ -145,8 +145,8 @@ export class TelemetryManager { #clear() { delete this.#telemetryObject.country; delete this.#telemetryObject.language; - delete this.#telemetryObject.device; - delete this.#telemetryObject.instance; + delete this.#telemetryObject.deviceId; + delete this.#telemetryObject.instanceId; delete this.#telemetryObject.version; delete this.#telemetryObject.openCount; } diff --git a/fyo/telemetry/types.ts b/fyo/telemetry/types.ts index 677e6905..c091cdf8 100644 --- a/fyo/telemetry/types.ts +++ b/fyo/telemetry/types.ts @@ -19,8 +19,8 @@ export enum Verb { export type Noun = string; export interface Telemetry { - device: UniqueId; - instance: UniqueId; + deviceId: UniqueId; + instanceId: UniqueId; platform?: Platform; country: string; language: string;