Skip to content
Open
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
18 changes: 17 additions & 1 deletion packages/desktop/src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading