Skip to content

Commit 1491dc5

Browse files
committed
feat(desktop): add hardware acceleration toggle for Windows
- Add 'Disable hardware acceleration' setting in Settings > General > Advanced - Only shown on Windows where WebView2 is used - Passes --disable-gpu flags to WebView2 when enabled - Requires app restart to take effect - May fix crashes and conflicts with other GPU-using apps like Chrome Related issues: anomalyco#10248, anomalyco#9385, anomalyco#9151, anomalyco#7046
1 parent f6bab99 commit 1491dc5

5 files changed

Lines changed: 124 additions & 2 deletions

File tree

‎packages/app/src/components/settings-general.tsx‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, createMemo, Show, type JSX } from "solid-js"
1+
import { Component, createMemo, createSignal, Show, type JSX, createResource, onMount } from "solid-js"
22
import { Select } from "@opencode-ai/ui/select"
33
import { Switch } from "@opencode-ai/ui/switch"
44
import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme"
@@ -294,6 +294,11 @@ export const SettingsGeneral: Component = () => {
294294
</div>
295295
</Show>
296296

297+
{/* Advanced Section - only show on Windows desktop */}
298+
<Show when={platform.os === "windows" && platform.getDisableHardwareAcceleration}>
299+
<AdvancedSection />
300+
</Show>
301+
297302
</div>
298303
</div>
299304
)
@@ -316,3 +321,53 @@ const SettingsRow: Component<SettingsRowProps> = (props) => {
316321
</div>
317322
)
318323
}
324+
325+
const AdvancedSection: Component = () => {
326+
const platform = usePlatform()
327+
const language = useLanguage()
328+
const [disableGpu, setDisableGpu] = createSignal(false)
329+
const [needsRestart, setNeedsRestart] = createSignal(false)
330+
331+
onMount(async () => {
332+
if (platform.getDisableHardwareAcceleration) {
333+
const value = await platform.getDisableHardwareAcceleration()
334+
setDisableGpu(value)
335+
}
336+
})
337+
338+
const handleToggle = async (checked: boolean) => {
339+
if (platform.setDisableHardwareAcceleration) {
340+
await platform.setDisableHardwareAcceleration(checked)
341+
setDisableGpu(checked)
342+
setNeedsRestart(true)
343+
}
344+
}
345+
346+
return (
347+
<div class="flex flex-col gap-1">
348+
<h3 class="text-14-medium text-text-strong pb-2">{language.t("settings.general.section.advanced")}</h3>
349+
350+
<div class="bg-surface-raised-base px-4 rounded-lg">
351+
<SettingsRow
352+
title={language.t("settings.general.advanced.disableHardwareAcceleration.title")}
353+
description={language.t("settings.general.advanced.disableHardwareAcceleration.description")}
354+
>
355+
<div class="flex items-center gap-2">
356+
<Show when={needsRestart()}>
357+
<button
358+
class="text-12-regular text-text-info hover:underline"
359+
onClick={() => platform.restart()}
360+
>
361+
Restart now
362+
</button>
363+
</Show>
364+
<Switch
365+
checked={disableGpu()}
366+
onChange={handleToggle}
367+
/>
368+
</div>
369+
</SettingsRow>
370+
</div>
371+
</div>
372+
)
373+
}

‎packages/app/src/context/platform.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export type Platform = {
8585

8686
/** Watch a file for changes (desktop only) - returns an unwatch function */
8787
watchFile?(path: string, callback: (event: FileWatchEvent) => void): Promise<() => void>
88+
89+
/** Get hardware acceleration disabled setting (desktop only, Windows) */
90+
getDisableHardwareAcceleration?(): Promise<boolean>
91+
92+
/** Set hardware acceleration disabled setting (desktop only, Windows) - requires restart */
93+
setDisableHardwareAcceleration?(disable: boolean): Promise<void>
8894
}
8995

