Skip to content

Commit 28a00ad

Browse files
fix(app): enable auto-accept in session settings (#33974)
1 parent 0f272d9 commit 28a00ad

7 files changed

Lines changed: 67 additions & 48 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { useParams } from "@solidjs/router"
2+
import { onCleanup } from "solid-js"
3+
import { useCommand } from "@/context/command"
4+
import { useLanguage } from "@/context/language"
5+
import { useDialog } from "@opencode-ai/ui/context/dialog"
6+
7+
export function useSettingsDialog() {
8+
const dialog = useDialog()
9+
const params = useParams<{ id?: string }>()
10+
let run = 0
11+
let dead = false
12+
13+
onCleanup(() => {
14+
dead = true
15+
})
16+
17+
return () => {
18+
const current = ++run
19+
const sessionID = params.id
20+
void import("@/components/settings-v2").then((module) => {
21+
if (dead || run !== current) return
22+
void dialog.show(() => <module.DialogSettings sessionID={sessionID} />)
23+
})
24+
}
25+
}
26+
27+
export function useSettingsCommand() {
28+
const command = useCommand()
29+
const language = useLanguage()
30+
const show = useSettingsDialog()
31+
32+
command.register("settings", () => [
33+
{
34+
id: "settings.open",
35+
title: language.t("command.settings.open"),
36+
category: language.t("command.category.settings"),
37+
keybind: "mod+comma",
38+
onSelect: show,
39+
},
40+
])
41+
42+
return show
43+
}

packages/app/src/components/settings-v2/dialog-settings-v2.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { SettingsModelsV2 } from "./models"
1111
import "./settings-v2.css"
1212
import { SettingsServersV2 } from "./servers"
1313

14-
export const DialogSettings: Component = () => {
14+
export const DialogSettings: Component<{
15+
sessionID?: string
16+
}> = (props) => {
1517
const language = useLanguage()
1618
const platform = usePlatform()
1719

@@ -62,7 +64,7 @@ export const DialogSettings: Component = () => {
6264
</div>
6365
</TabsV2.List>
6466
<TabsV2.Content value="general" class="settings-v2-panel">
65-
<SettingsGeneralV2 />
67+
<SettingsGeneralV2 sessionID={props.sessionID} />
6668
</TabsV2.Content>
6769
<TabsV2.Content value="shortcuts" class="settings-v2-panel">
6870
<SettingsKeybinds v2 />

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Switch } from "@opencode-ai/ui/v2/switch-v2"
66
import { TextInputV2 } from "@opencode-ai/ui/v2/text-input-v2"
77
import { useTheme, type ColorScheme } from "@opencode-ai/ui/theme/context"
88
import { useDialog } from "@opencode-ai/ui/context/dialog"
9-
import { useParams } from "@solidjs/router"
109
import { useLanguage } from "@/context/language"
1110
import { usePermission } from "@/context/permission"
1211
import { usePlatform } from "@/context/platform"
@@ -25,7 +24,6 @@ import {
2524
terminalInput,
2625
useSettings,
2726
} from "@/context/settings"
28-
import { decode64 } from "@/utils/base64"
2927
import { playSoundById, SOUND_OPTIONS } from "@/utils/sound"
3028
import { Link } from "../link"
3129
import { SettingsListV2 } from "./parts/list"
@@ -82,50 +80,46 @@ const playDemoSound = (id: string | undefined) => {
8280
}, 100)
8381
}
8482

85-
export const SettingsGeneralV2: Component = () => {
83+
export const SettingsGeneralV2: Component<{
84+
sessionID?: string
85+
}> = (props) => {
8686
const theme = useTheme()
8787
const language = useLanguage()
8888
const permission = usePermission()
8989
const platform = usePlatform()
9090
const dialog = useDialog()
91-
const params = useParams()
9291
const settings = useSettings()
92+
const serverSync = useServerSync()
93+
const serverSdk = useServerSDK()
9394
const mobile = createMediaQuery("(max-width: 767px)")
9495

9596
const updater = useUpdaterAction()
9697

97-
const dir = createMemo(() => decode64(params.dir))
98+
const dir = createMemo(() => {
99+
if (!props.sessionID) return undefined
100+
return serverSync().session.lineage.peek(props.sessionID)?.session.directory
101+
})
98102
const accepting = createMemo(() => {
99103
const value = dir()
100-
if (!value) return false
101-
if (!params.id) return permission.isAutoAcceptingDirectory(value)
102-
return permission.isAutoAccepting(params.id, value)
104+
if (!value || !props.sessionID) return false
105+
return permission.isAutoAccepting(props.sessionID, value)
103106
})
104107

105108
const toggleAccept = (checked: boolean) => {
106109
const value = dir()
107-
if (!value) return
108-
109-
if (!params.id) {
110-
if (permission.isAutoAcceptingDirectory(value) === checked) return
111-
permission.toggleAutoAcceptDirectory(value)
112-
return
113-
}
110+
if (!value || !props.sessionID) return
114111

115112
if (checked) {
116-
permission.enableAutoAccept(params.id, value)
113+
permission.enableAutoAccept(props.sessionID, value)
117114
return
118115
}
119116

120-
permission.disableAutoAccept(params.id, value)
117+
permission.disableAutoAccept(props.sessionID, value)
121118
}
122119
const desktop = createMemo(() => platform.platform === "desktop")
123120

124121
const themeOptions = createMemo<ThemeOption[]>(() => theme.ids().map((id) => ({ id, name: theme.name(id) })))
125122

126-
const serverSync = useServerSync()
127-
const serverSdk = useServerSDK()
128-
129123
const [shells] = createResource(
130124
() =>
131125
serverSdk()

packages/app/src/pages/home.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { usePlatform } from "@/context/platform"
3333
import { DateTime } from "luxon"
3434
import { useDialog } from "@opencode-ai/ui/context/dialog"
3535
import { useDirectoryPicker } from "@/components/directory-picker"
36+
import { useSettingsCommand } from "@/components/settings-dialog"
3637
import { DialogSelectServer, useServerManagementController } from "@/components/dialog-select-server"
3738
import { DialogServerV2 } from "@/components/settings-v2/dialog-server-v2"
3839
import { ServerConnection, serverName, useServer } from "@/context/server"
@@ -144,6 +145,7 @@ export function NewHome() {
144145
const command = useCommand()
145146
const notification = useNotification()
146147
const marked = useMarked()
148+
const openSettings = useSettingsCommand()
147149
let focusSessionSearch: (() => void) | undefined
148150
const [state, setState] = createStore({
149151
search: "",
@@ -402,12 +404,6 @@ export function NewHome() {
402404
})
403405
}
404406

405-
function openSettings() {
406-
void import("@/components/settings-v2").then((x) => {
407-
dialog.show(() => <x.DialogSettings />)
408-
})
409-
}
410-
411407
return (
412408
<div class="rounded-[10px] shadow-[var(--v2-elevation-raised)] m-2 min-h-0 lg:overflow-hidden bg-v2-background-bg-base self-stretch flex-1">
413409
<div class="mx-auto grid h-full w-full max-w-[1080px] grid-rows-[auto_minmax(0,1fr)_auto] gap-4 px-3 pb-3 lg:grid-cols-[280px_minmax(0,720px)] lg:grid-rows-1 lg:gap-8 lg:px-6 lg:pb-16">

packages/app/src/pages/layout-new.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ import { useNavigate, useParams } from "@solidjs/router"
33
import { DebugBar } from "@/components/debug-bar"
44
import { HelpButton } from "@/components/help-button"
55
import { Titlebar, type TitlebarUpdate } from "@/components/titlebar"
6-
import { useCommand } from "@/context/command"
7-
import { useDialog } from "@opencode-ai/ui/context/dialog"
8-
import { useLanguage } from "@/context/language"
96
import { useNotification } from "@/context/notification"
107
import { usePlatform } from "@/context/platform"
118
import { setNavigate } from "@/utils/notification-click"
129
import { setV2Toast, ToastRegion } from "@/utils/toast"
1310

1411
export default function NewLayout(props: ParentProps) {
15-
const command = useCommand()
16-
const dialog = useDialog()
17-
const language = useLanguage()
1812
const platform = usePlatform()
1913
const notification = useNotification()
2014
const navigate = useNavigate()
@@ -28,20 +22,6 @@ export default function NewLayout(props: ParentProps) {
2822
notification.session.markViewed(params.id)
2923
})
3024

31-
command.register("layout", () => [
32-
{
33-
id: "settings.open",
34-
title: language.t("command.settings.open"),
35-
category: language.t("command.category.settings"),
36-
keybind: "mod+comma",
37-
onSelect: () => {
38-
void import("@/components/settings-v2").then((x) => {
39-
dialog.show(() => <x.DialogSettings />)
40-
})
41-
},
42-
},
43-
])
44-
4525
const update: TitlebarUpdate = {
4626
version: () => {
4727
const state = platform.updater?.state()

packages/app/src/pages/new-session.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createStore } from "solid-js/store"
33
import { useSearchParams } from "@solidjs/router"
44
import { NewSessionDesignView } from "@/components/session"
55
import { PromptInput } from "@/components/prompt-input"
6+
import { useSettingsCommand } from "@/components/settings-dialog"
67
import {
78
PromptProjectAddButton,
89
PromptProjectSelector,
@@ -35,6 +36,7 @@ export default function NewSessionPage() {
3536
const [searchParams, setSearchParams] = useSearchParams<{ draftId?: string; prompt?: string }>()
3637

3738
useComposerCommands()
39+
useSettingsCommand()
3840

3941
let inputRef: HTMLDivElement | undefined
4042

packages/app/src/pages/session.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { useSettings } from "@/context/settings"
4343
import { useSync } from "@/context/sync"
4444
import { useTerminal } from "@/context/terminal"
4545
import { PromptInput } from "@/components/prompt-input"
46+
import { useSettingsCommand } from "@/components/settings-dialog"
4647
import { type FollowupDraft, sendFollowupDraft } from "@/components/prompt-input/submit"
4748
import {
4849
createPromptInputController,
@@ -787,6 +788,7 @@ export default function Page() {
787788
}
788789

789790
useComposerCommands()
791+
useSettingsCommand()
790792
useSessionCommands({
791793
navigateMessageByOffset,
792794
setActiveMessage,

0 commit comments

Comments
 (0)