enhance(frontend): improve theme apply handling

This commit is contained in:
syuilo 2025-10-22 11:11:30 +09:00
parent 130d065d0c
commit f0380f2d1c
3 changed files with 4 additions and 4 deletions

View File

@ -69,9 +69,6 @@ export async function common(createVue: () => Promise<App<Element>>) {
if (lastVersion !== version) { if (lastVersion !== version) {
miLocalStorage.setItem('lastVersion', version); miLocalStorage.setItem('lastVersion', version);
// テーマリビルドするため
miLocalStorage.removeItem('theme');
try { // 変なバージョン文字列来るとcompareVersionsでエラーになるため try { // 変なバージョン文字列来るとcompareVersionsでエラーになるため
if (lastVersion != null && compareVersions(version, lastVersion) === 1) { if (lastVersion != null && compareVersions(version, lastVersion) === 1) {
isClientUpdated = true; isClientUpdated = true;

View File

@ -25,6 +25,7 @@ export type Keys = (
'bootloaderLocales' | 'bootloaderLocales' |
'theme' | 'theme' |
'themeId' | 'themeId' |
'themeCachedVersion' |
'customCss' | 'customCss' |
'chatMessageDrafts' | 'chatMessageDrafts' |
'scratchpad' | 'scratchpad' |

View File

@ -10,6 +10,7 @@ import tinycolor from 'tinycolor2';
import lightTheme from '@@/themes/_light.json5'; import lightTheme from '@@/themes/_light.json5';
import darkTheme from '@@/themes/_dark.json5'; import darkTheme from '@@/themes/_dark.json5';
import JSON5 from 'json5'; import JSON5 from 'json5';
import { version } from '@@/js/config.js';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import type { BundledTheme } from 'shiki/themes'; import type { BundledTheme } from 'shiki/themes';
import { deepClone } from '@/utility/clone.js'; import { deepClone } from '@/utility/clone.js';
@ -123,6 +124,7 @@ function applyThemeInternal(theme: Theme, persist: boolean) {
if (persist) { if (persist) {
miLocalStorage.setItem('theme', JSON.stringify(props)); miLocalStorage.setItem('theme', JSON.stringify(props));
miLocalStorage.setItem('themeId', theme.id); miLocalStorage.setItem('themeId', theme.id);
miLocalStorage.setItem('themeCachedVersion', version);
miLocalStorage.setItem('colorScheme', colorScheme); miLocalStorage.setItem('colorScheme', colorScheme);
} }
@ -139,7 +141,7 @@ export function applyTheme(theme: Theme, persist = true) {
timeout = null; timeout = null;
} }
if (theme.id === currentThemeId) return; if (theme.id === currentThemeId && miLocalStorage.getItem('themeCachedVersion') === version) return;
currentThemeId = theme.id; currentThemeId = theme.id;
if (window.document.startViewTransition != null) { if (window.document.startViewTransition != null) {