summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/settings.tsx
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-12 09:49:14 -0600
committerGitHub <[email protected]>2026-02-12 09:49:14 -0600
commitff4414bb152acfddb5c0eb073c38bedc1df4ae14 (patch)
tree78381c67d21ef6f089647f6b19e7aa2976840dbc /packages/app/src/context/settings.tsx
parent56ad2db02055955f926fda0e4a89055b22ead6f9 (diff)
downloadopencode-ff4414bb152acfddb5c0eb073c38bedc1df4ae14.tar.gz
opencode-ff4414bb152acfddb5c0eb073c38bedc1df4ae14.zip
chore: refactor packages/app files (#13236)
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Frank <[email protected]>
Diffstat (limited to 'packages/app/src/context/settings.tsx')
-rw-r--r--packages/app/src/context/settings.tsx35
1 files changed, 22 insertions, 13 deletions
diff --git a/packages/app/src/context/settings.tsx b/packages/app/src/context/settings.tsx
index 19b3846f8..a8efb1eac 100644
--- a/packages/app/src/context/settings.tsx
+++ b/packages/app/src/context/settings.tsx
@@ -85,6 +85,10 @@ export function monoFontFamily(font: string | undefined) {
return monoFonts[font ?? defaultSettings.appearance.font] ?? monoFonts[defaultSettings.appearance.font]
}
+function withFallback<T>(read: () => T | undefined, fallback: T) {
+ return createMemo(() => read() ?? fallback)
+}
+
export const { use: useSettings, provider: SettingsProvider } = createSimpleContext({
name: "Settings",
init: () => {
@@ -101,27 +105,27 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
return store
},
general: {
- autoSave: createMemo(() => store.general?.autoSave ?? defaultSettings.general.autoSave),
+ autoSave: withFallback(() => store.general?.autoSave, defaultSettings.general.autoSave),
setAutoSave(value: boolean) {
setStore("general", "autoSave", value)
},
- releaseNotes: createMemo(() => store.general?.releaseNotes ?? defaultSettings.general.releaseNotes),
+ releaseNotes: withFallback(() => store.general?.releaseNotes, defaultSettings.general.releaseNotes),
setReleaseNotes(value: boolean) {
setStore("general", "releaseNotes", value)
},
},
updates: {
- startup: createMemo(() => store.updates?.startup ?? defaultSettings.updates.startup),
+ startup: withFallback(() => store.updates?.startup, defaultSettings.updates.startup),
setStartup(value: boolean) {
setStore("updates", "startup", value)
},
},
appearance: {
- fontSize: createMemo(() => store.appearance?.fontSize ?? defaultSettings.appearance.fontSize),
+ fontSize: withFallback(() => store.appearance?.fontSize, defaultSettings.appearance.fontSize),
setFontSize(value: number) {
setStore("appearance", "fontSize", value)
},
- font: createMemo(() => store.appearance?.font ?? defaultSettings.appearance.font),
+ font: withFallback(() => store.appearance?.font, defaultSettings.appearance.font),
setFont(value: string) {
setStore("appearance", "font", value)
},
@@ -132,42 +136,47 @@ export const { use: useSettings, provider: SettingsProvider } = createSimpleCont
setStore("keybinds", action, keybind)
},
reset(action: string) {
- setStore("keybinds", action, undefined!)
+ setStore("keybinds", (current) => {
+ if (!Object.prototype.hasOwnProperty.call(current, action)) return current
+ const next = { ...current }
+ delete next[action]
+ return next
+ })
},
resetAll() {
setStore("keybinds", reconcile({}))
},
},
permissions: {
- autoApprove: createMemo(() => store.permissions?.autoApprove ?? defaultSettings.permissions.autoApprove),
+ autoApprove: withFallback(() => store.permissions?.autoApprove, defaultSettings.permissions.autoApprove),
setAutoApprove(value: boolean) {
setStore("permissions", "autoApprove", value)
},
},
notifications: {
- agent: createMemo(() => store.notifications?.agent ?? defaultSettings.notifications.agent),
+ agent: withFallback(() => store.notifications?.agent, defaultSettings.notifications.agent),
setAgent(value: boolean) {
setStore("notifications", "agent", value)
},
- permissions: createMemo(() => store.notifications?.permissions ?? defaultSettings.notifications.permissions),
+ permissions: withFallback(() => store.notifications?.permissions, defaultSettings.notifications.permissions),
setPermissions(value: boolean) {
setStore("notifications", "permissions", value)
},
- errors: createMemo(() => store.notifications?.errors ?? defaultSettings.notifications.errors),
+ errors: withFallback(() => store.notifications?.errors, defaultSettings.notifications.errors),
setErrors(value: boolean) {
setStore("notifications", "errors", value)
},
},
sounds: {
- agent: createMemo(() => store.sounds?.agent ?? defaultSettings.sounds.agent),
+ agent: withFallback(() => store.sounds?.agent, defaultSettings.sounds.agent),
setAgent(value: string) {
setStore("sounds", "agent", value)
},
- permissions: createMemo(() => store.sounds?.permissions ?? defaultSettings.sounds.permissions),
+ permissions: withFallback(() => store.sounds?.permissions, defaultSettings.sounds.permissions),
setPermissions(value: string) {
setStore("sounds", "permissions", value)
},
- errors: createMemo(() => store.sounds?.errors ?? defaultSettings.sounds.errors),
+ errors: withFallback(() => store.sounds?.errors, defaultSettings.sounds.errors),
setErrors(value: string) {
setStore("sounds", "errors", value)
},