From 132edff44bd10bf43cb012cb1e16d7b2e710b6b0 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Thu, 10 Mar 2022 16:01:55 +0530 Subject: [PATCH] fix: log level checks --- src/config.ts | 12 +++++++++--- src/errorHandling.ts | 4 ++-- src/telemetry/telemetry.ts | 6 +++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/config.ts b/src/config.ts index 12979a32..17f0321d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,10 +12,16 @@ export enum ConfigKeys { Telemetry = 'telemetry', } +export enum TelemetrySetting { + allow = 'allow', + dontLogUsage = 'dontLogUsage', + dontLogAnything = 'dontLogAnything', +} + export const telemetryOptions = { - allow: frappe.t`Allow Telemetry`, - dontLogUsage: frappe.t`Don't Log Usage`, - dontLogAnything: frappe.t`Don't Log Anything`, + [TelemetrySetting.allow]: frappe.t`Allow Telemetry`, + [TelemetrySetting.dontLogUsage]: frappe.t`Don't Log Usage`, + [TelemetrySetting.dontLogAnything]: frappe.t`Don't Log Anything`, }; export interface ConfigFile { diff --git a/src/errorHandling.ts b/src/errorHandling.ts index f9905a8a..4f3f7231 100644 --- a/src/errorHandling.ts +++ b/src/errorHandling.ts @@ -7,7 +7,7 @@ import { ValidationError, } from 'frappe/common/errors'; import BaseDocument from 'frappe/model/document'; -import config, { ConfigKeys, telemetryOptions } from './config'; +import config, { ConfigKeys, TelemetrySetting } from './config'; import { IPC_ACTIONS, IPC_MESSAGES } from './messages'; import telemetry from './telemetry/telemetry'; import { showMessageDialog, showToast } from './utils'; @@ -21,7 +21,7 @@ interface ErrorLog { function getCanLog(): boolean { const telemetrySetting = config.get(ConfigKeys.Telemetry); - return telemetrySetting !== telemetryOptions.dontLogAnything; + return telemetrySetting !== TelemetrySetting.dontLogAnything; } function shouldNotStore(error: Error) { diff --git a/src/telemetry/telemetry.ts b/src/telemetry/telemetry.ts index 9b64a8b7..da2ca493 100644 --- a/src/telemetry/telemetry.ts +++ b/src/telemetry/telemetry.ts @@ -1,4 +1,4 @@ -import config, { ConfigKeys, telemetryOptions } from '@/config'; +import config, { ConfigKeys, TelemetrySetting } from '@/config'; import frappe from 'frappe'; import { cloneDeep } from 'lodash'; import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers'; @@ -20,7 +20,7 @@ class TelemetryManager { getCanLog(): boolean { const telemetrySetting = config.get(ConfigKeys.Telemetry) as string; - return telemetrySetting === telemetryOptions.allow; + return telemetrySetting === TelemetrySetting.allow; } log(verb: Verb, noun: Noun, more?: Record) { @@ -58,7 +58,7 @@ class TelemetryManager { this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {}; this.#telemetryObject.closeTime = new Date().valueOf(); - if (config.get(ConfigKeys.Telemetry) === telemetryOptions.dontLogAnything) { + if (config.get(ConfigKeys.Telemetry) === TelemetrySetting.dontLogAnything) { return; } }