fix(desktop): restore tabs after closing final window
This commit is contained in:
parent
fc29f99190
commit
c316b64cd6
4 changed files with 57 additions and 2 deletions
|
|
@ -208,4 +208,5 @@ describe("persist localStorage resilience", () => {
|
|||
test("server global target cannot collide when scope and key contain colons", () => {
|
||||
expect(Persist.serverGlobal("a:b" as ServerScope, "c")).not.toEqual(Persist.serverGlobal("a" as ServerScope, "b:c"))
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
|||
10
packages/desktop/src/main/windows-lifecycle.ts
Normal file
10
packages/desktop/src/main/windows-lifecycle.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export function nextWindowIDsAfterClosed(input: {
|
||||
ids: string[]
|
||||
closed: string
|
||||
remaining: number
|
||||
appQuitting: boolean
|
||||
}) {
|
||||
if (input.appQuitting) return input.ids
|
||||
if (input.remaining === 0) return input.ids
|
||||
return input.ids.filter((id) => id !== input.closed)
|
||||
}
|
||||
37
packages/desktop/src/main/windows.test.ts
Normal file
37
packages/desktop/src/main/windows.test.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { describe, expect, test } from "bun:test"
|
||||
import { nextWindowIDsAfterClosed } from "./windows-lifecycle"
|
||||
|
||||
describe("desktop window persistence", () => {
|
||||
test("keeps the last window id when the last window is closed", () => {
|
||||
expect(
|
||||
nextWindowIDsAfterClosed({
|
||||
ids: ["window-a"],
|
||||
closed: "window-a",
|
||||
remaining: 0,
|
||||
appQuitting: false,
|
||||
}),
|
||||
).toEqual(["window-a"])
|
||||
})
|
||||
|
||||
test("removes only non-final closed window ids", () => {
|
||||
expect(
|
||||
nextWindowIDsAfterClosed({
|
||||
ids: ["window-a", "window-b"],
|
||||
closed: "window-a",
|
||||
remaining: 1,
|
||||
appQuitting: false,
|
||||
}),
|
||||
).toEqual(["window-b"])
|
||||
})
|
||||
|
||||
test("keeps window ids while the app is quitting", () => {
|
||||
expect(
|
||||
nextWindowIDsAfterClosed({
|
||||
ids: ["window-a", "window-b"],
|
||||
closed: "window-a",
|
||||
remaining: 1,
|
||||
appQuitting: true,
|
||||
}),
|
||||
).toEqual(["window-a", "window-b"])
|
||||
})
|
||||
})
|
||||
|
|
@ -12,6 +12,7 @@ import { exportDebugLogs, write as writeLog } from "./logging"
|
|||
import { getStore } from "./store"
|
||||
import { PINCH_ZOOM_ENABLED_KEY, WINDOW_IDS_KEY } from "./store-keys"
|
||||
import { createUnresponsiveSampler } from "./unresponsive"
|
||||
import { nextWindowIDsAfterClosed } from "./windows-lifecycle"
|
||||
|
||||
const root = dirname(fileURLToPath(import.meta.url))
|
||||
const rendererRoot = join(root, "../renderer")
|
||||
|
|
@ -243,8 +244,14 @@ function persistWindowID(id: string) {
|
|||
}
|
||||
|
||||
function removeWindowID(id: string) {
|
||||
writeWindowIDs(readWindowIDs().filter((item) => item !== id))
|
||||
rmSync(join(app.getPath("userData"), windowStateFile(id)), { force: true })
|
||||
const next = nextWindowIDsAfterClosed({
|
||||
ids: readWindowIDs(),
|
||||
closed: id,
|
||||
remaining: windowsByID.size,
|
||||
appQuitting,
|
||||
})
|
||||
writeWindowIDs(next)
|
||||
if (!next.includes(id)) rmSync(join(app.getPath("userData"), windowStateFile(id)), { force: true })
|
||||
}
|
||||
|
||||
function windowStateFile(id: string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue