2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 18:24:40 +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">
<HowTo
link="https://github.com/frappe/books/wiki/Anonymized-Opt-In-Telemetry"
class="
text-sm
hover:text-gray-900
text-gray-800
py-1
justify-between
"
class="text-sm hover:text-gray-900 text-gray-800 py-1 justify-between"
:icon="false"
>{{ t`Know More` }}</HowTo
>
@ -60,11 +54,14 @@ ConfigKeys,
telemetryOptions,
TelemetrySetting
} from '@/config';
import telemetry from '@/telemetry/telemetry';
import { NounEnum, Verb } from '@/telemetry/types';
import Button from '../Button.vue';
import FormControl from '../Controls/FormControl';
import FeatherIcon from '../FeatherIcon.vue';
import HowTo from '../HowTo.vue';
import Modal from '../Modal.vue';
export default {
components: { Modal, FormControl, Button, HowTo, FeatherIcon },
data() {
@ -106,6 +103,12 @@ export default {
},
methods: {
saveClicked() {
if (this.value === TelemetrySetting.dontLogUsage) {
telemetry.finalLogAndStop();
} else {
telemetry.log(Verb.Started, NounEnum.Telemetry)
}
config.set(ConfigKeys.Telemetry, this.value);
this.shouldOpen = false;
},

View File

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

View File

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

View File

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

View File

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