From aa56750f8b37bb3d1f9e0341022338497fc96380 Mon Sep 17 00:00:00 2001 From: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Date: Tue, 30 Jun 2026 18:32:30 +0800 Subject: [PATCH] fix(desktop): persist last active url (#34595) --- packages/desktop/src/renderer/index.tsx | 29 +++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index c9bd050e709..fd91badea94 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -17,7 +17,7 @@ import { import type { UpdaterState } from "@opencode-ai/app/updater" import * as Sentry from "@sentry/solid" import type { AsyncStorage } from "@solid-primitives/storage" -import { MemoryRouter } from "@solidjs/router" +import { createMemoryHistory, MemoryRouter, type BaseRouterProps } from "@solidjs/router" import { createEffect, createMemo, createResource, createSignal, onCleanup, onMount, Show } from "solid-js" import { render } from "solid-js/web" import pkg from "../../package.json" @@ -63,6 +63,7 @@ const [updaterState, setUpdaterState] = createSignal({ status: "di void window.api.updater.subscribe(setUpdaterState) const deepLinkEvent = "opencode:deep-link" +const lastActiveUrlKey = "opencode.desktop.last-active-url" const emitDeepLinks = (urls: string[]) => { if (urls.length === 0) return @@ -77,6 +78,30 @@ const listenForDeepLinks = () => { return window.api.onDeepLink((urls) => emitDeepLinks(urls)) } +function getLastActiveUrl() { + if (typeof localStorage !== "object") return "/" + try { + const value = localStorage.getItem(lastActiveUrlKey) + if (value?.startsWith("/") && !value.startsWith("//")) return value + } catch {} + return "/" +} + +function setLastActiveUrl(value: string) { + if (typeof localStorage !== "object") return + try { + localStorage.setItem(lastActiveUrlKey, value) + } catch {} +} + +function DesktopMemoryRouter(props: BaseRouterProps) { + const history = createMemoryHistory() + const initialUrl = getLastActiveUrl() + if (initialUrl !== "/") history.set({ value: initialUrl, replace: true, scroll: false }) + onCleanup(history.listen(setLastActiveUrl)) + return +} + const createPlatform = (): Platform => { const attachmentPaths = new WeakMap() const os = (() => { @@ -367,7 +392,7 @@ render(() => { {(key) => ( - + )}