From f8b0510d0871926d189af49da2461b87a87f1009 Mon Sep 17 00:00:00 2001 From: Gabriel Oliveira Date: Fri, 8 Aug 2025 17:25:55 -0300 Subject: [PATCH] feat(settings): add do not check for updates (#246) Co-authored-by: Gregory Schier --- src-tauri/src/lib.rs | 11 +++++++---- src-tauri/yaak-models/bindings/gen_models.ts | 2 +- .../20250727190746_autoupdate_setting.sql | 1 + src-tauri/yaak-models/src/models.rs | 4 ++++ src-tauri/yaak-models/src/queries/settings.rs | 1 + src-web/components/Settings/SettingsGeneral.tsx | 15 +++++++++++++++ 6 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 src-tauri/yaak-models/migrations/20250727190746_autoupdate_setting.sql diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 4ab42bbb..a31b0776 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1389,12 +1389,15 @@ pub fn run() { } => { let w = app_handle.get_webview_window(&label).unwrap(); let h = app_handle.clone(); + // Run update check whenever the window is focused tauri::async_runtime::spawn(async move { - let val: State<'_, Mutex> = h.state(); - let update_mode = get_update_mode(&w).await.unwrap(); - if let Err(e) = val.lock().await.maybe_check(&w, update_mode).await { - warn!("Failed to check for updates {e:?}"); + if w.db().get_settings().autoupdate { + let val: State<'_, Mutex> = h.state(); + let update_mode = get_update_mode(&w).await.unwrap(); + if let Err(e) = val.lock().await.maybe_check(&w, update_mode).await { + warn!("Failed to check for updates {e:?}"); + }; }; }); diff --git a/src-tauri/yaak-models/bindings/gen_models.ts b/src-tauri/yaak-models/bindings/gen_models.ts index c36185b2..accd0c2c 100644 --- a/src-tauri/yaak-models/bindings/gen_models.ts +++ b/src-tauri/yaak-models/bindings/gen_models.ts @@ -62,7 +62,7 @@ export type ProxySetting = { "type": "enabled", http: string, https: string, aut export type ProxySettingAuth = { user: string, password: string, }; -export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, }; +export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, autoupdate: boolean, }; export type SyncState = { model: "sync_state", id: string, workspaceId: string, createdAt: string, updatedAt: string, flushedAt: string, modelId: string, checksum: string, relPath: string, syncDir: string, }; diff --git a/src-tauri/yaak-models/migrations/20250727190746_autoupdate_setting.sql b/src-tauri/yaak-models/migrations/20250727190746_autoupdate_setting.sql new file mode 100644 index 00000000..0ac9c1f2 --- /dev/null +++ b/src-tauri/yaak-models/migrations/20250727190746_autoupdate_setting.sql @@ -0,0 +1 @@ +ALTER TABLE settings ADD COLUMN autoupdate BOOLEAN DEFAULT true NOT NULL; diff --git a/src-tauri/yaak-models/src/models.rs b/src-tauri/yaak-models/src/models.rs index 1f5daf5a..959f02b4 100644 --- a/src-tauri/yaak-models/src/models.rs +++ b/src-tauri/yaak-models/src/models.rs @@ -120,6 +120,7 @@ pub struct Settings { pub theme_dark: String, pub theme_light: String, pub update_channel: String, + pub autoupdate: bool, } impl UpsertModelInfo for Settings { @@ -168,6 +169,7 @@ impl UpsertModelInfo for Settings { (ThemeDark, self.theme_dark.as_str().into()), (ThemeLight, self.theme_light.as_str().into()), (UpdateChannel, self.update_channel.into()), + (Autoupdate, self.autoupdate.into()), (ColoredMethods, self.colored_methods.into()), (Proxy, proxy.into()), ]) @@ -190,6 +192,7 @@ impl UpsertModelInfo for Settings { SettingsIden::ThemeDark, SettingsIden::ThemeLight, SettingsIden::UpdateChannel, + SettingsIden::Autoupdate, SettingsIden::ColoredMethods, ] } @@ -219,6 +222,7 @@ impl UpsertModelInfo for Settings { theme_light: row.get("theme_light")?, hide_window_controls: row.get("hide_window_controls")?, update_channel: row.get("update_channel")?, + autoupdate: row.get("autoupdate")?, colored_methods: row.get("colored_methods")?, }) } diff --git a/src-tauri/yaak-models/src/queries/settings.rs b/src-tauri/yaak-models/src/queries/settings.rs index 85b273fa..3a4dffa1 100644 --- a/src-tauri/yaak-models/src/queries/settings.rs +++ b/src-tauri/yaak-models/src/queries/settings.rs @@ -31,6 +31,7 @@ impl<'a> DbContext<'a> { theme_dark: "yaak-dark".to_string(), theme_light: "yaak-light".to_string(), update_channel: "stable".to_string(), + autoupdate: true, colored_methods: false, }; self.upsert(&settings, &UpdateSource::Background).expect("Failed to upsert settings") diff --git a/src-web/components/Settings/SettingsGeneral.tsx b/src-web/components/Settings/SettingsGeneral.tsx index a58f8d26..7a95f9a8 100644 --- a/src-web/components/Settings/SettingsGeneral.tsx +++ b/src-web/components/Settings/SettingsGeneral.tsx @@ -49,6 +49,21 @@ export function SettingsGeneral() { onClick={() => checkForUpdates.mutateAsync()} /> + +