diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index 966fb0c0bf3a..fd3d70a89215 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -90,11 +90,27 @@ function getLastActiveUrl(windowID: string) { if (typeof localStorage !== "object") return "/" try { const value = localStorage.getItem(windowLastActiveUrlKey(windowID)) - if (value?.startsWith("/") && !value.startsWith("//")) return value + if (value?.startsWith("/") && !value.startsWith("//") && !isStaleRemoteSessionUrl(value)) return value } catch {} return "/" } +function isStaleRemoteSessionUrl(value: string) { + const match = value.match(/^\/([^/]+)\/session(?:\/|$)/) + if (!match) return false + const directory = decodeRouteSegment(match[1]) + return directory?.startsWith("/") ?? false +} + +function decodeRouteSegment(value: string) { + try { + const binary = atob(value.replace(/-/g, "+").replace(/_/g, "/")) + return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0))) + } catch { + return undefined + } +} + function setLastActiveUrl(windowID: string, value: string) { if (typeof localStorage !== "object") return try {