feat: add multi-session desktop workspace
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import type { UiState, WorkspaceState } from "./types";
|
||||
|
||||
export const selectedPathKey = "pi-status-ui.selected-worktree";
|
||||
export const uiScaleKey = "pi-status-ui.interface-scale";
|
||||
|
||||
export function presentationState(state: WorkspaceState): UiState {
|
||||
const drafts: Record<string, string> = {};
|
||||
const scroll: UiState["scroll"] = {};
|
||||
const lastSeen: UiState["lastSeen"] = {};
|
||||
for (const [id, runtime] of Object.entries(state.runtimesById)) {
|
||||
if (runtime.draft) drafts[id] = runtime.draft;
|
||||
scroll[id] = runtime.scroll;
|
||||
if (!runtime.unread && state.bridge.instanceId)
|
||||
lastSeen[id] = {
|
||||
bridgeInstanceId: state.bridge.instanceId,
|
||||
seq: state.bridge.latestSeq,
|
||||
lastActivity: runtime.summary.lastActivity,
|
||||
};
|
||||
}
|
||||
return {
|
||||
version: 1,
|
||||
directoryOrder: state.directoryOrder,
|
||||
runtimeOrderByDirectory: state.runtimeOrderByDirectory,
|
||||
selectedRuntimeId: state.selectedRuntimeId,
|
||||
drafts,
|
||||
scroll,
|
||||
lastSeen,
|
||||
workspaceCursor: state.bridge.instanceId
|
||||
? {
|
||||
bridgeInstanceId: state.bridge.instanceId,
|
||||
seq: state.bridge.latestSeq,
|
||||
}
|
||||
: undefined,
|
||||
interfaceScale: state.interfaceScale,
|
||||
dismissedCollisionWarning: state.dismissedCollisionWarning,
|
||||
};
|
||||
}
|
||||
|
||||
export async function loadPresentation() {
|
||||
return invoke<UiState>("load_ui_state");
|
||||
}
|
||||
export async function savePresentation(state: UiState) {
|
||||
await invoke("save_ui_state", { state });
|
||||
}
|
||||
export function legacyPreferences(storage: Pick<Storage, "getItem">) {
|
||||
const path = storage.getItem(selectedPathKey) ?? undefined;
|
||||
const raw = Number(storage.getItem(uiScaleKey));
|
||||
const scale =
|
||||
Number.isFinite(raw) && raw >= 0.9 && raw <= 1.4 ? raw : undefined;
|
||||
return { path, scale };
|
||||
}
|
||||
export function removeLegacyPreferences(storage: Pick<Storage, "removeItem">) {
|
||||
storage.removeItem(selectedPathKey);
|
||||
storage.removeItem(uiScaleKey);
|
||||
}
|
||||
Reference in New Issue
Block a user