fix(portal): remember theme choice and restore light as default

Stop the one-time force-dark migration from overriding users, default first visits to light, and roll forced-dark browsers back to light once.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
John
2026-09-12 09:30:28 +08:00
parent 0e7e4829db
commit 06ba9e8bb7
3 changed files with 42 additions and 12 deletions
+11 -6
View File
@@ -1,20 +1,26 @@
<!doctype html>
<html lang="zh-CN" data-theme="dark">
<html lang="zh-CN" data-theme="light">
<head>
<meta charset="UTF-8" />
<meta name="theme-color" content="#f4f1ea" />
<script>
(function () {
var storageKey = 'memind-theme';
var migrationKey = 'memind-theme-migration';
var migrationVersion = 'dark-default-2026-09-11';
var migrationVersion = 'light-default-2026-09-12';
if (localStorage.getItem(migrationKey) !== migrationVersion) {
localStorage.setItem(storageKey, 'dark');
var previousMigration = localStorage.getItem(migrationKey);
var stored = localStorage.getItem(storageKey);
if (previousMigration === 'dark-default-2026-09-11' && stored !== 'light') {
localStorage.setItem(storageKey, 'light');
}
localStorage.setItem(migrationKey, migrationVersion);
}
var stored = localStorage.getItem(storageKey);
var theme = stored === 'light' || stored === 'dark' ? stored : 'dark';
var theme = localStorage.getItem(storageKey) === 'dark' ? 'dark' : 'light';
document.documentElement.dataset.theme = theme;
document.documentElement.style.colorScheme = theme;
var meta = document.querySelector('meta[name="theme-color"]');
if (meta) meta.setAttribute('content', theme === 'dark' ? '#0f1419' : '#f4f1ea');
})();
</script>
<meta
@@ -23,7 +29,6 @@
/>
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#0f1419" />
<title>TKMind</title>
</head>
<body>
+9 -3
View File
@@ -3,18 +3,24 @@
const THEME_STORAGE_KEY = 'memind-theme';
const THEME_MIGRATION_KEY = 'memind-theme-migration';
const THEME_MIGRATION_VERSION = 'dark-default-2026-09-11';
const THEME_MIGRATION_VERSION = 'light-default-2026-09-12';
const FORCE_DARK_MIGRATION_VERSION = 'dark-default-2026-09-11';
const DEFAULT_THEME = 'light';
function migrateThemePreferenceIfNeeded() {
if (localStorage.getItem(THEME_MIGRATION_KEY) === THEME_MIGRATION_VERSION) return;
localStorage.setItem(THEME_STORAGE_KEY, 'dark');
const previousMigration = localStorage.getItem(THEME_MIGRATION_KEY);
const stored = localStorage.getItem(THEME_STORAGE_KEY);
if (previousMigration === FORCE_DARK_MIGRATION_VERSION && stored !== 'light') {
localStorage.setItem(THEME_STORAGE_KEY, 'light');
}
localStorage.setItem(THEME_MIGRATION_KEY, THEME_MIGRATION_VERSION);
}
function getStoredTheme() {
const stored = localStorage.getItem(THEME_STORAGE_KEY);
if (stored === 'dark' || stored === 'light') return stored;
return 'dark';
return DEFAULT_THEME;
}
function applyTheme(theme) {
+22 -3
View File
@@ -2,19 +2,37 @@ export type MemindTheme = 'light' | 'dark';
export const THEME_STORAGE_KEY = 'memind-theme';
export const THEME_MIGRATION_KEY = 'memind-theme-migration';
export const THEME_MIGRATION_VERSION = 'dark-default-2026-09-11';
export const THEME_MIGRATION_VERSION = 'light-default-2026-09-12';
export const DEFAULT_THEME: MemindTheme = 'light';
const FORCE_DARK_MIGRATION_VERSION = 'dark-default-2026-09-11';
const THEME_COLOR = {
light: '#f4f1ea',
dark: '#0f1419',
} as const;
function syncThemeColor(theme: MemindTheme) {
const meta = document.querySelector('meta[name="theme-color"]');
if (meta) meta.setAttribute('content', THEME_COLOR[theme]);
}
export function migrateThemePreferenceIfNeeded() {
if (typeof localStorage === 'undefined') return;
if (localStorage.getItem(THEME_MIGRATION_KEY) === THEME_MIGRATION_VERSION) return;
localStorage.setItem(THEME_STORAGE_KEY, 'dark');
const previousMigration = localStorage.getItem(THEME_MIGRATION_KEY);
const stored = localStorage.getItem(THEME_STORAGE_KEY);
if (previousMigration === FORCE_DARK_MIGRATION_VERSION && stored !== 'light') {
localStorage.setItem(THEME_STORAGE_KEY, 'light');
}
localStorage.setItem(THEME_MIGRATION_KEY, THEME_MIGRATION_VERSION);
}
export function getStoredTheme(): MemindTheme {
if (typeof localStorage === 'undefined') return DEFAULT_THEME;
const stored = localStorage.getItem(THEME_STORAGE_KEY);
if (stored === 'dark' || stored === 'light') return stored;
return 'dark';
return DEFAULT_THEME;
}
export function applyTheme(theme: MemindTheme) {
@@ -22,6 +40,7 @@ export function applyTheme(theme: MemindTheme) {
document.documentElement.dataset.theme = normalized;
document.documentElement.style.colorScheme = normalized;
localStorage.setItem(THEME_STORAGE_KEY, normalized);
syncThemeColor(normalized);
window.dispatchEvent(new CustomEvent('memind-theme-change', { detail: { theme: normalized } }));
}