mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 22:10:21 +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_MacRequestProcessTrust = 'app:mac-request-process-trust',
|
||||||
|
|
||||||
App_QuoteToMain = 'app:quote-to-main',
|
App_QuoteToMain = 'app:quote-to-main',
|
||||||
|
App_SetDisableHardwareAcceleration = 'app:set-disable-hardware-acceleration',
|
||||||
|
|
||||||
Notification_Send = 'notification:send',
|
Notification_Send = 'notification:send',
|
||||||
Notification_OnClick = 'notification:on-click',
|
Notification_OnClick = 'notification:on-click',
|
||||||
|
|||||||
@ -28,6 +28,14 @@ import { windowService } from './services/WindowService'
|
|||||||
|
|
||||||
Logger.initialize()
|
Logger.initialize()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable hardware acceleration if setting is enabled
|
||||||
|
*/
|
||||||
|
const disableHardwareAcceleration = configManager.getDisableHardwareAcceleration()
|
||||||
|
if (disableHardwareAcceleration) {
|
||||||
|
app.disableHardwareAcceleration()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable chromium's window animations
|
* Disable chromium's window animations
|
||||||
* main purpose for this is to avoid the transparent window flashing when it is shown
|
* 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()
|
SelectionService.registerIpcHandler()
|
||||||
|
|
||||||
ipcMain.handle(IpcChannel.App_QuoteToMain, (_, text: string) => windowService.quoteToMainWindow(text))
|
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',
|
SelectionAssistantFollowToolbar = 'selectionAssistantFollowToolbar',
|
||||||
SelectionAssistantRemeberWinSize = 'selectionAssistantRemeberWinSize',
|
SelectionAssistantRemeberWinSize = 'selectionAssistantRemeberWinSize',
|
||||||
SelectionAssistantFilterMode = 'selectionAssistantFilterMode',
|
SelectionAssistantFilterMode = 'selectionAssistantFilterMode',
|
||||||
SelectionAssistantFilterList = 'selectionAssistantFilterList'
|
SelectionAssistantFilterList = 'selectionAssistantFilterList',
|
||||||
|
DisableHardwareAcceleration = 'disableHardwareAcceleration'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ConfigManager {
|
export class ConfigManager {
|
||||||
@ -218,6 +219,14 @@ export class ConfigManager {
|
|||||||
this.setAndNotify(ConfigKeys.SelectionAssistantFilterList, value)
|
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) {
|
setAndNotify(key: string, value: unknown) {
|
||||||
this.set(key, value, true)
|
this.set(key, value, true)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -290,7 +290,9 @@ const api = {
|
|||||||
minimizeActionWindow: () => ipcRenderer.invoke(IpcChannel.Selection_ActionWindowMinimize),
|
minimizeActionWindow: () => ipcRenderer.invoke(IpcChannel.Selection_ActionWindowMinimize),
|
||||||
pinActionWindow: (isPinned: boolean) => ipcRenderer.invoke(IpcChannel.Selection_ActionWindowPin, isPinned)
|
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
|
// Use `contextBridge` APIs to expose Electron APIs to
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {
|
|||||||
SendMessageShortcut,
|
SendMessageShortcut,
|
||||||
setAssistantIconType,
|
setAssistantIconType,
|
||||||
setAutoCheckUpdate as _setAutoCheckUpdate,
|
setAutoCheckUpdate as _setAutoCheckUpdate,
|
||||||
|
setDisableHardwareAcceleration,
|
||||||
setLaunchOnBoot,
|
setLaunchOnBoot,
|
||||||
setLaunchToTray,
|
setLaunchToTray,
|
||||||
setPinTopicsToTop,
|
setPinTopicsToTop,
|
||||||
@ -100,6 +101,10 @@ export function useSettings() {
|
|||||||
},
|
},
|
||||||
setShowTokens(showTokens: boolean) {
|
setShowTokens(showTokens: boolean) {
|
||||||
dispatch(setShowTokens(showTokens))
|
dispatch(setShowTokens(showTokens))
|
||||||
|
},
|
||||||
|
setDisableHardwareAcceleration(disableHardwareAcceleration: boolean) {
|
||||||
|
dispatch(setDisableHardwareAcceleration(disableHardwareAcceleration))
|
||||||
|
window.api.setDisableHardwareAcceleration(disableHardwareAcceleration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1805,6 +1805,13 @@
|
|||||||
"title": "Proxy Settings"
|
"title": "Proxy Settings"
|
||||||
},
|
},
|
||||||
"proxy.title": "Proxy Address",
|
"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": {
|
"quickAssistant": {
|
||||||
"click_tray_to_show": "Click the tray icon to start",
|
"click_tray_to_show": "Click the tray icon to start",
|
||||||
"enable_quick_assistant": "Enable Quick Assistant",
|
"enable_quick_assistant": "Enable Quick Assistant",
|
||||||
|
|||||||
@ -1787,6 +1787,13 @@
|
|||||||
"title": "プロキシ設定"
|
"title": "プロキシ設定"
|
||||||
},
|
},
|
||||||
"proxy.title": "プロキシアドレス",
|
"proxy.title": "プロキシアドレス",
|
||||||
|
"hardware_acceleration": {
|
||||||
|
"title": "ハードウェアアクセラレーションを無効にする",
|
||||||
|
"confirm": {
|
||||||
|
"title": "再起動が必要",
|
||||||
|
"content": "ハードウェアアクセラレーションを無効にするには、アプリを再起動する必要があります。再起動しますか?"
|
||||||
|
}
|
||||||
|
},
|
||||||
"quickAssistant": {
|
"quickAssistant": {
|
||||||
"click_tray_to_show": "トレイアイコンをクリックして起動",
|
"click_tray_to_show": "トレイアイコンをクリックして起動",
|
||||||
"enable_quick_assistant": "クイックアシスタントを有効にする",
|
"enable_quick_assistant": "クイックアシスタントを有効にする",
|
||||||
|
|||||||
@ -1787,6 +1787,13 @@
|
|||||||
"title": "Настройки прокси"
|
"title": "Настройки прокси"
|
||||||
},
|
},
|
||||||
"proxy.title": "Адрес прокси",
|
"proxy.title": "Адрес прокси",
|
||||||
|
"hardware_acceleration": {
|
||||||
|
"title": "Отключить аппаратное ускорение",
|
||||||
|
"confirm": {
|
||||||
|
"title": "Требуется перезапуск",
|
||||||
|
"content": "Отключение аппаратного ускорения требует перезапуска приложения для вступления в силу. Перезапустить приложение?"
|
||||||
|
}
|
||||||
|
},
|
||||||
"quickAssistant": {
|
"quickAssistant": {
|
||||||
"click_tray_to_show": "Нажмите на иконку трея для запуска",
|
"click_tray_to_show": "Нажмите на иконку трея для запуска",
|
||||||
"enable_quick_assistant": "Включить быстрый помощник",
|
"enable_quick_assistant": "Включить быстрый помощник",
|
||||||
|
|||||||
@ -1805,6 +1805,13 @@
|
|||||||
"title": "代理设置"
|
"title": "代理设置"
|
||||||
},
|
},
|
||||||
"proxy.title": "代理地址",
|
"proxy.title": "代理地址",
|
||||||
|
"hardware_acceleration": {
|
||||||
|
"title": "禁用硬件加速",
|
||||||
|
"confirm": {
|
||||||
|
"title": "需要重启应用",
|
||||||
|
"content": "禁用硬件加速需要重启应用才能生效,是否现在重启?"
|
||||||
|
}
|
||||||
|
},
|
||||||
"quickAssistant": {
|
"quickAssistant": {
|
||||||
"click_tray_to_show": "点击托盘图标启动",
|
"click_tray_to_show": "点击托盘图标启动",
|
||||||
"enable_quick_assistant": "启用快捷助手",
|
"enable_quick_assistant": "启用快捷助手",
|
||||||
|
|||||||
@ -1790,6 +1790,13 @@
|
|||||||
"title": "代理伺服器設定"
|
"title": "代理伺服器設定"
|
||||||
},
|
},
|
||||||
"proxy.title": "代理伺服器地址",
|
"proxy.title": "代理伺服器地址",
|
||||||
|
"hardware_acceleration": {
|
||||||
|
"title": "禁用硬件加速",
|
||||||
|
"confirm": {
|
||||||
|
"title": "需要重新啟動",
|
||||||
|
"content": "禁用硬件加速需要重新啟動應用程序才能生效。是否立即重新啟動?"
|
||||||
|
}
|
||||||
|
},
|
||||||
"quickAssistant": {
|
"quickAssistant": {
|
||||||
"click_tray_to_show": "點選工具列圖示啟動",
|
"click_tray_to_show": "點選工具列圖示啟動",
|
||||||
"enable_quick_assistant": "啟用快捷助手",
|
"enable_quick_assistant": "啟用快捷助手",
|
||||||
|
|||||||
@ -35,7 +35,9 @@ const GeneralSettings: FC = () => {
|
|||||||
tray,
|
tray,
|
||||||
proxyMode: storeProxyMode,
|
proxyMode: storeProxyMode,
|
||||||
enableDataCollection,
|
enableDataCollection,
|
||||||
enableSpellCheck
|
enableSpellCheck,
|
||||||
|
disableHardwareAcceleration,
|
||||||
|
setDisableHardwareAcceleration
|
||||||
} = useSettings()
|
} = useSettings()
|
||||||
const [proxyUrl, setProxyUrl] = useState<string | undefined>(storeProxyUrl)
|
const [proxyUrl, setProxyUrl] = useState<string | undefined>(storeProxyUrl)
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
@ -147,6 +149,32 @@ const GeneralSettings: FC = () => {
|
|||||||
window.api.setSpellCheckLanguages(selectedLanguages)
|
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 (
|
return (
|
||||||
<SettingContainer theme={theme}>
|
<SettingContainer theme={theme}>
|
||||||
<SettingGroup theme={theme}>
|
<SettingGroup theme={theme}>
|
||||||
@ -223,6 +251,11 @@ const GeneralSettings: FC = () => {
|
|||||||
</SettingRow>
|
</SettingRow>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<SettingDivider />
|
||||||
|
<SettingRow>
|
||||||
|
<SettingRowTitle>{t('settings.hardware_acceleration.title')}</SettingRowTitle>
|
||||||
|
<Switch checked={disableHardwareAcceleration} onChange={handleHardwareAccelerationChange} />
|
||||||
|
</SettingRow>
|
||||||
</SettingGroup>
|
</SettingGroup>
|
||||||
<SettingGroup theme={theme}>
|
<SettingGroup theme={theme}>
|
||||||
<SettingTitle>{t('settings.notification.title')}</SettingTitle>
|
<SettingTitle>{t('settings.notification.title')}</SettingTitle>
|
||||||
|
|||||||
@ -1721,6 +1721,7 @@ const migrateConfig = {
|
|||||||
try {
|
try {
|
||||||
addProvider(state, 'new-api')
|
addProvider(state, 'new-api')
|
||||||
state.llm.providers = moveProvider(state.llm.providers, 'new-api', 16)
|
state.llm.providers = moveProvider(state.llm.providers, 'new-api', 16)
|
||||||
|
state.settings.disableHardwareAcceleration = false
|
||||||
return state
|
return state
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return state
|
return state
|
||||||
|
|||||||
@ -163,6 +163,8 @@ export interface SettingsState {
|
|||||||
spellCheckLanguages: string[]
|
spellCheckLanguages: string[]
|
||||||
enableQuickPanelTriggers: boolean
|
enableQuickPanelTriggers: boolean
|
||||||
enableBackspaceDeleteModel: boolean
|
enableBackspaceDeleteModel: boolean
|
||||||
|
// 硬件加速设置
|
||||||
|
disableHardwareAcceleration: boolean
|
||||||
exportMenuOptions: {
|
exportMenuOptions: {
|
||||||
image: boolean
|
image: boolean
|
||||||
markdown: boolean
|
markdown: boolean
|
||||||
@ -310,6 +312,8 @@ export const initialState: SettingsState = {
|
|||||||
spellCheckLanguages: [],
|
spellCheckLanguages: [],
|
||||||
enableQuickPanelTriggers: false,
|
enableQuickPanelTriggers: false,
|
||||||
enableBackspaceDeleteModel: true,
|
enableBackspaceDeleteModel: true,
|
||||||
|
// 硬件加速设置
|
||||||
|
disableHardwareAcceleration: false,
|
||||||
exportMenuOptions: {
|
exportMenuOptions: {
|
||||||
image: true,
|
image: true,
|
||||||
markdown: true,
|
markdown: true,
|
||||||
@ -685,6 +689,9 @@ const settingsSlice = createSlice({
|
|||||||
setEnableBackspaceDeleteModel: (state, action: PayloadAction<boolean>) => {
|
setEnableBackspaceDeleteModel: (state, action: PayloadAction<boolean>) => {
|
||||||
state.enableBackspaceDeleteModel = action.payload
|
state.enableBackspaceDeleteModel = action.payload
|
||||||
},
|
},
|
||||||
|
setDisableHardwareAcceleration: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.disableHardwareAcceleration = action.payload
|
||||||
|
},
|
||||||
setOpenAISummaryText: (state, action: PayloadAction<OpenAISummaryText>) => {
|
setOpenAISummaryText: (state, action: PayloadAction<OpenAISummaryText>) => {
|
||||||
state.openAI.summaryText = action.payload
|
state.openAI.summaryText = action.payload
|
||||||
},
|
},
|
||||||
@ -801,6 +808,7 @@ export const {
|
|||||||
setExportMenuOptions,
|
setExportMenuOptions,
|
||||||
setEnableQuickPanelTriggers,
|
setEnableQuickPanelTriggers,
|
||||||
setEnableBackspaceDeleteModel,
|
setEnableBackspaceDeleteModel,
|
||||||
|
setDisableHardwareAcceleration,
|
||||||
setOpenAISummaryText,
|
setOpenAISummaryText,
|
||||||
setOpenAIServiceTier,
|
setOpenAIServiceTier,
|
||||||
setNotificationSettings,
|
setNotificationSettings,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user