From 4c55c284ad255c2e1e98356df7136e4afd5e3fff Mon Sep 17 00:00:00 2001 From: ZouYonghe <1259085392z@gmail.com> Date: Sun, 22 Nov 2026 01:04:37 +0900 Subject: [PATCH 01/10] fix: sync the desktop startup theme with the dashboard --- ...bridge-bootstrap-updater-contract.test.mjs | 38 ++++++++++- .../startup-shell-copy.test.mjs | 28 ++++++++ src-tauri/src/app_runtime.rs | 23 +++++-- src-tauri/src/bridge/commands.rs | 29 ++++++++ src-tauri/src/bridge_bootstrap.js | 39 +++++++++++ src-tauri/src/desktop_settings.rs | 66 +++++++++++++++++++ src-tauri/src/window/startup_loading.rs | 15 ++++- ui/index.html | 38 ++++++++++- 8 files changed, 263 insertions(+), 13 deletions(-) diff --git a/scripts/prepare-resources/bridge-bootstrap-updater-contract.test.mjs b/scripts/prepare-resources/bridge-bootstrap-updater-contract.test.mjs index 7f765ea8..e65d99e1 100644 --- a/scripts/prepare-resources/bridge-bootstrap-updater-contract.test.mjs +++ b/scripts/prepare-resources/bridge-bootstrap-updater-contract.test.mjs @@ -37,8 +37,21 @@ function runBootstrap(source, authResults, sharedState = {}) { sharedState.navigation = navigation; const invocations = []; const intervals = []; - const localStorage = createStorage(localValues); - const sessionStorage = createStorage(sessionValues); + // Native Storage objects do not accept instance-level method overrides. + class Storage {} + if (sharedState.nativeStorage) { + Object.assign(Storage.prototype, { + getItem(key) { return this.values.get(key) ?? null; }, + setItem(key, value) { this.values.set(String(key), String(value)); }, + removeItem(key) { this.values.delete(String(key)); }, + clear() { this.values.clear(); }, + }); + } + const makeStorage = (values) => sharedState.nativeStorage + ? Object.preventExtensions(Object.assign(new Storage(), { values })) + : createStorage(values); + const localStorage = makeStorage(localValues); + const sessionStorage = makeStorage(sessionValues); const location = { href: 'http://127.0.0.1:6185/#/auth/login', origin: 'http://127.0.0.1:6185', @@ -53,6 +66,7 @@ function runBootstrap(source, authResults, sharedState = {}) { }, }; const window = { + Storage: sharedState.nativeStorage ? Storage : undefined, __TAURI_INTERNALS__: { event: sharedState.event, async invoke(command, payload = {}) { @@ -126,6 +140,26 @@ function runBootstrap(source, authResults, sharedState = {}) { }; } +test('bridge saves the Dashboard theme even when switching to system keeps the same palette', async () => { + const source = await readFile(bootstrapPath, 'utf8'); + const { localStorage, sessionStorage, invocations } = runBootstrap(source, [], { + nativeStorage: true, + localValues: new Map([['uiTheme', 'PurpleThemeDark']]), + }); + const savedModes = () => invocations + .filter(({ command }) => command === 'desktop_bridge_set_startup_theme') + .map(({ payload }) => payload.theme); + + assert.deepEqual(savedModes(), ['dark']); + sessionStorage.setItem('themeMode', 'light'); + localStorage.setItem('themeMode', 'system'); + localStorage.setItem('uiTheme', 'PurpleThemeDark'); + localStorage.setItem('themeMode', 'light'); + localStorage.clear(); + + assert.deepEqual(savedModes(), ['dark', 'system', 'light', 'system']); +}); + test('bridge bootstrap defines astrbotAppUpdater methods', async () => { const source = await readFile(bootstrapPath, 'utf8'); diff --git a/scripts/prepare-resources/startup-shell-copy.test.mjs b/scripts/prepare-resources/startup-shell-copy.test.mjs index 7c8aeb7e..3d393428 100644 --- a/scripts/prepare-resources/startup-shell-copy.test.mjs +++ b/scripts/prepare-resources/startup-shell-copy.test.mjs @@ -1,10 +1,38 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; +import { runInNewContext } from 'node:vm'; const startupShellPath = new URL('../../ui/index.html', import.meta.url); const startupCopyConfigPath = new URL('../../ui/startup-copy.js', import.meta.url); +test('startup shell applies an explicit theme before styles and follows system without a preference', async () => { + const source = await readFile(startupShellPath, 'utf8'); + const beforeStyles = source.split('