2
0
mirror of https://github.com/frappe/books.git synced 2025-01-11 02:36:14 +00:00

fix: add final log on switching off telemetry

This commit is contained in:
18alantom 2022-03-15 16:28:43 +05:30
parent 391cd8544c
commit 20578d2ab5
5 changed files with 34 additions and 13 deletions

View File

@ -32,13 +32,7 @@
<div class="flex flex-row w-full justify-between items-center mt-12"> <div class="flex flex-row w-full justify-between items-center mt-12">
<HowTo <HowTo
link="https://github.com/frappe/books/wiki/Anonymized-Opt-In-Telemetry" link="https://github.com/frappe/books/wiki/Anonymized-Opt-In-Telemetry"
class=" class="text-sm hover:text-gray-900 text-gray-800 py-1 justify-between"
text-sm
hover:text-gray-900
text-gray-800
py-1
justify-between
"
:icon="false" :icon="false"
>{{ t`Know More` }}</HowTo >{{ t`Know More` }}</HowTo
> >
@ -60,11 +54,14 @@ ConfigKeys,
telemetryOptions, telemetryOptions,
TelemetrySetting TelemetrySetting
} from '@/config'; } from '@/config';
import telemetry from '@/telemetry/telemetry';
import { NounEnum, Verb } from '@/telemetry/types';
import Button from '../Button.vue'; import Button from '../Button.vue';
import FormControl from '../Controls/FormControl'; import FormControl from '../Controls/FormControl';
import FeatherIcon from '../FeatherIcon.vue'; import FeatherIcon from '../FeatherIcon.vue';
import HowTo from '../HowTo.vue'; import HowTo from '../HowTo.vue';
import Modal from '../Modal.vue'; import Modal from '../Modal.vue';
export default { export default {
components: { Modal, FormControl, Button, HowTo, FeatherIcon }, components: { Modal, FormControl, Button, HowTo, FeatherIcon },
data() { data() {
@ -106,6 +103,12 @@ export default {
}, },
methods: { methods: {
saveClicked() { saveClicked() {
if (this.value === TelemetrySetting.dontLogUsage) {
telemetry.finalLogAndStop();
} else {
telemetry.log(Verb.Started, NounEnum.Telemetry)
}
config.set(ConfigKeys.Telemetry, this.value); config.set(ConfigKeys.Telemetry, this.value);
this.shouldOpen = false; this.shouldOpen = false;
}, },

View File

@ -158,7 +158,6 @@ function registerIpcRendererListeners() {
return; return;
} }
const { url, data } = telemetry.stop(); telemetry.stop();
navigator.sendBeacon(url, data);
}); });
} }

View File

@ -41,7 +41,12 @@
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import LanguageSelector from '@/components/Controls/LanguageSelector.vue'; import LanguageSelector from '@/components/Controls/LanguageSelector.vue';
import TwoColumnForm from '@/components/TwoColumnForm'; import TwoColumnForm from '@/components/TwoColumnForm';
import config, { ConfigKeys, telemetryOptions } from '@/config'; import config, {
ConfigKeys,
telemetryOptions,
TelemetrySetting
} from '@/config';
import telemetry from '@/telemetry/telemetry';
import { checkForUpdates } from '@/utils'; import { checkForUpdates } from '@/utils';
import frappe from 'frappe'; import frappe from 'frappe';
@ -86,6 +91,12 @@ export default {
checkForUpdates, checkForUpdates,
setValue(value) { setValue(value) {
this.telemetry = value; this.telemetry = value;
if (value === TelemetrySetting.dontLogAnything) {
telemetry.finalLogAndStop();
} else {
telemetry.log(Verb.Started, NounEnum.Telemetry);
}
config.set(ConfigKeys.Telemetry, value); config.set(ConfigKeys.Telemetry, value);
}, },
forwardChangeEvent(...args) { forwardChangeEvent(...args) {

View File

@ -2,7 +2,7 @@ import config, { ConfigKeys, TelemetrySetting } from '@/config';
import frappe from 'frappe'; import frappe from 'frappe';
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers'; import { getCounts, getDeviceId, getInstanceId, getLocale } from './helpers';
import { Noun, Telemetry, Verb } from './types'; import { Noun, NounEnum, Telemetry, Verb } from './types';
class TelemetryManager { class TelemetryManager {
#url: string = ''; #url: string = '';
@ -74,7 +74,7 @@ class TelemetryManager {
this.#telemetryObject = {}; this.#telemetryObject = {};
if (config.get(ConfigKeys.Telemetry) === TelemetrySetting.dontLogAnything) { if (config.get(ConfigKeys.Telemetry) === TelemetrySetting.dontLogAnything) {
return ''; return;
} }
const data = JSON.stringify({ const data = JSON.stringify({
@ -82,7 +82,12 @@ class TelemetryManager {
telemetryData: telemetryObject, telemetryData: telemetryObject,
}); });
return { url: this.#url, data }; navigator.sendBeacon(this.#url, data);
}
finalLogAndStop() {
this.log(Verb.Stopped, NounEnum.Telemetry);
this.stop();
} }
get telemetryObject(): Readonly<Partial<Telemetry>> { get telemetryObject(): Readonly<Partial<Telemetry>> {

View File

@ -38,10 +38,13 @@ export enum Verb {
Navigated = 'navigated', Navigated = 'navigated',
Imported = 'imported', Imported = 'imported',
Exported = 'exported', Exported = 'exported',
Stopped = 'stopped',
Started = 'stopped',
} }
export enum NounEnum { export enum NounEnum {
Route = 'route', Route = 'route',
Telemetry = 'telemetry',
} }
export type Noun = string | NounEnum; export type Noun = string | NounEnum;