fix(desktop): persist tray icon preference

This commit is contained in:
t8y2 2026-05-28 19:21:43 +08:00
parent 3f64e830f8
commit c124ce3b69
4 changed files with 22 additions and 2 deletions

View File

@ -756,6 +756,7 @@ function onLoginSuccess() {
function initApp() {
const t0 = performance.now();
console.log("[STARTUP] initApp begin");
settingsStore.initDesktopSettings().catch(() => {});
savedSqlStore
.initFromStorage()
.then(() => {

View File

@ -335,6 +335,7 @@ impl Storage {
show_tray_icon: settings
.get("show_tray_icon")
.and_then(|value| value.as_bool())
.or_else(|| settings.get("run_in_background").and_then(|value| value.as_bool()))
.unwrap_or_else(|| DesktopSettings::default().show_tray_icon),
})
}
@ -1079,14 +1080,14 @@ mod tests {
}
#[tokio::test]
async fn desktop_settings_ignore_legacy_background_preference() {
async fn desktop_settings_fall_back_to_legacy_background_preference() {
let path = temp_db_path("desktop-settings-legacy-background");
let storage = Storage::open(&path).await.unwrap();
let mut settings = serde_json::Map::new();
settings.insert("run_in_background".to_string(), serde_json::Value::Bool(false));
storage.save_app_settings_json(&settings).await.unwrap();
assert_eq!(storage.load_desktop_settings().await.unwrap(), DesktopSettings { show_tray_icon: true });
assert_eq!(storage.load_desktop_settings().await.unwrap(), DesktopSettings { show_tray_icon: false });
}
#[tokio::test]

View File

@ -0,0 +1,9 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
test("desktop settings fall back to the legacy run_in_background preference during upgrades", () => {
const source = readFileSync("crates/dbx-core/src/storage.rs", "utf8");
assert.match(source, /\.or_else\(\|\| settings\.get\("run_in_background"\)\.and_then\(\|value\| value\.as_bool\(\)\)\)/);
});

View File

@ -0,0 +1,9 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
test("app startup eagerly loads desktop settings so tray preference is not reset in the UI", () => {
const source = readFileSync("apps/desktop/src/App.vue", "utf8");
assert.match(source, /settingsStore\.initDesktopSettings\(\)\.catch\(\(\) => \{\}\);/);
});