summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context
diff options
context:
space:
mode:
authorOpeOginni <[email protected]>2026-03-19 14:32:11 +0100
committerGitHub <[email protected]>2026-03-19 13:32:11 +0000
commitbd4527b4f28333a3c49faba43dc03d99e1e02ae2 (patch)
treefbbe7344885a0ab34f79b324e23cf48f23afdd9e /packages/app/src/context
parentf4a9fe29a3b9ef4050d5d4ec45c1da74fcd42a21 (diff)
downloadopencode-bd4527b4f28333a3c49faba43dc03d99e1e02ae2.tar.gz
opencode-bd4527b4f28333a3c49faba43dc03d99e1e02ae2.zip
fix(desktop): remote server switching (#17214)
Co-authored-by: Brendan Allan <[email protected]>
Diffstat (limited to 'packages/app/src/context')
-rw-r--r--packages/app/src/context/terminal.tsx122
1 files changed, 73 insertions, 49 deletions
diff --git a/packages/app/src/context/terminal.tsx b/packages/app/src/context/terminal.tsx
index e65c16788..17355aab9 100644
--- a/packages/app/src/context/terminal.tsx
+++ b/packages/app/src/context/terminal.tsx
@@ -185,6 +185,60 @@ function createWorkspaceTerminalSession(sdk: ReturnType<typeof useSDK>, dir: str
})
onCleanup(unsub)
+ const update = (client: ReturnType<typeof useSDK>["client"], pty: Partial<LocalPTY> & { id: string }) => {
+ const index = store.all.findIndex((x) => x.id === pty.id)
+ const previous = index >= 0 ? store.all[index] : undefined
+ if (index >= 0) {
+ setStore("all", index, (item) => ({ ...item, ...pty }))
+ }
+ client.pty
+ .update({
+ ptyID: pty.id,
+ title: pty.title,
+ size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
+ })
+ .catch((error: unknown) => {
+ if (previous) {
+ const currentIndex = store.all.findIndex((item) => item.id === pty.id)
+ if (currentIndex >= 0) setStore("all", currentIndex, previous)
+ }
+ console.error("Failed to update terminal", error)
+ })
+ }
+
+ const clone = async (client: ReturnType<typeof useSDK>["client"], id: string) => {
+ const index = store.all.findIndex((x) => x.id === id)
+ const pty = store.all[index]
+ if (!pty) return
+ const next = await client.pty
+ .create({
+ title: pty.title,
+ })
+ .catch((error: unknown) => {
+ console.error("Failed to clone terminal", error)
+ return undefined
+ })
+ if (!next?.data) return
+
+ const active = store.active === pty.id
+
+ batch(() => {
+ setStore("all", index, {
+ id: next.data.id,
+ title: next.data.title ?? pty.title,
+ titleNumber: pty.titleNumber,
+ buffer: undefined,
+ cursor: undefined,
+ scrollY: undefined,
+ rows: undefined,
+ cols: undefined,
+ })
+ if (active) {
+ setStore("active", next.data.id)
+ }
+ })
+ }
+
return {
ready,
all: createMemo(() => store.all),
@@ -216,24 +270,7 @@ function createWorkspaceTerminalSession(sdk: ReturnType<typeof useSDK>, dir: str
})
},
update(pty: Partial<LocalPTY> & { id: string }) {
- const index = store.all.findIndex((x) => x.id === pty.id)
- const previous = index >= 0 ? store.all[index] : undefined
- if (index >= 0) {
- setStore("all", index, (item) => ({ ...item, ...pty }))
- }
- sdk.client.pty
- .update({
- ptyID: pty.id,
- title: pty.title,
- size: pty.cols && pty.rows ? { rows: pty.rows, cols: pty.cols } : undefined,
- })
- .catch((error: unknown) => {
- if (previous) {
- const currentIndex = store.all.findIndex((item) => item.id === pty.id)
- if (currentIndex >= 0) setStore("all", currentIndex, previous)
- }
- console.error("Failed to update terminal", error)
- })
+ update(sdk.client, pty)
},
trim(id: string) {
const index = store.all.findIndex((x) => x.id === id)
@@ -248,37 +285,23 @@ function createWorkspaceTerminalSession(sdk: ReturnType<typeof useSDK>, dir: str
})
},
async clone(id: string) {
- const index = store.all.findIndex((x) => x.id === id)
- const pty = store.all[index]
- if (!pty) return
- const clone = await sdk.client.pty
- .create({
- title: pty.title,
- })
- .catch((error: unknown) => {
- console.error("Failed to clone terminal", error)
- return undefined
- })
- if (!clone?.data) return
-
- const active = store.active === pty.id
-
- batch(() => {
- setStore("all", index, {
- id: clone.data.id,
- title: clone.data.title ?? pty.title,
- titleNumber: pty.titleNumber,
- // New PTY process, so start clean.
- buffer: undefined,
- cursor: undefined,
- scrollY: undefined,
- rows: undefined,
- cols: undefined,
- })
- if (active) {
- setStore("active", clone.data.id)
- }
- })
+ await clone(sdk.client, id)
+ },
+ bind() {
+ const client = sdk.client
+ return {
+ trim(id: string) {
+ const index = store.all.findIndex((x) => x.id === id)
+ if (index === -1) return
+ setStore("all", index, (pty) => trimTerminal(pty))
+ },
+ update(pty: Partial<LocalPTY> & { id: string }) {
+ update(client, pty)
+ },
+ async clone(id: string) {
+ await clone(client, id)
+ },
+ }
},
open(id: string) {
setStore("active", id)
@@ -403,6 +426,7 @@ export const { use: useTerminal, provider: TerminalProvider } = createSimpleCont
trim: (id: string) => workspace().trim(id),
trimAll: () => workspace().trimAll(),
clone: (id: string) => workspace().clone(id),
+ bind: () => workspace(),
open: (id: string) => workspace().open(id),
close: (id: string) => workspace().close(id),
move: (id: string, to: number) => workspace().move(id, to),