mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 19:30:17 +08:00
feat(settings): add option to disable hardware acceleration (#7811)
* feat(settings): add option to disable hardware acceleration - Introduced a new setting to allow users to disable hardware acceleration. - Added corresponding IPC channel and configuration management methods. - Updated UI components to reflect the new setting and prompt for app restart. - Localized confirmation messages for hardware acceleration changes in multiple languages. * fix(settings): add delay before relaunching app after disabling hardware acceleration - Introduced a 500ms delay before the application relaunches to ensure settings are applied correctly. - This change improves user experience by allowing time for the setting to take effect before the app restarts. * fix lint * fix(settings): handle errors when disabling hardware acceleration - Wrapped the hardware acceleration disabling function in a try-catch block to manage potential errors. - Added user feedback through an error message if the operation fails, improving overall robustness.
This commit is contained in:
parent
134ea51b0f
commit
8cfe6a5848
@ -36,6 +36,7 @@ export enum IpcChannel {
|
||||
App_MacRequestProcessTrust = 'app:mac-request-process-trust',
|
||||
|
||||
App_QuoteToMain = 'app:quote-to-main',
|
||||
App_SetDisableHardwareAcceleration = 'app:set-disable-hardware-acceleration',
|
||||
|
||||
Notification_Send = 'notification:send',
|
||||
Notification_OnClick = 'notification:on-click',
|
||||
|
||||
@ -28,6 +28,14 @@ import { windowService } from './services/WindowService'
|
||||
|
||||
Logger.initialize()
|
||||
|
||||
/**
|
||||
* Disable hardware acceleration if setting is enabled
|
||||
*/
|
||||
const disableHardwareAcceleration = configManager.getDisableHardwareAcceleration()
|
||||
if (disableHardwareAcceleration) {
|
||||
app.disableHardwareAcceleration()
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable chromium's window animations
|
||||
* main purpose for this is to avoid the transparent window flashing when it is shown
|
||||
|
||||
@ -561,4 +561,8 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
SelectionService.registerIpcHandler()
|
||||
|
||||
ipcMain.handle(IpcChannel.App_QuoteToMain, (_, text: string) => windowService.quoteToMainWindow(text))
|
||||
|
||||
ipcMain.handle(IpcChannel.App_SetDisableHardwareAcceleration, (_, isDisable: boolean) => {
|
||||
configManager.setDisableHardwareAcceleration(isDisable)
|
||||
})
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@ export enum ConfigKeys {
|
||||
SelectionAssistantFollowToolbar = 'selectionAssistantFollowToolbar',
|
||||
SelectionAssistantRemeberWinSize = 'selectionAssistantRemeberWinSize',
|
||||
SelectionAssistantFilterMode = 'selectionAssistantFilterMode',
|
||||
SelectionAssistantFilterList = 'selectionAssistantFilterList'
|
||||
SelectionAssistantFilterList = 'selectionAssistantFilterList',
|
||||
DisableHardwareAcceleration = 'disableHardwareAcceleration'
|
||||
}
|
||||
|
||||
export class ConfigManager {
|
||||
@ -218,6 +219,14 @@ export class ConfigManager {
|
||||
this.setAndNotify(ConfigKeys.SelectionAssistantFilterList, value)
|
||||
}
|
||||
|
||||
getDisableHardwareAcceleration(): boolean {
|
||||
return this.get<boolean>(ConfigKeys.DisableHardwareAcceleration, false)
|
||||
}
|
||||
|
||||
setDisableHardwareAcceleration(value: boolean) {
|
||||
this.set(ConfigKeys.DisableHardwareAcceleration, value)
|
||||
}
|
||||
|
||||
setAndNotify(key: string, value: unknown) {
|
||||
this.set(key, value, true)
|
||||
}
|
||||
|
||||
@ -290,7 +290,9 @@ const api = {
|
||||
minimizeActionWindow: () => ipcRenderer.invoke(IpcChannel.Selection_ActionWindowMinimize),
|
||||
pinActionWindow: (isPinned: boolean) => ipcRenderer.invoke(IpcChannel.Selection_ActionWindowPin, isPinned)
|
||||
},
|
||||
quoteToMainWindow: (text: string) => ipcRenderer.invoke(IpcChannel.App_QuoteToMain, text)
|
||||
quoteToMainWindow: (text: string) => ipcRenderer.invoke(IpcChannel.App_QuoteToMain, text),
|
||||
setDisableHardwareAcceleration: (isDisable: boolean) =>
|
||||
ipcRenderer.invoke(IpcChannel.App_SetDisableHardwareAcceleration, isDisable)
|
||||
}
|
||||
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
SendMessageShortcut,
|
||||
setAssistantIconType,
|
||||
setAutoCheckUpdate as _setAutoCheckUpdate,
|
||||
setDisableHardwareAcceleration,
|
||||
setLaunchOnBoot,
|
||||
setLaunchToTray,
|
||||
setPinTopicsToTop,
|
||||
@ -100,6 +101,10 @@ export function useSettings() {
|
||||
},
|
||||
setShowTokens(showTokens: boolean) {
|
||||
dispatch(setShowTokens(showTokens))
|
||||
},
|
||||
setDisableHardwareAcceleration(disableHardwareAcceleration: boolean) {
|
||||
dispatch(setDisableHardwareAcceleration(disableHardwareAcceleration))
|
||||
window.api.setDisableHardwareAcceleration(disableHardwareAcceleration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1805,6 +1805,13 @@
|
||||
"title": "Proxy Settings"
|
||||
},
|
||||
"proxy.title": "Proxy Address",
|
||||
"hardware_acceleration": {
|
||||
"title": "Disable Hardware Acceleration",
|
||||
"confirm": {
|
||||
"title": "Restart Required",
|
||||
"content": "Disabling hardware acceleration requires restarting the app to take effect. Do you want to restart now?"
|
||||
}
|
||||
},
|
||||
"quickAssistant": {
|
||||
"click_tray_to_show": "Click the tray icon to start",
|
||||
"enable_quick_assistant": "Enable Quick Assistant",
|
||||
|
||||
@ -1787,6 +1787,13 @@
|
||||
"title": "プロキシ設定"
|
||||
},
|
||||
"proxy.title": "プロキシアドレス",
|
||||
"hardware_acceleration": {
|
||||
"title": "ハードウェアアクセラレーションを無効にする",
|
||||
"confirm": {
|
||||
"title": "再起動が必要",
|
||||
"content": "ハードウェアアクセラレーションを無効にするには、アプリを再起動する必要があります。再起動しますか?"
|
||||
}
|
||||
},
|
||||
"quickAssistant": {
|
||||
"click_tray_to_show": "トレイアイコンをクリックして起動",
|
||||
"enable_quick_assistant": "クイックアシスタントを有効にする",
|
||||
|
||||
@ -1787,6 +1787,13 @@
|
||||
"title": "Настройки прокси"
|
||||
},
|
||||
"proxy.title": "Адрес прокси",
|
||||
"hardware_acceleration": {
|
||||
"title": "Отключить аппаратное ускорение",
|
||||
"confirm": {
|
||||
"title": "Требуется перезапуск",
|
||||
"content": "Отключение аппаратного ускорения требует перезапуска приложения для вступления в силу. Перезапустить приложение?"
|
||||
}
|
||||
},
|
||||
"quickAssistant": {
|
||||
"click_tray_to_show": "Нажмите на иконку трея для запуска",
|
||||
"enable_quick_assistant": "Включить быстрый помощник",
|
||||
|
||||
@ -1805,6 +1805,13 @@
|
||||
"title": "代理设置"
|
||||
},
|
||||
"proxy.title": "代理地址",
|
||||
"hardware_acceleration": {
|
||||
"title": "禁用硬件加速",
|
||||
"confirm": {
|
||||
"title": "需要重启应用",
|
||||
"content": "禁用硬件加速需要重启应用才能生效,是否现在重启?"
|
||||
}
|
||||
},
|
||||
"quickAssistant": {
|
||||
"click_tray_to_show": "点击托盘图标启动",
|
||||
"enable_quick_assistant": "启用快捷助手",
|
||||
|
||||
@ -1790,6 +1790,13 @@
|
||||
"title": "代理伺服器設定"
|
||||
},
|
||||
"proxy.title": "代理伺服器地址",
|
||||
"hardware_acceleration": {
|
||||
"title": "禁用硬件加速",
|
||||
"confirm": {
|
||||
"title": "需要重新啟動",
|
||||
"content": "禁用硬件加速需要重新啟動應用程序才能生效。是否立即重新啟動?"
|
||||
}
|
||||
},
|
||||
"quickAssistant": {
|
||||
"click_tray_to_show": "點選工具列圖示啟動",
|
||||
"enable_quick_assistant": "啟用快捷助手",
|
||||
|
||||
@ -35,7 +35,9 @@ const GeneralSettings: FC = () => {
|
||||
tray,
|
||||
proxyMode: storeProxyMode,
|
||||
enableDataCollection,
|
||||
enableSpellCheck
|
||||
enableSpellCheck,
|
||||
disableHardwareAcceleration,
|
||||
setDisableHardwareAcceleration
|
||||
} = useSettings()
|
||||
const [proxyUrl, setProxyUrl] = useState<string | undefined>(storeProxyUrl)
|
||||
const { theme } = useTheme()
|
||||
@ -147,6 +149,32 @@ const GeneralSettings: FC = () => {
|
||||
window.api.setSpellCheckLanguages(selectedLanguages)
|
||||
}
|
||||
|
||||
const handleHardwareAccelerationChange = (checked: boolean) => {
|
||||
window.modal.confirm({
|
||||
title: t('settings.hardware_acceleration.confirm.title'),
|
||||
content: t('settings.hardware_acceleration.confirm.content'),
|
||||
okText: t('common.confirm'),
|
||||
cancelText: t('common.cancel'),
|
||||
centered: true,
|
||||
onOk() {
|
||||
try {
|
||||
setDisableHardwareAcceleration(checked)
|
||||
} catch (error) {
|
||||
window.message.error({
|
||||
content: (error as Error).message,
|
||||
key: 'disable-hardware-acceleration-error'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 重启应用
|
||||
setTimeout(() => {
|
||||
window.api.relaunchApp()
|
||||
}, 500)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<SettingContainer theme={theme}>
|
||||
<SettingGroup theme={theme}>
|
||||
@ -223,6 +251,11 @@ const GeneralSettings: FC = () => {
|
||||
</SettingRow>
|
||||
</>
|
||||
)}
|
||||
<SettingDivider />
|
||||
<SettingRow>
|
||||
<SettingRowTitle>{t('settings.hardware_acceleration.title')}</SettingRowTitle>
|
||||
<Switch checked={disableHardwareAcceleration} onChange={handleHardwareAccelerationChange} />
|
||||
</SettingRow>
|
||||
</SettingGroup>
|
||||
<SettingGroup theme={theme}>
|
||||
<SettingTitle>{t('settings.notification.title')}</SettingTitle>
|
||||
|
||||
@ -1721,6 +1721,7 @@ const migrateConfig = {
|
||||
try {
|
||||
addProvider(state, 'new-api')
|
||||
state.llm.providers = moveProvider(state.llm.providers, 'new-api', 16)
|
||||
state.settings.disableHardwareAcceleration = false
|
||||
return state
|
||||
} catch (error) {
|
||||
return state
|
||||
|
||||
@ -163,6 +163,8 @@ export interface SettingsState {
|
||||
spellCheckLanguages: string[]
|
||||
enableQuickPanelTriggers: boolean
|
||||
enableBackspaceDeleteModel: boolean
|
||||
// 硬件加速设置
|
||||
disableHardwareAcceleration: boolean
|
||||
exportMenuOptions: {
|
||||
image: boolean
|
||||
markdown: boolean
|
||||
@ -310,6 +312,8 @@ export const initialState: SettingsState = {
|
||||
spellCheckLanguages: [],
|
||||
enableQuickPanelTriggers: false,
|
||||
enableBackspaceDeleteModel: true,
|
||||
// 硬件加速设置
|
||||
disableHardwareAcceleration: false,
|
||||
exportMenuOptions: {
|
||||
image: true,
|
||||
markdown: true,
|
||||
@ -685,6 +689,9 @@ const settingsSlice = createSlice({
|
||||
setEnableBackspaceDeleteModel: (state, action: PayloadAction<boolean>) => {
|
||||
state.enableBackspaceDeleteModel = action.payload
|
||||
},
|
||||
setDisableHardwareAcceleration: (state, action: PayloadAction<boolean>) => {
|
||||
state.disableHardwareAcceleration = action.payload
|
||||
},
|
||||
setOpenAISummaryText: (state, action: PayloadAction<OpenAISummaryText>) => {
|
||||
state.openAI.summaryText = action.payload
|
||||
},
|
||||
@ -801,6 +808,7 @@ export const {
|
||||
setExportMenuOptions,
|
||||
setEnableQuickPanelTriggers,
|
||||
setEnableBackspaceDeleteModel,
|
||||
setDisableHardwareAcceleration,
|
||||
setOpenAISummaryText,
|
||||
setOpenAIServiceTier,
|
||||
setNotificationSettings,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user