feat: add desktop storage cleanup controls

This commit is contained in:
2026-06-18 23:50:56 +08:00
parent 889a575188
commit d8195bc935
7 changed files with 976 additions and 1 deletions
@@ -19,6 +19,11 @@ export interface SessionHandleSnapshot {
partition: string
}
export interface PersistedSessionPartitionSnapshot {
accountId: string
partition: string
}
const registry = new Map<string, SessionHandle>()
const sessionsWithUA = new WeakSet<Session>()
let persistedPartitionsCache: Record<string, string> | null = null
@@ -58,6 +63,13 @@ export function getPersistedPartition(accountId: string): string | null {
return persistedPartitionFor(accountId)
}
export function listPersistedSessionPartitions(): PersistedSessionPartitionSnapshot[] {
return Object.entries(readPersistedPartitions()).map(([accountId, partition]) => ({
accountId,
partition,
}))
}
function rememberPersistedPartition(accountId: string, partition: string): void {
const current = readPersistedPartitions()
if (current[accountId] === partition) {
@@ -83,6 +95,18 @@ function forgetPersistedPartition(accountId: string): string | null {
return partition
}
export function forgetPersistedSessionPartition(accountId: string, partition: string): boolean {
const current = readPersistedPartitions()
if (current[accountId] !== partition) {
return false
}
const next = { ...current }
delete next[accountId]
writePersistedPartitions(next)
return true
}
function partitionFor(accountId: string): string {
return `persist:acc-${accountId}`
}