feat:新增了切换账号的功能 (#89)

This commit is contained in:
xuncha
2026-01-24 12:43:09 +08:00
committed by GitHub
parent 16cbc6adb1
commit 3a10aeb23e
13 changed files with 300 additions and 86 deletions

View File

@@ -6,6 +6,7 @@ export const CONFIG_KEYS = {
DECRYPT_KEY: 'decryptKey',
DB_PATH: 'dbPath',
MY_WXID: 'myWxid',
WXID_CONFIGS: 'wxidConfigs',
THEME: 'theme',
THEME_ID: 'themeId',
LAST_SESSION: 'lastSession',
@@ -31,6 +32,13 @@ export const CONFIG_KEYS = {
EXPORT_DEFAULT_TXT_COLUMNS: 'exportDefaultTxtColumns'
} as const
export interface WxidConfig {
decryptKey?: string
imageXorKey?: number
imageAesKey?: string
updatedAt?: number
}
// 获取解密密钥
export async function getDecryptKey(): Promise<string | null> {
const value = await config.get(CONFIG_KEYS.DECRYPT_KEY)
@@ -64,6 +72,32 @@ export async function setMyWxid(wxid: string): Promise<void> {
await config.set(CONFIG_KEYS.MY_WXID, wxid)
}
export async function getWxidConfigs(): Promise<Record<string, WxidConfig>> {
const value = await config.get(CONFIG_KEYS.WXID_CONFIGS)
if (value && typeof value === 'object') {
return value as Record<string, WxidConfig>
}
return {}
}
export async function getWxidConfig(wxid: string): Promise<WxidConfig | null> {
if (!wxid) return null
const configs = await getWxidConfigs()
return configs[wxid] || null
}
export async function setWxidConfig(wxid: string, configValue: WxidConfig): Promise<void> {
if (!wxid) return
const configs = await getWxidConfigs()
const previous = configs[wxid] || {}
configs[wxid] = {
...previous,
...configValue,
updatedAt: Date.now()
}
await config.set(CONFIG_KEYS.WXID_CONFIGS, configs)
}
// 获取主题
export async function getTheme(): Promise<'light' | 'dark'> {
const value = await config.get(CONFIG_KEYS.THEME)