From ee9421b8313a948169b141224cef81742b05c4de Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Sun, 14 Jul 2024 15:22:42 +0000 Subject: [PATCH] web/state/settings: add "disable analytics" option --- web/src/lib/settings/defaults.ts | 5 ++++- web/src/lib/state/settings.ts | 9 +++++++++ web/src/lib/types/settings.ts | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/web/src/lib/settings/defaults.ts b/web/src/lib/settings/defaults.ts index 3a727e1d..c8bdb8a6 100644 --- a/web/src/lib/settings/defaults.ts +++ b/web/src/lib/settings/defaults.ts @@ -3,7 +3,7 @@ import { defaultLocale } from "$lib/i18n/translations"; import type { CobaltSettings } from "$lib/types/settings"; const defaultSettings: CobaltSettings = { - schemaVersion: 1, + schemaVersion: 2, advanced: { debug: false, }, @@ -27,6 +27,9 @@ const defaultSettings: CobaltSettings = { youtubeVideoCodec: "h264", youtubeDubBrowserLang: false, }, + privacy: { + disableAnalytics: false + } } const defaultSettingsPage = () => { diff --git a/web/src/lib/state/settings.ts b/web/src/lib/state/settings.ts index 41f0cc68..1b62b750 100644 --- a/web/src/lib/state/settings.ts +++ b/web/src/lib/state/settings.ts @@ -9,6 +9,14 @@ import defaultSettings from '../settings/defaults'; type PartialSettings = RecursivePartial; type PartialSettingsWithSchema = RecursivePartial & { schemaVersion: number }; +const updatePlausiblePreference = (settings: PartialSettings) => { + if (settings.privacy?.disableAnalytics) { + localStorage.setItem('plausible_ignore', 'true'); + } else if (localStorage.getItem('plausible_ignore') !== null) { + localStorage.removeItem('plausible_ignore'); + } +} + const writeToStorage = (settings: PartialSettings) => { localStorage.setItem( "settings", @@ -69,6 +77,7 @@ export function updateSetting(partial: PartialSettings) { ) ); + updatePlausiblePreference(partial); return updated; }); } diff --git a/web/src/lib/types/settings.ts b/web/src/lib/types/settings.ts index dc962e71..bfeb2d10 100644 --- a/web/src/lib/types/settings.ts +++ b/web/src/lib/types/settings.ts @@ -19,6 +19,10 @@ type CobaltSettingsAdvanced = { debug: boolean, }; +type CobaltSettingsPrivacy = { + disableAnalytics: boolean +}; + type CobaltSettingsSave = { audioFormat: typeof audioFormatOptions[number], disableMetadata: boolean, @@ -38,6 +42,7 @@ export type CobaltSettings = { advanced: CobaltSettingsAdvanced, appearance: CobaltSettingsAppearance, save: CobaltSettingsSave, + privacy: CobaltSettingsPrivacy }; export type DownloadModeOption = CobaltSettings['save']['downloadMode'];