2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

chore: change telemetry to a single select

This commit is contained in:
18alantom 2022-03-10 14:35:47 +05:30
parent d63e6e5cd8
commit 2e67dddc09
4 changed files with 38 additions and 29 deletions

View File

@ -1,4 +1,5 @@
import Store from 'electron-store';
import frappe from 'frappe';
const config = new Store();
export default config;
@ -8,9 +9,15 @@ export enum ConfigKeys {
LastSelectedFilePath = 'lastSelectedFilePath',
Language = 'language',
DeviceId = 'deviceId',
AnonymizedTelemetry = 'anonymizedTelemetry',
Telemetry = 'telemetry',
}
export const telemetryOptions = {
allow: frappe.t`Allow Telemetry`,
dontLogUsage: frappe.t`Don't Log Usage`,
dontLogAnything: frappe.t`Don't Log Anything`,
};
export interface ConfigFile {
id: string;
companyName: string;

View File

@ -7,7 +7,7 @@ import {
ValidationError,
} from 'frappe/common/errors';
import BaseDocument from 'frappe/model/document';
import config, { ConfigKeys } from './config';
import config, { ConfigKeys, telemetryOptions } from './config';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import telemetry from './telemetry/telemetry';
import { showMessageDialog, showToast } from './utils';
@ -20,7 +20,8 @@ interface ErrorLog {
}
function getCanLog(): boolean {
return !!config.get(ConfigKeys.AnonymizedTelemetry);
const telemetrySetting = config.get(ConfigKeys.Telemetry);
return telemetrySetting !== telemetryOptions.dontLogAnything;
}
function shouldNotStore(error: Error) {

View File

@ -9,16 +9,16 @@
@change="forwardChangeEvent"
/>
<div class="flex flex-row justify-between items-center w-full">
<div class="flex items-center rounded-lg">
<div class="flex items-center">
<FormControl
:df="anonymizedTelemetryDf"
:showLabel="true"
:value="anonymizedTelemetry"
@change="setAnonymizedTelemetry"
class="border-r pr-4"
:df="df"
:value="telemetry"
@change="setValue"
class="text-sm py-0 w-44"
:label-right="false"
/>
<LanguageSelector class="text-sm w-28" input-class="px-4 py-1.5" />
<div class="border-r h-6 mx-2" />
<LanguageSelector class="text-sm w-44" input-class="py-2" />
</div>
<button
class="
@ -41,7 +41,7 @@
import FormControl from '@/components/Controls/FormControl';
import LanguageSelector from '@/components/Controls/LanguageSelector.vue';
import TwoColumnForm from '@/components/TwoColumnForm';
import config, { ConfigKeys } from '@/config';
import config, { ConfigKeys, telemetryOptions } from '@/config';
import { checkForUpdates } from '@/utils';
import frappe from 'frappe';
@ -56,28 +56,23 @@ export default {
data() {
return {
doc: null,
anonymizedTelemetry: 0,
telemetry: '',
};
},
watch: {
anonymizedTelemetry(newValue) {
config.set(ConfigKeys.AnonymizedTelemetry, !!newValue);
},
},
async mounted() {
this.doc = frappe.SystemSettings;
this.companyName = frappe.AccountingSettings.companyName;
this.anonymizedTelemetry = Number(
config.get(ConfigKeys.AnonymizedTelemetry)
);
this.telemetry = config.get(ConfigKeys.Telemetry);
},
computed: {
anonymizedTelemetryDf() {
df() {
return {
fieldname: 'anonymizedTelemetry',
label: this.t`Anonymized Telemetry`,
fieldtype: 'Check',
default: 0,
fieldtype: 'Select',
options: Object.keys(telemetryOptions),
map: telemetryOptions,
default: 'allow',
description: this
.t`Send anonymized usage data and error reports to help improve the product.`,
};
@ -89,8 +84,9 @@ export default {
},
methods: {
checkForUpdates,
setAnonymizedTelemetry(value) {
this.anonymizedTelemetry = value;
setValue(value) {
this.telemetry = value;
config.set(ConfigKeys.Telemetry, value);
},
forwardChangeEvent(...args) {
this.$emit('change', ...args);

View File

@ -1,4 +1,4 @@
import config, { ConfigKeys } from '@/config';
import config, { ConfigKeys, telemetryOptions } from '@/config';
import frappe from 'frappe';
import { cloneDeep } from 'lodash';
import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers';
@ -18,8 +18,9 @@ class TelemetryManager {
this.#started = true;
}
getCanLog() {
return !!config.get(ConfigKeys.AnonymizedTelemetry);
getCanLog(): boolean {
const telemetrySetting = config.get(ConfigKeys.Telemetry) as string;
return telemetrySetting === telemetryOptions.allow;
}
log(verb: Verb, noun: Noun, more?: Record<string, unknown>) {
@ -27,7 +28,7 @@ class TelemetryManager {
this.start();
}
if (!this.getCanLog) {
if (!this.getCanLog()) {
return;
}
@ -56,6 +57,10 @@ class TelemetryManager {
this.#telemetryObject.version = frappe.store.appVersion ?? '';
this.#telemetryObject.counts = this.getCanLog() ? await getCounts() : {};
this.#telemetryObject.closeTime = new Date().valueOf();
if (config.get(ConfigKeys.Telemetry) === telemetryOptions.dontLogAnything) {
return;
}
}
get telemetryObject(): Readonly<Partial<Telemetry>> {