refactor: expand settings state with comprehensive user preferences

- Introduced a detailed SettingsState interface, incorporating various user preferences such as showAssistants, language settings, proxy configurations, and more.
- Updated initialState to reflect the new comprehensive settings structure, ensuring all preferences are initialized correctly.
- Cleaned up commented-out code and organized settings for improved clarity and maintainability.
- Enhanced type safety by integrating new types for various settings, aligning with recent refactoring efforts in preference management.
This commit is contained in:
fullex 2025-09-03 16:53:29 +08:00
parent 566dd14fed
commit 1dacdc3178

View File

@ -1,6 +1,27 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import { ApiServerConfig, OpenAIServiceTier, OpenAISummaryText, PaintingProvider } from '@renderer/types' import { isMac } from '@renderer/config/constant'
import {
ApiServerConfig,
CodeStyleVarious,
MathEngine,
OpenAIServiceTier,
OpenAISummaryText,
PaintingProvider,
S3Config,
TranslateLanguageCode
} from '@renderer/types'
import { uuid } from '@renderer/utils' import { uuid } from '@renderer/utils'
import { TRANSLATE_PROMPT } from '@shared/config/prompts'
import { DefaultPreferences } from '@shared/data/preferences'
import type {
AssistantIconType,
AssistantTabSortType,
LanguageVarious,
MultiModelMessageStyle,
SendMessageShortcut,
SidebarIcon
} from '@shared/data/preferenceTypes'
import { ThemeMode, UpgradeChannel } from '@shared/data/preferenceTypes'
import { OpenAIVerbosity } from '@types' import { OpenAIVerbosity } from '@types'
import { RemoteSyncState } from './backup' import { RemoteSyncState } from './backup'
@ -19,159 +40,159 @@ export type UserTheme = {
} }
export interface SettingsState { export interface SettingsState {
// showAssistants: boolean showAssistants: boolean
// showTopics: boolean showTopics: boolean
// assistantsTabSortType: AssistantTabSortType assistantsTabSortType: AssistantTabSortType
// sendMessageShortcut: SendMessageShortcut sendMessageShortcut: SendMessageShortcut
// language: LanguageVarious language: LanguageVarious
// targetLanguage: TranslateLanguageCode targetLanguage: TranslateLanguageCode
// proxyMode: 'system' | 'custom' | 'none' proxyMode: 'system' | 'custom' | 'none'
// proxyUrl?: string proxyUrl?: string
// proxyBypassRules?: string proxyBypassRules?: string
// userName: string userName: string
// userId: string userId: string
// showPrompt: boolean showPrompt: boolean
// showMessageDivider: boolean showMessageDivider: boolean
// messageFont: 'system' | 'serif' messageFont: 'system' | 'serif'
// showInputEstimatedTokens: boolean showInputEstimatedTokens: boolean
// launchOnBoot: boolean launchOnBoot: boolean
// launchToTray: boolean launchToTray: boolean
// trayOnClose: boolean trayOnClose: boolean
// tray: boolean tray: boolean
// theme: ThemeMode theme: ThemeMode
// userTheme: { userTheme: {
// colorPrimary: string colorPrimary: string
// } }
// windowStyle: 'transparent' | 'opaque' windowStyle: 'transparent' | 'opaque'
// fontSize: number fontSize: number
// topicPosition: 'left' | 'right' topicPosition: 'left' | 'right'
// showTopicTime: boolean showTopicTime: boolean
// pinTopicsToTop: boolean pinTopicsToTop: boolean
// assistantIconType: AssistantIconType assistantIconType: AssistantIconType
// pasteLongTextAsFile: boolean pasteLongTextAsFile: boolean
// pasteLongTextThreshold: number pasteLongTextThreshold: number
// clickAssistantToShowTopic: boolean clickAssistantToShowTopic: boolean
// autoCheckUpdate: boolean autoCheckUpdate: boolean
// testPlan: boolean testPlan: boolean
// testChannel: UpgradeChannel testChannel: UpgradeChannel
// renderInputMessageAsMarkdown: boolean renderInputMessageAsMarkdown: boolean
// // 代码执行 // 代码执行
// codeExecution: { codeExecution: {
// enabled: boolean enabled: boolean
// timeoutMinutes: number timeoutMinutes: number
// } }
// codeEditor: { codeEditor: {
// enabled: boolean enabled: boolean
// themeLight: string themeLight: string
// themeDark: string themeDark: string
// highlightActiveLine: boolean highlightActiveLine: boolean
// foldGutter: boolean foldGutter: boolean
// autocompletion: boolean autocompletion: boolean
// keymap: boolean keymap: boolean
// } }
// /** @deprecated use codeViewer instead */ /** @deprecated use codeViewer instead */
// codePreview: { codePreview: {
// themeLight: CodeStyleVarious themeLight: CodeStyleVarious
// themeDark: CodeStyleVarious themeDark: CodeStyleVarious
// } }
// codeViewer: { codeViewer: {
// themeLight: CodeStyleVarious themeLight: CodeStyleVarious
// themeDark: CodeStyleVarious themeDark: CodeStyleVarious
// } }
// codeShowLineNumbers: boolean codeShowLineNumbers: boolean
// codeCollapsible: boolean codeCollapsible: boolean
// codeWrappable: boolean codeWrappable: boolean
// codeImageTools: boolean codeImageTools: boolean
// mathEngine: MathEngine mathEngine: MathEngine
// mathEnableSingleDollar: boolean mathEnableSingleDollar: boolean
// messageStyle: 'plain' | 'bubble' messageStyle: 'plain' | 'bubble'
// foldDisplayMode: 'expanded' | 'compact' foldDisplayMode: 'expanded' | 'compact'
// gridColumns: number gridColumns: number
// gridPopoverTrigger: 'hover' | 'click' gridPopoverTrigger: 'hover' | 'click'
// messageNavigation: 'none' | 'buttons' | 'anchor' messageNavigation: 'none' | 'buttons' | 'anchor'
// // 数据目录设置 // 数据目录设置
// skipBackupFile: boolean skipBackupFile: boolean
// // webdav 配置 host, user, pass, path // webdav 配置 host, user, pass, path
// webdavHost: string webdavHost: string
// webdavUser: string webdavUser: string
// webdavPass: string webdavPass: string
// webdavPath: string webdavPath: string
// webdavAutoSync: boolean webdavAutoSync: boolean
// webdavSyncInterval: number webdavSyncInterval: number
// webdavMaxBackups: number webdavMaxBackups: number
// webdavSkipBackupFile: boolean webdavSkipBackupFile: boolean
// webdavDisableStream: boolean webdavDisableStream: boolean
// translateModelPrompt: string translateModelPrompt: string
// autoTranslateWithSpace: boolean autoTranslateWithSpace: boolean
// showTranslateConfirm: boolean showTranslateConfirm: boolean
// enableTopicNaming: boolean enableTopicNaming: boolean
// customCss: string customCss: string
// topicNamingPrompt: string topicNamingPrompt: string
// // 消息操作确认设置 // 消息操作确认设置
// confirmDeleteMessage: boolean confirmDeleteMessage: boolean
// confirmRegenerateMessage: boolean confirmRegenerateMessage: boolean
// // Sidebar icons // Sidebar icons
// sidebarIcons: { sidebarIcons: {
// visible: SidebarIcon[] visible: SidebarIcon[]
// disabled: SidebarIcon[] disabled: SidebarIcon[]
// } }
// narrowMode: boolean narrowMode: boolean
// // QuickAssistant // QuickAssistant
// enableQuickAssistant: boolean enableQuickAssistant: boolean
// clickTrayToShowQuickAssistant: boolean clickTrayToShowQuickAssistant: boolean
// multiModelMessageStyle: MultiModelMessageStyle multiModelMessageStyle: MultiModelMessageStyle
// readClipboardAtStartup: boolean readClipboardAtStartup: boolean
// notionDatabaseID: string | null notionDatabaseID: string | null
// notionApiKey: string | null notionApiKey: string | null
// notionPageNameKey: string | null notionPageNameKey: string | null
// markdownExportPath: string | null markdownExportPath: string | null
// forceDollarMathInMarkdown: boolean forceDollarMathInMarkdown: boolean
// useTopicNamingForMessageTitle: boolean useTopicNamingForMessageTitle: boolean
// showModelNameInMarkdown: boolean showModelNameInMarkdown: boolean
// showModelProviderInMarkdown: boolean showModelProviderInMarkdown: boolean
// thoughtAutoCollapse: boolean thoughtAutoCollapse: boolean
// notionExportReasoning: boolean notionExportReasoning: boolean
// excludeCitationsInExport: boolean excludeCitationsInExport: boolean
// standardizeCitationsInExport: boolean standardizeCitationsInExport: boolean
// yuqueToken: string | null yuqueToken: string | null
// yuqueUrl: string | null yuqueUrl: string | null
// yuqueRepoId: string | null yuqueRepoId: string | null
// joplinToken: string | null joplinToken: string | null
// joplinUrl: string | null joplinUrl: string | null
// joplinExportReasoning: boolean joplinExportReasoning: boolean
// defaultObsidianVault: string | null defaultObsidianVault: string | null
defaultAgent: string | null defaultAgent: string | null
// // 思源笔记配置 // 思源笔记配置
// siyuanApiUrl: string | null siyuanApiUrl: string | null
// siyuanToken: string | null siyuanToken: string | null
// siyuanBoxId: string | null siyuanBoxId: string | null
// siyuanRootPath: string | null siyuanRootPath: string | null
// 订阅的助手地址 // 订阅的助手地址
agentssubscribeUrl: string | null agentssubscribeUrl: string | null
// MinApps // MinApps
maxKeepAliveMinapps: number maxKeepAliveMinapps: number
showOpenedMinappsInSidebar: boolean showOpenedMinappsInSidebar: boolean
minappsOpenLinkExternal: boolean minappsOpenLinkExternal: boolean
// // 隐私设置 // 隐私设置
// enableDataCollection: boolean enableDataCollection: boolean
// enableSpellCheck: boolean enableSpellCheck: boolean
// spellCheckLanguages: string[] spellCheckLanguages: string[]
// enableQuickPanelTriggers: boolean enableQuickPanelTriggers: boolean
// // 硬件加速设置 // 硬件加速设置
// disableHardwareAcceleration: boolean disableHardwareAcceleration: boolean
// exportMenuOptions: { exportMenuOptions: {
// image: boolean image: boolean
// markdown: boolean markdown: boolean
// markdown_reason: boolean markdown_reason: boolean
// notion: boolean notion: boolean
// yuque: boolean yuque: boolean
// joplin: boolean joplin: boolean
// obsidian: boolean obsidian: boolean
// siyuan: boolean siyuan: boolean
// docx: boolean docx: boolean
// plain_text: boolean plain_text: boolean
// notes: boolean notes: boolean
// } }
// OpenAI // OpenAI
openAI: { openAI: {
summaryText: OpenAISummaryText summaryText: OpenAISummaryText
@ -179,24 +200,24 @@ export interface SettingsState {
serviceTier: OpenAIServiceTier serviceTier: OpenAIServiceTier
verbosity: OpenAIVerbosity verbosity: OpenAIVerbosity
} }
// // Notification // Notification
// notification: { notification: {
// assistant: boolean assistant: boolean
// backup: boolean backup: boolean
// knowledge: boolean knowledge: boolean
// } }
// // Local backup settings // Local backup settings
// localBackupDir: string localBackupDir: string
// localBackupAutoSync: boolean localBackupAutoSync: boolean
// localBackupSyncInterval: number localBackupSyncInterval: number
// localBackupMaxBackups: number localBackupMaxBackups: number
// localBackupSkipBackupFile: boolean localBackupSkipBackupFile: boolean
defaultPaintingProvider: PaintingProvider defaultPaintingProvider: PaintingProvider
// s3: S3Config s3: S3Config
// Developer mode // Developer mode
// enableDeveloperMode: boolean enableDeveloperMode: boolean
// // UI // UI
// navbarPosition: 'left' | 'top' navbarPosition: 'left' | 'top'
// API Server // API Server
apiServer: ApiServerConfig apiServer: ApiServerConfig
showMessageOutline?: boolean showMessageOutline?: boolean
@ -207,186 +228,186 @@ export interface SettingsState {
// export type MultiModelMessageStyle = 'horizontal' | 'vertical' | 'fold' | 'grid' // export type MultiModelMessageStyle = 'horizontal' | 'vertical' | 'fold' | 'grid'
export const initialState: SettingsState = { export const initialState: SettingsState = {
// showAssistants: true, showAssistants: true,
// showTopics: true, showTopics: true,
// assistantsTabSortType: 'list', assistantsTabSortType: 'list',
// sendMessageShortcut: 'Enter', sendMessageShortcut: 'Enter',
// language: navigator.language as LanguageVarious, language: navigator.language as LanguageVarious,
// targetLanguage: 'en-us', targetLanguage: 'en-us',
// proxyMode: 'system', proxyMode: 'system',
// proxyUrl: undefined, proxyUrl: undefined,
// proxyBypassRules: undefined, proxyBypassRules: undefined,
// userName: '', userName: '',
// userId: uuid(), userId: uuid(),
// showPrompt: true, showPrompt: true,
// showMessageDivider: true, showMessageDivider: true,
// messageFont: 'system', messageFont: 'system',
// showInputEstimatedTokens: false, showInputEstimatedTokens: false,
// launchOnBoot: false, launchOnBoot: false,
// launchToTray: false, launchToTray: false,
// trayOnClose: true, trayOnClose: true,
// tray: true, tray: true,
// theme: ThemeMode.system, theme: ThemeMode.system,
// userTheme: { userTheme: {
// colorPrimary: '#00b96b' colorPrimary: '#00b96b'
// }, },
// windowStyle: isMac ? 'transparent' : 'opaque', windowStyle: isMac ? 'transparent' : 'opaque',
// fontSize: 14, fontSize: 14,
// topicPosition: 'left', topicPosition: 'left',
// showTopicTime: false, showTopicTime: false,
// pinTopicsToTop: false, pinTopicsToTop: false,
// assistantIconType: 'emoji', assistantIconType: 'emoji',
// pasteLongTextAsFile: false, pasteLongTextAsFile: false,
// pasteLongTextThreshold: 1500, pasteLongTextThreshold: 1500,
// clickAssistantToShowTopic: true, clickAssistantToShowTopic: true,
// autoCheckUpdate: true, autoCheckUpdate: true,
// testPlan: false, testPlan: false,
// testChannel: UpgradeChannel.LATEST, testChannel: UpgradeChannel.LATEST,
// renderInputMessageAsMarkdown: false, renderInputMessageAsMarkdown: false,
// codeExecution: { codeExecution: {
// enabled: false, enabled: false,
// timeoutMinutes: 1 timeoutMinutes: 1
// }, },
// codeEditor: { codeEditor: {
// enabled: false, enabled: false,
// themeLight: 'auto', themeLight: 'auto',
// themeDark: 'auto', themeDark: 'auto',
// highlightActiveLine: false, highlightActiveLine: false,
// foldGutter: false, foldGutter: false,
// autocompletion: true, autocompletion: true,
// keymap: false keymap: false
// }, },
// /** @deprecated use codeViewer instead */ /** @deprecated use codeViewer instead */
// codePreview: { codePreview: {
// themeLight: 'auto', themeLight: 'auto',
// themeDark: 'auto' themeDark: 'auto'
// }, },
// codeViewer: { codeViewer: {
// themeLight: 'auto', themeLight: 'auto',
// themeDark: 'auto' themeDark: 'auto'
// }, },
// codeShowLineNumbers: false, codeShowLineNumbers: false,
// codeCollapsible: false, codeCollapsible: false,
// codeWrappable: false, codeWrappable: false,
// codeImageTools: false, codeImageTools: false,
// mathEngine: 'KaTeX', mathEngine: 'KaTeX',
// mathEnableSingleDollar: true, mathEnableSingleDollar: true,
// messageStyle: 'plain', messageStyle: 'plain',
// foldDisplayMode: 'expanded', foldDisplayMode: 'expanded',
// gridColumns: 2, gridColumns: 2,
// gridPopoverTrigger: 'click', gridPopoverTrigger: 'click',
// messageNavigation: 'none', messageNavigation: 'none',
// skipBackupFile: false, skipBackupFile: false,
// webdavHost: '', webdavHost: '',
// webdavUser: '', webdavUser: '',
// webdavPass: '', webdavPass: '',
// webdavPath: '/cherry-studio', webdavPath: '/cherry-studio',
// webdavAutoSync: false, webdavAutoSync: false,
// webdavSyncInterval: 0, webdavSyncInterval: 0,
// webdavMaxBackups: 0, webdavMaxBackups: 0,
// webdavSkipBackupFile: false, webdavSkipBackupFile: false,
// webdavDisableStream: false, webdavDisableStream: false,
// translateModelPrompt: TRANSLATE_PROMPT, translateModelPrompt: TRANSLATE_PROMPT,
// autoTranslateWithSpace: false, autoTranslateWithSpace: false,
// showTranslateConfirm: true, showTranslateConfirm: true,
// enableTopicNaming: true, enableTopicNaming: true,
// customCss: '', customCss: '',
// topicNamingPrompt: '', topicNamingPrompt: '',
// sidebarIcons: { sidebarIcons: {
// visible: DefaultPreferences.default['ui.sidebar.icons.visible'], visible: DefaultPreferences.default['ui.sidebar.icons.visible'],
// disabled: [] disabled: []
// }, },
// narrowMode: false, narrowMode: false,
// enableQuickAssistant: false, enableQuickAssistant: false,
// clickTrayToShowQuickAssistant: false, clickTrayToShowQuickAssistant: false,
// readClipboardAtStartup: true, readClipboardAtStartup: true,
// multiModelMessageStyle: 'horizontal', multiModelMessageStyle: 'horizontal',
// notionDatabaseID: '', notionDatabaseID: '',
// notionApiKey: '', notionApiKey: '',
// notionPageNameKey: 'Name', notionPageNameKey: 'Name',
// markdownExportPath: null, markdownExportPath: null,
// forceDollarMathInMarkdown: false, forceDollarMathInMarkdown: false,
// useTopicNamingForMessageTitle: false, useTopicNamingForMessageTitle: false,
// showModelNameInMarkdown: false, showModelNameInMarkdown: false,
// showModelProviderInMarkdown: false, showModelProviderInMarkdown: false,
// thoughtAutoCollapse: true, thoughtAutoCollapse: true,
// notionExportReasoning: false, notionExportReasoning: false,
// excludeCitationsInExport: false, excludeCitationsInExport: false,
// standardizeCitationsInExport: false, standardizeCitationsInExport: false,
// yuqueToken: '', yuqueToken: '',
// yuqueUrl: '', yuqueUrl: '',
// yuqueRepoId: '', yuqueRepoId: '',
// joplinToken: '', joplinToken: '',
// joplinUrl: '', joplinUrl: '',
// joplinExportReasoning: false, joplinExportReasoning: false,
// defaultObsidianVault: null, defaultObsidianVault: null,
defaultAgent: null, defaultAgent: null,
// siyuanApiUrl: null, siyuanApiUrl: null,
// siyuanToken: null, siyuanToken: null,
// siyuanBoxId: null, siyuanBoxId: null,
// siyuanRootPath: null, siyuanRootPath: null,
agentssubscribeUrl: '', agentssubscribeUrl: '',
// MinApps // MinApps
maxKeepAliveMinapps: 3, maxKeepAliveMinapps: 3,
showOpenedMinappsInSidebar: true, showOpenedMinappsInSidebar: true,
minappsOpenLinkExternal: false, minappsOpenLinkExternal: false,
// enableDataCollection: false, enableDataCollection: false,
// enableSpellCheck: false, enableSpellCheck: false,
// spellCheckLanguages: [], spellCheckLanguages: [],
// enableQuickPanelTriggers: false, enableQuickPanelTriggers: false,
// // 消息操作确认设置 // 消息操作确认设置
// confirmDeleteMessage: true, confirmDeleteMessage: true,
// confirmRegenerateMessage: true, confirmRegenerateMessage: true,
// // 硬件加速设置 // 硬件加速设置
// disableHardwareAcceleration: false, disableHardwareAcceleration: false,
// exportMenuOptions: { exportMenuOptions: {
// image: true, image: true,
// markdown: true, markdown: true,
// markdown_reason: true, markdown_reason: true,
// notion: true, notion: true,
// yuque: true, yuque: true,
// joplin: true, joplin: true,
// obsidian: true, obsidian: true,
// siyuan: true, siyuan: true,
// docx: true, docx: true,
// plain_text: true, plain_text: true,
// notes: true notes: true
// }, },
// OpenAI // OpenAI
openAI: { openAI: {
summaryText: 'off', summaryText: 'off',
serviceTier: 'auto', serviceTier: 'auto',
verbosity: 'medium' verbosity: 'medium'
}, },
// notification: { notification: {
// assistant: false, assistant: false,
// backup: false, backup: false,
// knowledge: false knowledge: false
// }, },
// // Local backup settings // Local backup settings
// localBackupDir: '', localBackupDir: '',
// localBackupAutoSync: false, localBackupAutoSync: false,
// localBackupSyncInterval: 0, localBackupSyncInterval: 0,
// localBackupMaxBackups: 0, localBackupMaxBackups: 0,
// localBackupSkipBackupFile: false, localBackupSkipBackupFile: false,
defaultPaintingProvider: 'zhipu', defaultPaintingProvider: 'zhipu',
// s3: { s3: {
// endpoint: '', endpoint: '',
// region: '', region: '',
// bucket: '', bucket: '',
// accessKeyId: '', accessKeyId: '',
// secretAccessKey: '', secretAccessKey: '',
// root: '', root: '',
// autoSync: false, autoSync: false,
// syncInterval: 0, syncInterval: 0,
// maxBackups: 0, maxBackups: 0,
// skipBackupFile: false skipBackupFile: false
// }, },
// // Developer mode // Developer mode
// enableDeveloperMode: false, enableDeveloperMode: false,
// // UI // UI
// navbarPosition: 'top', navbarPosition: 'top',
// API Server // API Server
apiServer: { apiServer: {
enabled: false, enabled: false,
@ -394,7 +415,7 @@ export const initialState: SettingsState = {
port: 23333, port: 23333,
apiKey: `cs-sk-${uuid()}` apiKey: `cs-sk-${uuid()}`
}, },
// showMessageOutline: undefined, showMessageOutline: false,
// Notes Related // Notes Related
showWorkspace: true showWorkspace: true
} }