mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-20 13:53:32 +08:00
Update settingsStore.ts
This commit is contained in:
parent
93e55f8f7e
commit
415f00573e
@ -3,7 +3,8 @@ import { ApiError } from '../api/client'
|
|||||||
import { settingsApi } from '../api/settings'
|
import { settingsApi } from '../api/settings'
|
||||||
import { modelsApi } from '../api/models'
|
import { modelsApi } from '../api/models'
|
||||||
import { h5AccessApi } from '../api/h5Access'
|
import { h5AccessApi } from '../api/h5Access'
|
||||||
import { isThemeMode, type H5AccessSettings, type PermissionMode, type EffortLevel, type ModelInfo, type ThemeMode, type WebSearchSettings } from '../types/settings'
|
import { isThemeMode, type H5AccessSettings, type PermissionMode, type EffortLevel, type ModelInfo, type ThemeMode, type WebSearchSettings, type AppMode, type AppModeConfig } from '../types/settings'
|
||||||
|
import { isTauriRuntime } from '../lib/desktopRuntime'
|
||||||
import type { Locale } from '../i18n'
|
import type { Locale } from '../i18n'
|
||||||
import { useUIStore } from './uiStore'
|
import { useUIStore } from './uiStore'
|
||||||
|
|
||||||
@ -36,6 +37,9 @@ type SettingsStore = {
|
|||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
error: string | null
|
error: string | null
|
||||||
|
|
||||||
|
appMode: AppModeConfig
|
||||||
|
appModeRequiresRestart: boolean
|
||||||
|
|
||||||
fetchAll: () => Promise<void>
|
fetchAll: () => Promise<void>
|
||||||
fetchH5Access: () => Promise<void>
|
fetchH5Access: () => Promise<void>
|
||||||
setPermissionMode: (mode: PermissionMode) => Promise<void>
|
setPermissionMode: (mode: PermissionMode) => Promise<void>
|
||||||
@ -55,6 +59,8 @@ type SettingsStore = {
|
|||||||
publicBaseUrl?: string | null
|
publicBaseUrl?: string | null
|
||||||
}) => Promise<void>
|
}) => Promise<void>
|
||||||
setResponseLanguage: (language: string) => Promise<void>
|
setResponseLanguage: (language: string) => Promise<void>
|
||||||
|
fetchAppMode: () => Promise<void>
|
||||||
|
setAppMode: (mode: AppMode, portableDir?: string | null) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_H5_ACCESS_SETTINGS: H5AccessSettings = {
|
const DEFAULT_H5_ACCESS_SETTINGS: H5AccessSettings = {
|
||||||
@ -82,6 +88,9 @@ export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
|
|
||||||
|
appMode: { mode: 'default', portableDir: null, defaultPortableDir: null },
|
||||||
|
appModeRequiresRestart: false,
|
||||||
|
|
||||||
fetchAll: async () => {
|
fetchAll: async () => {
|
||||||
set({ isLoading: true, error: null })
|
set({ isLoading: true, error: null })
|
||||||
try {
|
try {
|
||||||
@ -288,6 +297,37 @@ export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
|||||||
set({ responseLanguage: prev })
|
set({ responseLanguage: prev })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchAppMode: async () => {
|
||||||
|
if (!isTauriRuntime()) return
|
||||||
|
try {
|
||||||
|
const { invoke } = await import('@tauri-apps/api/core')
|
||||||
|
const result: AppModeConfig = await invoke('get_app_mode')
|
||||||
|
set({ appMode: result })
|
||||||
|
} catch { /* silently ignore - not in Tauri or command unavailable */ }
|
||||||
|
},
|
||||||
|
|
||||||
|
setAppMode: async (mode, portableDir) => {
|
||||||
|
if (!isTauriRuntime()) return
|
||||||
|
const prev = get().appMode
|
||||||
|
const newMode: AppModeConfig = {
|
||||||
|
...prev,
|
||||||
|
mode,
|
||||||
|
portableDir: mode === 'portable'
|
||||||
|
? portableDir ?? prev.defaultPortableDir ?? prev.portableDir
|
||||||
|
: null,
|
||||||
|
}
|
||||||
|
set({ appMode: newMode, appModeRequiresRestart: true })
|
||||||
|
try {
|
||||||
|
const { invoke } = await import('@tauri-apps/api/core')
|
||||||
|
await invoke('set_app_mode', {
|
||||||
|
mode,
|
||||||
|
portableDir: newMode.portableDir || null,
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
set({ appMode: prev, appModeRequiresRestart: false })
|
||||||
|
}
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
function normalizeWebSearchSettings(settings: WebSearchSettings | undefined): WebSearchSettings {
|
function normalizeWebSearchSettings(settings: WebSearchSettings | undefined): WebSearchSettings {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user