mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(storage): reset legacy data hint after directory changes
This commit is contained in:
1 parent
e68ce77266
commit
bb4986d703
2 files changed
+58
-7
No files matched your search
@@ -9,6 +9,7 @@ import { usePlatformService } from '@/services'
|
||||
import { IS_ELECTRON } from '@/utils/platform'
|
||||
import { useCacheService } from '@/services/cache/service'
|
||||
import type { CacheInfo } from '@/services/cache/types'
|
||||
import { clearMigrateHintIgnore, isMigrateHintIgnoredForDir, writeMigrateHintIgnore } from './migrateHintIgnore'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -75,10 +76,6 @@ const canMigrateToDefault = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
function getMigrateHintIgnoreKey(pathValue: string, defaultPathValue: string): string {
|
||||
return `chatlab_ignore_migrate_default_hint:${pathValue}:${defaultPathValue}`
|
||||
}
|
||||
|
||||
function updateMigrateHintIgnored() {
|
||||
if (!dataDir.value || !defaultDataDir.value) {
|
||||
isMigrateHintIgnored.value = false
|
||||
@@ -86,8 +83,7 @@ function updateMigrateHintIgnored() {
|
||||
}
|
||||
|
||||
try {
|
||||
isMigrateHintIgnored.value =
|
||||
localStorage.getItem(getMigrateHintIgnoreKey(dataDir.value, defaultDataDir.value)) === '1'
|
||||
isMigrateHintIgnored.value = isMigrateHintIgnoredForDir(localStorage, dataDir.value)
|
||||
} catch {
|
||||
isMigrateHintIgnored.value = false
|
||||
}
|
||||
@@ -190,7 +186,7 @@ function ignoreMigrateHint() {
|
||||
if (!dataDir.value || !defaultDataDir.value) return
|
||||
|
||||
try {
|
||||
localStorage.setItem(getMigrateHintIgnoreKey(dataDir.value, defaultDataDir.value), '1')
|
||||
writeMigrateHintIgnore(localStorage, dataDir.value)
|
||||
} catch {
|
||||
// localStorage 不可用时只在当前页面隐藏,避免阻塞用户继续使用设置页。
|
||||
}
|
||||
@@ -222,6 +218,14 @@ async function applyDataDirChange(newDir: string | null, migrate: boolean) {
|
||||
return
|
||||
}
|
||||
|
||||
if (result.requiresRelaunch !== false) {
|
||||
try {
|
||||
clearMigrateHintIgnore(localStorage)
|
||||
} catch {
|
||||
// localStorage 清理失败不影响目录切换,下一次加载时仍会按当前内存状态处理。
|
||||
}
|
||||
}
|
||||
|
||||
if (result.requiresRelaunch === false) {
|
||||
await loadDataDir()
|
||||
return
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
export const MIGRATE_HINT_IGNORE_KEY = 'chatlab_ignore_migrate_default_hint'
|
||||
|
||||
interface MigrateHintIgnoreState {
|
||||
ignoredForDataDir: string
|
||||
ignoredAt: string
|
||||
}
|
||||
|
||||
interface StorageLike {
|
||||
getItem(key: string): string | null
|
||||
setItem(key: string, value: string): void
|
||||
removeItem(key: string): void
|
||||
}
|
||||
|
||||
function readMigrateHintIgnore(storage: StorageLike): MigrateHintIgnoreState | null {
|
||||
const raw = storage.getItem(MIGRATE_HINT_IGNORE_KEY)
|
||||
if (!raw) return null
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as Partial<MigrateHintIgnoreState>
|
||||
if (!parsed.ignoredForDataDir || !parsed.ignoredAt) return null
|
||||
return {
|
||||
ignoredForDataDir: parsed.ignoredForDataDir,
|
||||
ignoredAt: parsed.ignoredAt,
|
||||
}
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function isMigrateHintIgnoredForDir(storage: StorageLike, dataDir: string): boolean {
|
||||
const state = readMigrateHintIgnore(storage)
|
||||
return state?.ignoredForDataDir === dataDir
|
||||
}
|
||||
|
||||
export function writeMigrateHintIgnore(storage: StorageLike, dataDir: string): void {
|
||||
storage.setItem(
|
||||
MIGRATE_HINT_IGNORE_KEY,
|
||||
JSON.stringify({
|
||||
ignoredForDataDir: dataDir,
|
||||
ignoredAt: new Date().toISOString(),
|
||||
} satisfies MigrateHintIgnoreState)
|
||||
)
|
||||
}
|
||||
|
||||
export function clearMigrateHintIgnore(storage: StorageLike): void {
|
||||
storage.removeItem(MIGRATE_HINT_IGNORE_KEY)
|
||||
}
|
||||
Reference in new issue
Block a user