9096
export type FileWatchEvent = {

‎packages/app/src/i18n/en.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,14 @@ export const dict = {
481481
"settings.general.section.notifications": "System notifications",
482482
"settings.general.section.sounds": "Sound effects",
483483
"settings.general.section.editor": "File Editor",
484+
"settings.general.section.advanced": "Advanced",
484485

485486
"settings.general.editor.autoReloadBackgroundFiles.title": "Auto-reload background files",
486487
"settings.general.editor.autoReloadBackgroundFiles.description": "Automatically reload inactive tabs when files change on disk (e.g., edited by AI). When off, you'll be prompted to reload or keep your version.",
487488

489+
"settings.general.advanced.disableHardwareAcceleration.title": "Disable hardware acceleration",
490+
"settings.general.advanced.disableHardwareAcceleration.description": "Disable GPU acceleration for the app. May fix crashes or conflicts with other apps. Requires restart.",
491+
488492
"settings.general.row.language.title": "Language",
489493
"settings.general.row.language.description": "Change the display language for OpenCode",
490494
"settings.general.row.appearance.title": "Appearance",

‎packages/desktop/src-tauri/src/lib.rs‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::window_customizer::PinchZoomDisablePlugin;
2727

2828
const SETTINGS_STORE: &str = "opencode.settings.dat";
2929
const DEFAULT_SERVER_URL_KEY: &str = "defaultServerUrl";
30+
const DISABLE_GPU_KEY: &str = "disableHardwareAcceleration";
3031
const MAX_FILE_SIZE: usize = 10 * 1024 * 1024;
3132

3233
#[derive(Clone, serde::Serialize)]
@@ -158,6 +159,34 @@ async fn set_default_server_url(app: AppHandle, url: Option<String>) -> Result<(
158159
Ok(())
159160
}
160161

162+
#[tauri::command]
163+
fn get_disable_hardware_acceleration(app: AppHandle) -> Result<bool, String> {
164+
let store = app
165+
.store(SETTINGS_STORE)
166+
.map_err(|e| format!("Failed to open settings store: {}", e))?;
167+
168+
let value = store.get(DISABLE_GPU_KEY);
169+
match value {
170+
Some(v) => Ok(v.as_bool().unwrap_or(false)),
171+
None => Ok(false),
172+
}
173+
}
174+
175+
#[tauri::command]
176+
async fn set_disable_hardware_acceleration(app: AppHandle, disable: bool) -> Result<(), String> {
177+
let store = app
178+
.store(SETTINGS_STORE)
179+
.map_err(|e| format!("Failed to open settings store: {}", e))?;
180+
181+
store.set(DISABLE_GPU_KEY, serde_json::Value::Bool(disable));
182+
183+
store
184+
.save()
185+
.map_err(|e| format!("Failed to save settings: {}", e))?;
186+
187+
Ok(())
188+
}
189+
161190
#[tauri::command]
162191
fn get_project_root(app: AppHandle) -> Result<String, String> {
163192
app.path()
@@ -512,6 +541,8 @@ pub fn run() {
512541
ensure_server_ready,
513542
get_default_server_url,
514543
set_default_server_url,
544+
get_disable_hardware_acceleration,
545+
set_disable_hardware_acceleration,
515546
markdown::parse_markdown_command,
516547
get_project_root,
517548
read_directory,
@@ -545,6 +576,16 @@ pub fn run() {
545576
.find(|w| w.label == "main")
546577
.expect("main window config missing");
547578

579+
// Check if hardware acceleration should be disabled (Windows only)
580+
#[cfg(windows)]
581+
let disable_gpu = {
582+
app.store(SETTINGS_STORE)
583+
.ok()
584+
.and_then(|store| store.get(DISABLE_GPU_KEY))
585+
.and_then(|v| v.as_bool())
586+
.unwrap_or(false)
587+
};
588+
548589
let window_builder = WebviewWindowBuilder::from_config(&app, config)
549590
.expect("Failed to create window builder from config")
550591
.inner_size(size.width as f64, size.height as f64)
@@ -561,7 +602,15 @@ pub fn run() {
561602
.hidden_title(true);
562603

563604
#[cfg(windows)]
564-
let window_builder = window_builder.decorations(false);
605+
let window_builder = {
606+
let builder = window_builder.decorations(false);
607+
if disable_gpu {
608+
println!("Hardware acceleration disabled by user setting");
609+
builder.additional_browser_args("--disable-gpu --disable-gpu-compositing --disable-software-rasterizer")
610+
} else {
611+
builder
612+
}
613+
};
565614

566615
let window = window_builder.build().expect("Failed to create window");
567616

‎packages/desktop/src/index.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({
372372
}, { delayMs: 500 })
373373
return unwatch
374374
},
375+
376+
getDisableHardwareAcceleration: async () => {
377+
return invoke<boolean>("get_disable_hardware_acceleration").catch(() => false)
378+
},
379+
380+
setDisableHardwareAcceleration: async (disable: boolean) => {
381+
await invoke("set_disable_hardware_acceleration", { disable })
382+
},
375383
})
376384

377385
createMenu()

0 commit comments

Comments
 (0)