From f404aa53c6f8c8b6b54369b9de40374352fb9b45 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 26 Aug 2024 12:06:56 -0700 Subject: [PATCH] Option to disable telemetry --- package-lock.json | 8 ++++---- package.json | 2 +- plugin-runtime-types/package.json | 2 +- plugin-runtime-types/src/gen/Settings.ts | 2 +- .../migrations/20240826184943_disable-telemetry.sql | 1 + src-tauri/src/analytics.rs | 13 +++++++++---- src-tauri/yaak_models/src/models.rs | 3 +++ src-tauri/yaak_models/src/queries.rs | 4 ++++ src-web/components/CookieDialog.tsx | 2 +- src-web/components/Settings/SettingsGeneral.tsx | 6 ++++++ src-web/hooks/useCookieJars.ts | 2 +- src-web/hooks/useCreateCookieJar.ts | 2 +- src-web/hooks/useDeleteCookieJar.tsx | 2 +- src-web/hooks/useSettings.ts | 2 +- src-web/hooks/useUpdateCookieJar.ts | 2 +- src-web/hooks/useUpdateSettings.ts | 2 +- src-web/lib/models.ts | 7 +------ src-web/lib/models/Cookie.ts | 5 ----- src-web/lib/models/CookieDomain.ts | 3 --- src-web/lib/models/CookieExpires.ts | 3 --- src-web/lib/models/CookieJar.ts | 4 ---- src-web/lib/models/Settings.ts | 3 --- src-web/lib/store.ts | 12 +++++++++--- 23 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 src-tauri/migrations/20240826184943_disable-telemetry.sql delete mode 100644 src-web/lib/models/Cookie.ts delete mode 100644 src-web/lib/models/CookieDomain.ts delete mode 100644 src-web/lib/models/CookieExpires.ts delete mode 100644 src-web/lib/models/CookieJar.ts delete mode 100644 src-web/lib/models/Settings.ts diff --git a/package-lock.json b/package-lock.json index 6cbba48d..e7c6d30c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "@tauri-apps/plugin-log": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "^2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0-rc.0", - "@yaakapp/api": "^0.1.12", + "@yaakapp/api": "^0.1.13", "buffer": "^6.0.3", "classnames": "^2.3.2", "cm6-graphql": "^0.0.9", @@ -2990,9 +2990,9 @@ "integrity": "sha512-N8tkAACJx2ww8vFMneJmaAgmjAG1tnVBZJRLRcx061tmsLRZHSEZSLuGWnwPtunsSLvSqXQ2wfp7Mgqg1I+2dQ==" }, "node_modules/@yaakapp/api": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.12.tgz", - "integrity": "sha512-qA+2BBZz1LGTi0wsOmlwaw6xJbE3elPIUMt/BkiRT+DqQC5spZtISsyoPXjtsM0xZc2orjoRJd0LesXH7xkD0g==", + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/@yaakapp/api/-/api-0.1.13.tgz", + "integrity": "sha512-FSYPHZV0mP967w63VXi9zYP81hPo3vjSW3/UElJLuF/8ig6WmG4p1q2oYos4Ik267Z3qSQAGN5dPMfuk3DAnBA==", "dependencies": { "@types/node": "^22.0.0" } diff --git a/package.json b/package.json index 6207134d..1e9590dc 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@tauri-apps/plugin-log": "^2.0.0-rc.0", "@tauri-apps/plugin-os": "^2.0.0-rc.0", "@tauri-apps/plugin-shell": "^2.0.0-rc.0", - "@yaakapp/api": "^0.1.12", + "@yaakapp/api": "^0.1.13", "buffer": "^6.0.3", "classnames": "^2.3.2", "cm6-graphql": "^0.0.9", diff --git a/plugin-runtime-types/package.json b/plugin-runtime-types/package.json index d82a2084..22214170 100644 --- a/plugin-runtime-types/package.json +++ b/plugin-runtime-types/package.json @@ -1,6 +1,6 @@ { "name": "@yaakapp/api", - "version": "0.1.12", + "version": "0.1.13", "main": "lib/index.js", "typings": "./lib/index.d.ts", "files": [ diff --git a/plugin-runtime-types/src/gen/Settings.ts b/plugin-runtime-types/src/gen/Settings.ts index 78548f5f..fa6c147b 100644 --- a/plugin-runtime-types/src/gen/Settings.ts +++ b/plugin-runtime-types/src/gen/Settings.ts @@ -1,3 +1,3 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -export type Settings = { id: string, model: "settings", createdAt: string, updatedAt: string, theme: string, appearance: string, themeDark: string, themeLight: string, updateChannel: string, interfaceFontSize: number, interfaceScale: number, editorFontSize: number, editorSoftWrap: boolean, openWorkspaceNewWindow: boolean | null, }; +export type Settings = { id: string, model: "settings", createdAt: string, updatedAt: string, theme: string, appearance: string, themeDark: string, themeLight: string, updateChannel: string, interfaceFontSize: number, interfaceScale: number, editorFontSize: number, editorSoftWrap: boolean, telemetry: boolean, openWorkspaceNewWindow: boolean | null, }; diff --git a/src-tauri/migrations/20240826184943_disable-telemetry.sql b/src-tauri/migrations/20240826184943_disable-telemetry.sql new file mode 100644 index 00000000..53ea8271 --- /dev/null +++ b/src-tauri/migrations/20240826184943_disable-telemetry.sql @@ -0,0 +1 @@ +ALTER TABLE settings ADD COLUMN telemetry BOOLEAN DEFAULT TRUE; diff --git a/src-tauri/src/analytics.rs b/src-tauri/src/analytics.rs index 63ca5651..59638cf9 100644 --- a/src-tauri/src/analytics.rs +++ b/src-tauri/src/analytics.rs @@ -5,9 +5,7 @@ use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; use tauri::{Manager, Runtime, WebviewWindow}; -use yaak_models::queries::{ - generate_id, get_key_value_int, get_key_value_string, set_key_value_int, set_key_value_string, -}; +use yaak_models::queries::{generate_id, get_key_value_int, get_key_value_string, get_or_create_settings, set_key_value_int, set_key_value_string}; use crate::is_dev; @@ -157,6 +155,7 @@ pub async fn track_event( action: AnalyticsAction, attributes: Option, ) { + let id = get_id(w).await; let event = format!("{}.{}", resource, action); let attributes_json = attributes.unwrap_or("{}".to_string().into()).to_string(); @@ -186,9 +185,15 @@ pub async fn track_event( .get(format!("{base_url}/t/e")) .query(¶ms); + let settings = get_or_create_settings(w).await; + if !settings.telemetry { + info!("Track event (disabled): {}", event); + return + } + // Disable analytics actual sending in dev if is_dev() { - debug!("track: {} {}", event, attributes_json); + debug!("Track event: {} {}", event, attributes_json); return; } diff --git a/src-tauri/yaak_models/src/models.rs b/src-tauri/yaak_models/src/models.rs index ef8da95a..1f2f95f6 100644 --- a/src-tauri/yaak_models/src/models.rs +++ b/src-tauri/yaak_models/src/models.rs @@ -23,6 +23,7 @@ pub struct Settings { pub interface_scale: i32, pub editor_font_size: i32, pub editor_soft_wrap: bool, + pub telemetry: bool, pub open_workspace_new_window: Option, } @@ -43,6 +44,7 @@ pub enum SettingsIden { InterfaceScale, EditorFontSize, EditorSoftWrap, + Telemetry, OpenWorkspaceNewWindow, } @@ -64,6 +66,7 @@ impl<'s> TryFrom<&Row<'s>> for Settings { interface_scale: r.get("interface_scale")?, editor_font_size: r.get("editor_font_size")?, editor_soft_wrap: r.get("editor_soft_wrap")?, + telemetry: r.get("telemetry")?, open_workspace_new_window: r.get("open_workspace_new_window")?, }) } diff --git a/src-tauri/yaak_models/src/queries.rs b/src-tauri/yaak_models/src/queries.rs index 9f73bc5e..74a65495 100644 --- a/src-tauri/yaak_models/src/queries.rs +++ b/src-tauri/yaak_models/src/queries.rs @@ -799,6 +799,10 @@ pub async fn update_settings( SettingsIden::EditorSoftWrap, settings.editor_soft_wrap.into(), ), + ( + SettingsIden::Telemetry, + settings.telemetry.into(), + ), ( SettingsIden::OpenWorkspaceNewWindow, settings.open_workspace_new_window.into(), diff --git a/src-web/components/CookieDialog.tsx b/src-web/components/CookieDialog.tsx index 4c5c7866..f634eb0d 100644 --- a/src-web/components/CookieDialog.tsx +++ b/src-web/components/CookieDialog.tsx @@ -1,6 +1,6 @@ +import type { Cookie } from '@yaakapp/api'; import { useCookieJars } from '../hooks/useCookieJars'; import { useUpdateCookieJar } from '../hooks/useUpdateCookieJar'; -import type { Cookie } from '../lib/models/Cookie'; import { cookieDomain } from '../lib/models'; import { Banner } from './core/Banner'; import { IconButton } from './core/IconButton'; diff --git a/src-web/components/Settings/SettingsGeneral.tsx b/src-web/components/Settings/SettingsGeneral.tsx index aab2b240..6a260ab4 100644 --- a/src-web/components/Settings/SettingsGeneral.tsx +++ b/src-web/components/Settings/SettingsGeneral.tsx @@ -77,6 +77,12 @@ export function SettingsGeneral() { { label: 'New Window', value: 'new' }, ]} /> + updateSettings.mutate({ telemetry })} + /> + diff --git a/src-web/hooks/useCookieJars.ts b/src-web/hooks/useCookieJars.ts index 50949f4b..e78c0a8b 100644 --- a/src-web/hooks/useCookieJars.ts +++ b/src-web/hooks/useCookieJars.ts @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query'; -import type { CookieJar } from '../lib/models'; +import type { CookieJar } from '@yaakapp/api'; import { invokeCmd } from '../lib/tauri'; import { useActiveWorkspace } from './useActiveWorkspace'; diff --git a/src-web/hooks/useCreateCookieJar.ts b/src-web/hooks/useCreateCookieJar.ts index c2622569..0964610b 100644 --- a/src-web/hooks/useCreateCookieJar.ts +++ b/src-web/hooks/useCreateCookieJar.ts @@ -1,6 +1,6 @@ import { useMutation } from '@tanstack/react-query'; +import type { CookieJar } from '@yaakapp/api'; import { trackEvent } from '../lib/analytics'; -import type { CookieJar } from '../lib/models'; import { invokeCmd } from '../lib/tauri'; import { useActiveWorkspace } from './useActiveWorkspace'; import { usePrompt } from './usePrompt'; diff --git a/src-web/hooks/useDeleteCookieJar.tsx b/src-web/hooks/useDeleteCookieJar.tsx index 6de10169..b98d002d 100644 --- a/src-web/hooks/useDeleteCookieJar.tsx +++ b/src-web/hooks/useDeleteCookieJar.tsx @@ -1,7 +1,7 @@ import { useMutation } from '@tanstack/react-query'; +import type { CookieJar } from '@yaakapp/api'; import { InlineCode } from '../components/core/InlineCode'; import { trackEvent } from '../lib/analytics'; -import type { CookieJar } from '../lib/models'; import { invokeCmd } from '../lib/tauri'; import { useConfirm } from './useConfirm'; diff --git a/src-web/hooks/useSettings.ts b/src-web/hooks/useSettings.ts index 51847d3d..470686ca 100644 --- a/src-web/hooks/useSettings.ts +++ b/src-web/hooks/useSettings.ts @@ -1,6 +1,6 @@ +import type { Settings } from '@yaakapp/api'; import { useAtomValue } from 'jotai'; import { atom } from 'jotai/index'; -import type { Settings } from '../lib/models/Settings'; import { getSettings } from '../lib/store'; const settings = await getSettings(); diff --git a/src-web/hooks/useUpdateCookieJar.ts b/src-web/hooks/useUpdateCookieJar.ts index 4c8be267..8a186f5f 100644 --- a/src-web/hooks/useUpdateCookieJar.ts +++ b/src-web/hooks/useUpdateCookieJar.ts @@ -1,5 +1,5 @@ import { useMutation } from '@tanstack/react-query'; -import type { CookieJar } from '../lib/models'; +import type { CookieJar } from '@yaakapp/api'; import { getCookieJar } from '../lib/store'; import { invokeCmd } from '../lib/tauri'; diff --git a/src-web/hooks/useUpdateSettings.ts b/src-web/hooks/useUpdateSettings.ts index e196de84..9f81a937 100644 --- a/src-web/hooks/useUpdateSettings.ts +++ b/src-web/hooks/useUpdateSettings.ts @@ -1,5 +1,5 @@ import { useMutation } from '@tanstack/react-query'; -import type { Settings } from '../lib/models'; +import type { Settings } from '@yaakapp/api'; import { getSettings } from '../lib/store'; import { invokeCmd } from '../lib/tauri'; diff --git a/src-web/lib/models.ts b/src-web/lib/models.ts index a4f4033f..27935139 100644 --- a/src-web/lib/models.ts +++ b/src-web/lib/models.ts @@ -1,9 +1,4 @@ -import type { GrpcConnection, HttpResponse, HttpResponseHeader, Model } from '@yaakapp/api'; -import type { Cookie } from './models/Cookie'; -import type { CookieJar } from './models/CookieJar'; -import type { Settings } from './models/Settings'; - -export type { CookieJar, Cookie, Settings }; +import type { Cookie, GrpcConnection, HttpResponse, HttpResponseHeader, Model } from '@yaakapp/api'; export const BODY_TYPE_NONE = null; export const BODY_TYPE_GRAPHQL = 'graphql'; diff --git a/src-web/lib/models/Cookie.ts b/src-web/lib/models/Cookie.ts deleted file mode 100644 index 6d2dfc77..00000000 --- a/src-web/lib/models/Cookie.ts +++ /dev/null @@ -1,5 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { CookieDomain } from "./CookieDomain"; -import type { CookieExpires } from "./CookieExpires"; - -export type Cookie = { raw_cookie: string, domain: CookieDomain, expires: CookieExpires, path: [string, boolean], }; diff --git a/src-web/lib/models/CookieDomain.ts b/src-web/lib/models/CookieDomain.ts deleted file mode 100644 index 5ee87594..00000000 --- a/src-web/lib/models/CookieDomain.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type CookieDomain = { "HostOnly": string } | { "Suffix": string } | "NotPresent" | "Empty"; diff --git a/src-web/lib/models/CookieExpires.ts b/src-web/lib/models/CookieExpires.ts deleted file mode 100644 index 1e936e38..00000000 --- a/src-web/lib/models/CookieExpires.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type CookieExpires = { "AtUtc": string } | "SessionEnd"; diff --git a/src-web/lib/models/CookieJar.ts b/src-web/lib/models/CookieJar.ts deleted file mode 100644 index aa67f049..00000000 --- a/src-web/lib/models/CookieJar.ts +++ /dev/null @@ -1,4 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. -import type { Cookie } from "./Cookie"; - -export type CookieJar = { id: string, model: "cookie_jar", createdAt: string, updatedAt: string, workspaceId: string, name: string, cookies: Array, }; diff --git a/src-web/lib/models/Settings.ts b/src-web/lib/models/Settings.ts deleted file mode 100644 index 78548f5f..00000000 --- a/src-web/lib/models/Settings.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type Settings = { id: string, model: "settings", createdAt: string, updatedAt: string, theme: string, appearance: string, themeDark: string, themeLight: string, updateChannel: string, interfaceFontSize: number, interfaceScale: number, editorFontSize: number, editorSoftWrap: boolean, openWorkspaceNewWindow: boolean | null, }; diff --git a/src-web/lib/store.ts b/src-web/lib/store.ts index 8634a040..45f86962 100644 --- a/src-web/lib/store.ts +++ b/src-web/lib/store.ts @@ -1,6 +1,12 @@ -import type { Environment, Folder, GrpcRequest, HttpRequest, Workspace } from '@yaakapp/api'; -import type { CookieJar } from './models/CookieJar'; -import type { Settings } from './models/Settings'; +import type { + CookieJar, + Environment, + Folder, + GrpcRequest, + HttpRequest, + Settings, + Workspace, +} from '@yaakapp/api'; import { invokeCmd } from './tauri'; export async function getSettings(): Promise {