cherry-studio/src/renderer/src/hooks/useSettings.ts
beyondkmp 780373d5f7
fix: 测试版本 (#7590)
* feat(AppUpdater): add support for pre-release versions and enhance feed URL logic

- Introduced a new FeedUrl for the lowest pre-release version.
- Updated AppUpdater to handle early access and upgrade channel settings more effectively.
- Enhanced IPC logging for early access and upgrade channel changes.
- Refactored feed URL setting logic to streamline update processes.

* fix(AppUpdater, ipc): enhance early access and upgrade channel handling

- Added checks to prevent unnecessary cancellation of downloads when early access and upgrade channel settings remain unchanged.
- Updated IPC handlers to ensure early access is enabled when switching upgrade channels if it was previously disabled.
- Improved logging for better traceability of changes in early access and upgrade channel settings.

* delete code

* delete logs

* refactor(AboutSettings): enhance upgrade channel management

- Introduced logic to determine the current upgrade channel based on version.
- Refactored available test channels to use a more structured approach with tooltips and labels.
- Updated the method for retrieving available test channels to improve clarity and maintainability.

* feat(IpcChannel, ConfigManager, AppUpdater): implement test plan and channel management

- Replaced early access features with test plan and test channel options in IpcChannel and ConfigManager.
- Updated IPC handlers to manage test plan and test channel settings, including logging enhancements.
- Refactored AppUpdater to support fetching pre-release versions based on the selected test channel.
- Modified settings and localization files to reflect the new test plan functionality.
- Adjusted AboutSettings and related components to integrate test plan management and improve user experience.

* format code

* refactor(AppUpdater, AboutSettings): improve test channel logic and localization updates

- Refactored the logic in AppUpdater to enhance the handling of test channels, ensuring correct channel retrieval based on the current version.
- Updated the AboutSettings component to include useEffect for managing test channel changes and displaying appropriate warnings.
- Modified localization files for multiple languages to clarify the behavior of test version switching, aligning with the new logic.
2025-06-28 17:17:47 +08:00

119 lines
3.5 KiB
TypeScript

import store, { useAppDispatch, useAppSelector } from '@renderer/store'
import {
AssistantIconType,
SendMessageShortcut,
setAssistantIconType,
setAutoCheckUpdate as _setAutoCheckUpdate,
setLaunchOnBoot,
setLaunchToTray,
setPinTopicsToTop,
setSendMessageShortcut as _setSendMessageShortcut,
setShowTokens,
setSidebarIcons,
setTargetLanguage,
setTestChannel as _setTestChannel,
setTestPlan as _setTestPlan,
setTheme,
SettingsState,
setTopicPosition,
setTray as _setTray,
setTrayOnClose,
setWindowStyle
} from '@renderer/store/settings'
import { SidebarIcon, ThemeMode, TranslateLanguageVarious } from '@renderer/types'
import { UpgradeChannel } from '@shared/config/constant'
export function useSettings() {
const settings = useAppSelector((state) => state.settings)
const dispatch = useAppDispatch()
return {
...settings,
setSendMessageShortcut(shortcut: SendMessageShortcut) {
dispatch(_setSendMessageShortcut(shortcut))
},
setLaunch(isLaunchOnBoot: boolean | undefined, isLaunchToTray: boolean | undefined = undefined) {
if (isLaunchOnBoot !== undefined) {
dispatch(setLaunchOnBoot(isLaunchOnBoot))
window.api.setLaunchOnBoot(isLaunchOnBoot)
}
if (isLaunchToTray !== undefined) {
dispatch(setLaunchToTray(isLaunchToTray))
window.api.setLaunchToTray(isLaunchToTray)
}
},
setTray(isShowTray: boolean | undefined, isTrayOnClose: boolean | undefined = undefined) {
if (isShowTray !== undefined) {
dispatch(_setTray(isShowTray))
window.api.setTray(isShowTray)
}
if (isTrayOnClose !== undefined) {
dispatch(setTrayOnClose(isTrayOnClose))
window.api.setTrayOnClose(isTrayOnClose)
}
},
setAutoCheckUpdate(isAutoUpdate: boolean) {
dispatch(_setAutoCheckUpdate(isAutoUpdate))
window.api.setAutoUpdate(isAutoUpdate)
},
setTestPlan(isTestPlan: boolean) {
dispatch(_setTestPlan(isTestPlan))
window.api.setTestPlan(isTestPlan)
},
setTestChannel(channel: UpgradeChannel) {
dispatch(_setTestChannel(channel))
window.api.setTestChannel(channel)
},
setTheme(theme: ThemeMode) {
dispatch(setTheme(theme))
},
setWindowStyle(windowStyle: 'transparent' | 'opaque') {
dispatch(setWindowStyle(windowStyle))
},
setTargetLanguage(targetLanguage: TranslateLanguageVarious) {
dispatch(setTargetLanguage(targetLanguage))
},
setTopicPosition(topicPosition: 'left' | 'right') {
dispatch(setTopicPosition(topicPosition))
},
setPinTopicsToTop(pinTopicsToTop: boolean) {
dispatch(setPinTopicsToTop(pinTopicsToTop))
},
updateSidebarIcons(icons: { visible: SidebarIcon[]; disabled: SidebarIcon[] }) {
dispatch(setSidebarIcons(icons))
},
updateSidebarVisibleIcons(icons: SidebarIcon[]) {
dispatch(setSidebarIcons({ visible: icons }))
},
updateSidebarDisabledIcons(icons: SidebarIcon[]) {
dispatch(setSidebarIcons({ disabled: icons }))
},
setAssistantIconType(assistantIconType: AssistantIconType) {
dispatch(setAssistantIconType(assistantIconType))
},
setShowTokens(showTokens: boolean) {
dispatch(setShowTokens(showTokens))
}
}
}
export function useMessageStyle() {
const { messageStyle } = useSettings()
const isBubbleStyle = messageStyle === 'bubble'
return {
isBubbleStyle
}
}
export const getStoreSetting = (key: keyof SettingsState) => {
return store.getState().settings[key]
}