Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/app/src/context/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createSimpleContext } from "@opencode-ai/ui/context"
import { useGlobalSync } from "./global-sync"
import { useGlobalSDK } from "./global-sdk"
import { useServer } from "./server"
import { usePlatform } from "./platform"
import { Project } from "@opencode-ai/sdk/v2"
import { Persist, persisted, removePersisted } from "@/utils/persist"
import { same } from "@/utils/same"
Expand Down Expand Up @@ -90,6 +91,7 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(
const globalSdk = useGlobalSDK()
const globalSync = useGlobalSync()
const server = useServer()
const platform = usePlatform()

const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value)
Expand Down Expand Up @@ -200,10 +202,10 @@ export const { use: useLayout, provider: LayoutProvider } = createSimpleContext(

for (const entry of SESSION_STATE_KEYS) {
const target = session ? Persist.session(dir, session, entry.key) : Persist.workspace(dir, entry.key)
void removePersisted(target)
void removePersisted(target, platform)

const legacyKey = `${dir}/${entry.legacy}${session ? "/" + session : ""}.${entry.version}`
void removePersisted({ key: legacyKey })
void removePersisted({ key: legacyKey }, platform)
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/app/src/context/terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createSimpleContext } from "@opencode-ai/ui/context"
import { batch, createEffect, createMemo, createRoot, onCleanup } from "solid-js"
import { useParams } from "@solidjs/router"
import { useSDK } from "./sdk"
import type { Platform } from "./platform"
import { Persist, persisted, removePersisted } from "@/utils/persist"

export type LocalPTY = {
Expand Down Expand Up @@ -37,14 +38,18 @@ type TerminalCacheEntry = {

const caches = new Set<Map<string, TerminalCacheEntry>>()

export function clearWorkspaceTerminals(dir: string, sessionIDs?: string[]) {
export function clearWorkspaceTerminals(
dir: string,
sessionIDs?: string[],
platform?: Platform,
) {
const key = getWorkspaceTerminalCacheKey(dir)
for (const cache of caches) {
const entry = cache.get(key)
entry?.value.clear()
}

removePersisted(Persist.workspace(dir, "terminal"))
removePersisted(Persist.workspace(dir, "terminal"), platform)

const legacy = new Set(getLegacyTerminalStorageKeys(dir))
for (const id of sessionIDs ?? []) {
Expand All @@ -53,7 +58,7 @@ export function clearWorkspaceTerminals(dir: string, sessionIDs?: string[]) {
}
}
for (const key of legacy) {
removePersisted({ key })
removePersisted({ key }, platform)
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/app/src/pages/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,16 @@ export default function Layout(props: ParentProps) {

if (!result) return

globalSync.set(
"project",
produce((draft) => {
const project = draft.find((item) => item.worktree === root)
if (!project) return
project.sandboxes = (project.sandboxes ?? []).filter((sandbox) => sandbox !== directory)
}),
)
setStore("workspaceOrder", root, (order) => (order ?? []).filter((workspace) => workspace !== directory))

layout.projects.close(directory)
layout.projects.open(root)

Expand Down Expand Up @@ -1230,6 +1240,7 @@ export default function Layout(props: ParentProps) {
clearWorkspaceTerminals(
directory,
sessions.map((s) => s.id),
platform,
)
await globalSDK.client.instance.dispose({ directory }).catch(() => undefined)

Expand Down
7 changes: 3 additions & 4 deletions packages/app/src/utils/persist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { usePlatform } from "@/context/platform"
import { Platform, usePlatform } from "@/context/platform"
import { makePersisted, type AsyncStorage, type SyncStorage } from "@solid-primitives/storage"
import { checksum } from "@opencode-ai/util/encode"
import { createResource, type Accessor } from "solid-js"
Expand Down Expand Up @@ -318,9 +318,8 @@ export const Persist = {
},
}

export function removePersisted(target: { storage?: string; key: string }) {
const platform = usePlatform()
const isDesktop = platform.platform === "desktop" && !!platform.storage
export function removePersisted(target: { storage?: string; key: string }, platform?: Platform) {
const isDesktop = platform?.platform === "desktop" && !!platform.storage

if (isDesktop) {
return platform.storage?.(target.storage)?.removeItem(target.key)
Expand Down
Loading