@fungi.computer/tourtois 0.15.1 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AppPane.d.ts +6 -1
- package/dist/AppPane.js +10 -7
- package/dist/AppWorkbench.js +53 -5
- package/dist/ModelKeys.d.ts +1 -1
- package/dist/desktop/Desktop.js +1 -1
- package/dist/desktop/welcome.css +3 -2
- package/dist/desktop-api.d.ts +1 -1
- package/dist/desktop-layout.d.ts +4 -4
- package/dist/oyster-setup.d.ts +4 -4
- package/dist/window-session.d.ts +80 -0
- package/dist/window-session.js +197 -0
- package/package.json +12 -5
package/dist/AppPane.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type WindowPlacement } from "./window-session.js";
|
|
1
2
|
import { WindowHeader } from "@fungi.computer/caps/components/window";
|
|
2
3
|
import { type AppNavigationState, type AppStatusAction } from "@fungi.computer/agar";
|
|
3
4
|
import { type ComponentProps } from "react";
|
|
@@ -15,13 +16,17 @@ export declare function FocusedWindowControls({ app, onOpenSettings, onOpenPermi
|
|
|
15
16
|
* has published no history), so every title keeps its place.
|
|
16
17
|
*/
|
|
17
18
|
export declare function historyProps(navigation: AppNavigationState | null, title: string, onBack: () => void, onForward: () => void): Pick<ComponentProps<typeof WindowHeader>, "back" | "forward">;
|
|
18
|
-
export declare function AppPane({ projection, nextLaunch, icon, manager, onError, index, focusWindow, afterHide, onBack, onForward, onSelectComputer, onChooseComputer, }: {
|
|
19
|
+
export declare function AppPane({ projection, nextLaunch, icon, manager, onError, index, seedFrame, onFrame, focusWindow, afterHide, onBack, onForward, onSelectComputer, onChooseComputer, }: {
|
|
19
20
|
projection: AppWindowProjection;
|
|
20
21
|
nextLaunch?: AppLaunchDescriptor | null;
|
|
21
22
|
icon: string | null | undefined;
|
|
22
23
|
manager: ReturnType<typeof createAppWindowManager>;
|
|
23
24
|
onError: (message: string) => void;
|
|
24
25
|
index: number;
|
|
26
|
+
/** Where a restored window last sat; absent for a new window. */
|
|
27
|
+
seedFrame?: WindowPlacement | undefined;
|
|
28
|
+
/** Reports where the window floats, so the session can restore it. */
|
|
29
|
+
onFrame?: ((windowId: string, frame: WindowPlacement) => void) | undefined;
|
|
25
30
|
focusWindow: (id: string) => void;
|
|
26
31
|
afterHide: (id: string) => void;
|
|
27
32
|
onBack: (id: string) => void;
|
package/dist/AppPane.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { cascade } from "./window-session.js";
|
|
2
3
|
import { LoadingState } from "@fungi.computer/caps/blocks/loading-state";
|
|
3
4
|
import { ResultState } from "@fungi.computer/caps/blocks/result-state";
|
|
4
5
|
import { Button } from "@fungi.computer/caps/components/button";
|
|
@@ -141,7 +142,7 @@ export function historyProps(navigation, title, onBack, onForward) {
|
|
|
141
142
|
},
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
|
-
export function AppPane({ projection, nextLaunch, icon, manager, onError, index, focusWindow, afterHide, onBack, onForward, onSelectComputer, onChooseComputer, }) {
|
|
145
|
+
export function AppPane({ projection, nextLaunch, icon, manager, onError, index, seedFrame, onFrame, focusWindow, afterHide, onBack, onForward, onSelectComputer, onChooseComputer, }) {
|
|
145
146
|
const phone = usePhone();
|
|
146
147
|
const containerRef = useRef(null);
|
|
147
148
|
const popover = useLayer("popover");
|
|
@@ -165,15 +166,17 @@ export function AppPane({ projection, nextLaunch, icon, manager, onError, index,
|
|
|
165
166
|
}, [projection.status]);
|
|
166
167
|
const binding = useMaosaicoItem({
|
|
167
168
|
id: projection.windowId,
|
|
168
|
-
frame:
|
|
169
|
-
x: 24 + index * 40,
|
|
170
|
-
y: 24 + index * 32,
|
|
171
|
-
width: 600,
|
|
172
|
-
height: 480,
|
|
173
|
-
},
|
|
169
|
+
frame: seedFrame ?? cascade(index),
|
|
174
170
|
minima: { width: 320, height: 360 },
|
|
175
171
|
}, { participating: projection.status !== "minimized" });
|
|
176
172
|
const layout = useMaosaicoLayout();
|
|
173
|
+
// The session keeps where each window floats; a tiled arrangement is not it.
|
|
174
|
+
const floating = layout.mode === "floating";
|
|
175
|
+
const { x, y, width, height } = binding.frame;
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (floating)
|
|
178
|
+
onFrame?.(projection.windowId, { x, y, width, height });
|
|
179
|
+
}, [floating, onFrame, projection.windowId, x, y, width, height]);
|
|
177
180
|
const element = useWindowMotion(binding, layout.interacting, layout.bounds);
|
|
178
181
|
const zoomed = layout.zoomedId === projection.windowId;
|
|
179
182
|
const zoom = () => {
|
package/dist/AppWorkbench.js
CHANGED
|
@@ -27,6 +27,7 @@ import { OwnSprite } from "./member-avatar.js";
|
|
|
27
27
|
import { Desktop } from "./desktop/Desktop.js";
|
|
28
28
|
import { useAppOpenUrlHandoff } from "./useAppOpenUrlHandoff.js";
|
|
29
29
|
import { useAppWindowManager } from "./useAppWindowManager.js";
|
|
30
|
+
import { useWindowSession } from "./window-session.js";
|
|
30
31
|
import { useDirectoryCommands } from "./useDirectoryCommands.js";
|
|
31
32
|
const emptyAppBarLabel = (loading, failed) => {
|
|
32
33
|
if (loading)
|
|
@@ -81,6 +82,8 @@ function phoneShowDesktop(phone, covered, host, onFailure) {
|
|
|
81
82
|
export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialComputerId, computers, computersUnavailable, extraPanes, initialFocusId, onLayoutChange, extraLaunchers = [], settingsLaunchers = [], settingsSections, systemMenuItems, directoryReader, takeAppOpenRequest, platform, desktopStorage, desktopMethods, gills, }) {
|
|
82
83
|
const setSettingsLocation = platform.openSettings;
|
|
83
84
|
const [appDialOpen, setAppDialOpen] = useState(false);
|
|
85
|
+
const appDialOpenRef = useRef(appDialOpen);
|
|
86
|
+
appDialOpenRef.current = appDialOpen;
|
|
84
87
|
// The Layout menu's "Arrange desktop" command and the desktop's own
|
|
85
88
|
// controls share one state: this is their common ancestor.
|
|
86
89
|
const [desktopEditing, setDesktopEditing] = useState(false);
|
|
@@ -170,6 +173,10 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
170
173
|
const focusWindow = useCallback((id) => {
|
|
171
174
|
focus(id);
|
|
172
175
|
requestAnimationFrame(() => {
|
|
176
|
+
// Focus the person moved into an open App dial since this request must
|
|
177
|
+
// stay there; landing in a window would dismiss the dial.
|
|
178
|
+
if (appDialContainer?.contains(document.activeElement))
|
|
179
|
+
return;
|
|
173
180
|
const pane = [
|
|
174
181
|
...(paneLayerRef.current?.querySelectorAll("[data-window-id]") ?? []),
|
|
175
182
|
].find((candidate) => candidate.dataset.windowId === id);
|
|
@@ -177,7 +184,7 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
177
184
|
?.querySelector("[data-caps-window-handle]")
|
|
178
185
|
?.focus();
|
|
179
186
|
});
|
|
180
|
-
}, [focus, paneLayerRef]);
|
|
187
|
+
}, [appDialContainer, focus, paneLayerRef]);
|
|
181
188
|
const afterHide = (id) => {
|
|
182
189
|
if (layout.zoomedId === id)
|
|
183
190
|
layout.zoom(null);
|
|
@@ -453,6 +460,39 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
453
460
|
});
|
|
454
461
|
}, [appWindows, listedApps, initialComputerId, computers]);
|
|
455
462
|
const directory = useMemo(() => listedApps ?? [], [listedApps]);
|
|
463
|
+
const windowSession = useWindowSession({
|
|
464
|
+
storage: desktopStorage,
|
|
465
|
+
manager: appWindows,
|
|
466
|
+
apps: listedApps,
|
|
467
|
+
launchFor: (app) => launchFor(app),
|
|
468
|
+
snapshot: {
|
|
469
|
+
tiled: mode === "tiled",
|
|
470
|
+
activeWindowId: activeId,
|
|
471
|
+
windows: appProjection.windows.map((item) => ({
|
|
472
|
+
windowId: item.windowId,
|
|
473
|
+
surfaceId: item.launch.surfaceId,
|
|
474
|
+
status: item.status,
|
|
475
|
+
})),
|
|
476
|
+
},
|
|
477
|
+
interacting: layout.interacting,
|
|
478
|
+
phone,
|
|
479
|
+
onTiledChange: onLayoutChange,
|
|
480
|
+
focusWindow,
|
|
481
|
+
onError: setAppStatus,
|
|
482
|
+
});
|
|
483
|
+
/** An App that is already open comes forward instead of opening twice. */
|
|
484
|
+
const bringForward = (windowId) => {
|
|
485
|
+
void appWindows
|
|
486
|
+
.restore(windowId)
|
|
487
|
+
.then(() => {
|
|
488
|
+
layout.zoom(null);
|
|
489
|
+
focusWindow(windowId);
|
|
490
|
+
})
|
|
491
|
+
.catch((cause) => {
|
|
492
|
+
console.error("App workbench operation failed", cause);
|
|
493
|
+
setAppStatus("App could not be restored.");
|
|
494
|
+
});
|
|
495
|
+
};
|
|
456
496
|
const launchApp = (installation, requestedLaunch) => {
|
|
457
497
|
const windowId = "app:" + installation.surfaceId;
|
|
458
498
|
const launch = requestedLaunch ?? launchFor(installation);
|
|
@@ -505,11 +545,14 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
505
545
|
label: installation.displayName ?? "App",
|
|
506
546
|
icon: _jsx(AppIcon, { roles: installation.roles, icon: installation.icon }),
|
|
507
547
|
onSelect: () => {
|
|
508
|
-
|
|
548
|
+
if (appProjection.windows.some((item) => item.windowId === windowId))
|
|
549
|
+
bringForward(windowId);
|
|
550
|
+
else
|
|
551
|
+
launchApp(installation);
|
|
509
552
|
},
|
|
510
553
|
};
|
|
511
554
|
});
|
|
512
|
-
const appLaunchers = launchableItems
|
|
555
|
+
const appLaunchers = [...launchableItems];
|
|
513
556
|
appLaunchers.push(...settingsLaunchers.map((launcher) => {
|
|
514
557
|
const item = {
|
|
515
558
|
id: launcher.id,
|
|
@@ -616,7 +659,7 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
616
659
|
void appsQuery.refetch();
|
|
617
660
|
} }) }), _jsxs(MaosaicoRegion, { layer: "windows", style: { height: "100%", pointerEvents: "none" }, ref: paneLayerRef, className: "tourtois-pane-layer", "data-layout-mode": mode, "data-desktop": visibility, children: [appProjection.windows.map((projection, index) => {
|
|
618
661
|
const app = directory.find((item) => item.surfaceId === projection.launch.surfaceId);
|
|
619
|
-
return (_jsx(AppPane, { index: index, focusWindow: focusWindow, afterHide: afterHide, onBack: goBack, onForward: goForward, manager: appWindows, projection: projection, nextLaunch: app ? launchFor(app, projection.launch) : null, icon: app?.icon, onError: setAppStatus, onSelectComputer: (windowId, computerId) => {
|
|
662
|
+
return (_jsx(AppPane, { index: index, seedFrame: windowSession.seedFrame(projection.windowId), onFrame: windowSession.reportFrame, focusWindow: focusWindow, afterHide: afterHide, onBack: goBack, onForward: goForward, manager: appWindows, projection: projection, nextLaunch: app ? launchFor(app, projection.launch) : null, icon: app?.icon, onError: setAppStatus, onSelectComputer: (windowId, computerId) => {
|
|
620
663
|
void selectWindowComputer(windowId, computerId);
|
|
621
664
|
}, onChooseComputer: openAppPermissions }, projection.windowId));
|
|
622
665
|
}), extraPanes?.({ activeId, order, focus }), layout.snapPreview && (_jsx(WindowSnapPreview, { "data-snap-side": layout.snapPreview.side, style: {
|
|
@@ -633,5 +676,10 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
633
676
|
name: app.displayName ?? "App",
|
|
634
677
|
roles: app.roles,
|
|
635
678
|
surfaceId: app.surfaceId,
|
|
636
|
-
})), onStatus: setAppStatus, finalFocus: () =>
|
|
679
|
+
})), onStatus: setAppStatus, finalFocus: () =>
|
|
680
|
+
// Ctrl K then O opens the App dial as this dialog closes; focus goes
|
|
681
|
+
// to its search so typing filters, not back to the launcher button.
|
|
682
|
+
appDialOpenRef.current
|
|
683
|
+
? document.querySelector(".caps-app-bar-launchers input[type='search']")
|
|
684
|
+
: document.querySelector(".caps-app-bar-launcher-button") })] }));
|
|
637
685
|
}
|
package/dist/ModelKeys.d.ts
CHANGED
|
@@ -21,9 +21,9 @@ export declare const modelKeysViewSchema: z.ZodObject<{
|
|
|
21
21
|
validatedAt: z.ZodNumber;
|
|
22
22
|
}, z.core.$strict>>;
|
|
23
23
|
models: z.ZodEnum<{
|
|
24
|
-
missing: "missing";
|
|
25
24
|
ready: "ready";
|
|
26
25
|
unknown: "unknown";
|
|
26
|
+
missing: "missing";
|
|
27
27
|
}>;
|
|
28
28
|
catalogs: z.ZodRecord<z.ZodEnum<{
|
|
29
29
|
"cloudflare-workers-ai": "cloudflare-workers-ai";
|
package/dist/desktop/Desktop.js
CHANGED
|
@@ -197,7 +197,7 @@ function ArrangedDesktop({ owner, ...props }) {
|
|
|
197
197
|
const height = Math.max(0, ...frames.map((frame) => frame.y + frame.height));
|
|
198
198
|
// Phones and arranging fit each card to its content. Otherwise cards that
|
|
199
199
|
// share a row reach the tallest neighbour's bottom, so Inbox matches Launcher.
|
|
200
|
-
const evenRows = !props.phone
|
|
200
|
+
const evenRows = !props.phone;
|
|
201
201
|
const evenRowHeight = (id) => {
|
|
202
202
|
const frame = binding.frames.get(id);
|
|
203
203
|
const cell = placements.find((entry) => entry.id === id);
|
package/dist/desktop/welcome.css
CHANGED
|
@@ -75,9 +75,10 @@
|
|
|
75
75
|
.tourtois-launcher-more {
|
|
76
76
|
display: flex;
|
|
77
77
|
justify-content: flex-end;
|
|
78
|
-
/* Keep the keyboard outline inside the Gill body's scroll boundary
|
|
78
|
+
/* Keep the keyboard outline inside the Gill body's scroll boundary: the
|
|
79
|
+
button below pulls 0.75rem outward, so reserve that plus the outline. */
|
|
79
80
|
padding: var(--spacing-sm);
|
|
80
|
-
padding-inline-end: 0;
|
|
81
|
+
padding-inline-end: calc(0.75rem + var(--spacing-sm));
|
|
81
82
|
margin-block-start: var(--spacing-sm);
|
|
82
83
|
}
|
|
83
84
|
/* The ghost button's text, not its padding, lines up with Edit launcher. */
|
package/dist/desktop-api.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export declare const desktopSnapshotSchema: z.ZodObject<{
|
|
|
23
23
|
}, z.core.$strict>;
|
|
24
24
|
source: z.ZodEnum<{
|
|
25
25
|
none: "none";
|
|
26
|
-
member: "member";
|
|
27
26
|
team: "team";
|
|
27
|
+
member: "member";
|
|
28
28
|
}>;
|
|
29
29
|
memberRevision: z.ZodNullable<z.ZodNumber>;
|
|
30
30
|
teamRevision: z.ZodNullable<z.ZodNumber>;
|
package/dist/desktop-layout.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ export type DesktopGill = Readonly<{
|
|
|
32
32
|
}>;
|
|
33
33
|
export declare const desktopArrangeSchema: z.ZodObject<{
|
|
34
34
|
scope: z.ZodEnum<{
|
|
35
|
-
member: "member";
|
|
36
35
|
team: "team";
|
|
36
|
+
member: "member";
|
|
37
37
|
}>;
|
|
38
38
|
basedOn: z.ZodNullable<z.ZodNumber>;
|
|
39
39
|
ops: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -88,15 +88,15 @@ export declare const desktopArrangeResultSchema: z.ZodDiscriminatedUnion<[z.ZodO
|
|
|
88
88
|
code: z.ZodEnum<{
|
|
89
89
|
invalid: "invalid";
|
|
90
90
|
owner_required: "owner_required";
|
|
91
|
+
too_large: "too_large";
|
|
92
|
+
quota_exceeded: "quota_exceeded";
|
|
93
|
+
conflict: "conflict";
|
|
91
94
|
unknown_gill: "unknown_gill";
|
|
92
95
|
unknown_app: "unknown_app";
|
|
93
96
|
size_not_allowed: "size_not_allowed";
|
|
94
97
|
unknown_item: "unknown_item";
|
|
95
98
|
last_launcher: "last_launcher";
|
|
96
99
|
too_many: "too_many";
|
|
97
|
-
conflict: "conflict";
|
|
98
|
-
too_large: "too_large";
|
|
99
|
-
quota_exceeded: "quota_exceeded";
|
|
100
100
|
params_invalid: "params_invalid";
|
|
101
101
|
}>;
|
|
102
102
|
}, z.core.$strict>], "kind">;
|
package/dist/oyster-setup.d.ts
CHANGED
|
@@ -5,24 +5,24 @@ import type { SettingsLocation } from "./settings-routes.js";
|
|
|
5
5
|
/** The owner-direct `/api/setup` reply, decoded before any App sees it. */
|
|
6
6
|
export declare const oysterSetupSchema: z.ZodObject<{
|
|
7
7
|
models: z.ZodEnum<{
|
|
8
|
-
missing: "missing";
|
|
9
8
|
ready: "ready";
|
|
10
9
|
unknown: "unknown";
|
|
10
|
+
missing: "missing";
|
|
11
11
|
}>;
|
|
12
12
|
media: z.ZodEnum<{
|
|
13
|
-
missing: "missing";
|
|
14
13
|
ready: "ready";
|
|
15
14
|
unknown: "unknown";
|
|
15
|
+
missing: "missing";
|
|
16
16
|
}>;
|
|
17
17
|
git: z.ZodEnum<{
|
|
18
|
-
missing: "missing";
|
|
19
18
|
ready: "ready";
|
|
20
19
|
unknown: "unknown";
|
|
20
|
+
missing: "missing";
|
|
21
21
|
}>;
|
|
22
22
|
terminal: z.ZodEnum<{
|
|
23
|
-
missing: "missing";
|
|
24
23
|
ready: "ready";
|
|
25
24
|
unknown: "unknown";
|
|
25
|
+
missing: "missing";
|
|
26
26
|
"exec-only": "exec-only";
|
|
27
27
|
}>;
|
|
28
28
|
terminalReason: z.ZodOptional<z.ZodString>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AppStorage } from "@fungi.computer/agar/storage";
|
|
3
|
+
import type { AppDirectoryApp } from "./app-launch.js";
|
|
4
|
+
import type { AppLaunchDescriptor, AppWindowManager } from "./app-windows.js";
|
|
5
|
+
/** The member's own storage key for the windows they had open. */
|
|
6
|
+
export declare const windowSessionKey = "windows";
|
|
7
|
+
declare const frameSchema: z.ZodObject<{
|
|
8
|
+
x: z.ZodNumber;
|
|
9
|
+
y: z.ZodNumber;
|
|
10
|
+
width: z.ZodNumber;
|
|
11
|
+
height: z.ZodNumber;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const windowSessionSchema: z.ZodObject<{
|
|
14
|
+
tiled: z.ZodBoolean;
|
|
15
|
+
active: z.ZodNullable<z.ZodString>;
|
|
16
|
+
windows: z.ZodArray<z.ZodObject<{
|
|
17
|
+
surfaceId: z.ZodString;
|
|
18
|
+
frame: z.ZodObject<{
|
|
19
|
+
x: z.ZodNumber;
|
|
20
|
+
y: z.ZodNumber;
|
|
21
|
+
width: z.ZodNumber;
|
|
22
|
+
height: z.ZodNumber;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
minimized: z.ZodDefault<z.ZodBoolean>;
|
|
25
|
+
}, z.core.$strip>>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
export type WindowSession = z.infer<typeof windowSessionSchema>;
|
|
28
|
+
export type WindowPlacement = z.infer<typeof frameSchema>;
|
|
29
|
+
/** What the shell reads from layout and windows to describe the session. */
|
|
30
|
+
export type WindowSessionSnapshot = Readonly<{
|
|
31
|
+
tiled: boolean;
|
|
32
|
+
activeWindowId: string | null;
|
|
33
|
+
windows: readonly Readonly<{
|
|
34
|
+
windowId: string;
|
|
35
|
+
surfaceId: string;
|
|
36
|
+
status: string;
|
|
37
|
+
}>[];
|
|
38
|
+
frames: ReadonlyMap<string, WindowPlacement>;
|
|
39
|
+
}>;
|
|
40
|
+
/** Where a new window floats until the person moves it. */
|
|
41
|
+
export declare const cascade: (index: number) => WindowPlacement;
|
|
42
|
+
/** Pure projection of the live desktop into the stored shape. */
|
|
43
|
+
export declare function windowSessionFrom(snapshot: WindowSessionSnapshot): WindowSession;
|
|
44
|
+
/** Launches for the stored windows whose Apps are still installed, in order. */
|
|
45
|
+
export declare function restorableLaunches<App extends Readonly<{
|
|
46
|
+
surfaceId: string;
|
|
47
|
+
roles: readonly string[];
|
|
48
|
+
}>, Launch>(session: WindowSession, apps: readonly App[], launchFor: (app: App) => Launch | null): readonly Readonly<{
|
|
49
|
+
launch: Launch;
|
|
50
|
+
frame: WindowPlacement;
|
|
51
|
+
minimized: boolean;
|
|
52
|
+
}>[];
|
|
53
|
+
/** Reads and writes the session through the member's storage layer. */
|
|
54
|
+
export declare function createWindowSessionStore(storage: AppStorage): {
|
|
55
|
+
load(): Promise<WindowSession | null>;
|
|
56
|
+
save(session: WindowSession): Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
export type WindowSessionInput = Readonly<{
|
|
59
|
+
storage: AppStorage;
|
|
60
|
+
manager: AppWindowManager;
|
|
61
|
+
apps: readonly AppDirectoryApp[] | undefined;
|
|
62
|
+
launchFor: (app: AppDirectoryApp) => AppLaunchDescriptor | null;
|
|
63
|
+
snapshot: Omit<WindowSessionSnapshot, "frames">;
|
|
64
|
+
interacting: boolean;
|
|
65
|
+
/** A phone is always tiled, so it neither reads nor overwrites the choice. */
|
|
66
|
+
phone: boolean;
|
|
67
|
+
onTiledChange: ((tiled: boolean) => void) | undefined;
|
|
68
|
+
focusWindow: (windowId: string) => void;
|
|
69
|
+
/** Shown to the person as a toast; the session is never lost silently. */
|
|
70
|
+
onError: (message: string) => void;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Restore the member's windows once the App directory is known, then keep
|
|
74
|
+
* the stored session current. Frames seed panes as they register.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useWindowSession(input: WindowSessionInput): {
|
|
77
|
+
reportFrame: (windowId: string, frame: WindowPlacement) => void;
|
|
78
|
+
seedFrame: (windowId: string) => WindowPlacement | undefined;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { AppStorageError } from "@fungi.computer/agar/storage";
|
|
4
|
+
/** The member's own storage key for the windows they had open. */
|
|
5
|
+
export const windowSessionKey = "windows";
|
|
6
|
+
const frameSchema = z.object({
|
|
7
|
+
x: z.number(),
|
|
8
|
+
y: z.number(),
|
|
9
|
+
width: z.number().positive(),
|
|
10
|
+
height: z.number().positive(),
|
|
11
|
+
});
|
|
12
|
+
export const windowSessionSchema = z.object({
|
|
13
|
+
tiled: z.boolean(),
|
|
14
|
+
/** The focused window's surface, raised last so it stays on top. */
|
|
15
|
+
active: z.string().nullable(),
|
|
16
|
+
/** Open windows in tiling order, minimized ones included. */
|
|
17
|
+
windows: z
|
|
18
|
+
.array(z.object({
|
|
19
|
+
surfaceId: z.string().min(1),
|
|
20
|
+
frame: frameSchema,
|
|
21
|
+
minimized: z.boolean().default(false),
|
|
22
|
+
}))
|
|
23
|
+
.max(16),
|
|
24
|
+
});
|
|
25
|
+
const windowIdFor = (surfaceId) => "app:" + surfaceId;
|
|
26
|
+
/** Where a new window floats until the person moves it. */
|
|
27
|
+
export const cascade = (index) => ({
|
|
28
|
+
x: 24 + index * 40,
|
|
29
|
+
y: 24 + index * 32,
|
|
30
|
+
width: 600,
|
|
31
|
+
height: 480,
|
|
32
|
+
});
|
|
33
|
+
/** Pure projection of the live desktop into the stored shape. */
|
|
34
|
+
export function windowSessionFrom(snapshot) {
|
|
35
|
+
const windows = snapshot.windows.map((item, index) => ({
|
|
36
|
+
surfaceId: item.surfaceId,
|
|
37
|
+
frame: { ...(snapshot.frames.get(item.windowId) ?? cascade(index)) },
|
|
38
|
+
minimized: item.status === "minimized",
|
|
39
|
+
}));
|
|
40
|
+
const active = snapshot.windows.find((item) => item.windowId === snapshot.activeWindowId);
|
|
41
|
+
return windowSessionSchema.parse({
|
|
42
|
+
tiled: snapshot.tiled,
|
|
43
|
+
active: active &&
|
|
44
|
+
windows.some((item) => item.surfaceId === active.surfaceId && !item.minimized)
|
|
45
|
+
? active.surfaceId
|
|
46
|
+
: null,
|
|
47
|
+
windows: windows.slice(0, 16),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Launches for the stored windows whose Apps are still installed, in order. */
|
|
51
|
+
export function restorableLaunches(session, apps, launchFor) {
|
|
52
|
+
return session.windows.flatMap((saved) => {
|
|
53
|
+
const app = apps.find((item) => item.surfaceId === saved.surfaceId && !item.roles.includes("dashboard"));
|
|
54
|
+
const launch = app ? launchFor(app) : null;
|
|
55
|
+
return launch
|
|
56
|
+
? [{ launch, frame: saved.frame, minimized: saved.minimized }]
|
|
57
|
+
: [];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Reads and writes the session through the member's storage layer. */
|
|
61
|
+
export function createWindowSessionStore(storage) {
|
|
62
|
+
let revision = null;
|
|
63
|
+
let queue = Promise.resolve();
|
|
64
|
+
return {
|
|
65
|
+
async load() {
|
|
66
|
+
const resolved = await storage.read(windowSessionKey);
|
|
67
|
+
revision = resolved.member?.revision ?? null;
|
|
68
|
+
const parsed = windowSessionSchema.safeParse(resolved.member?.value);
|
|
69
|
+
return parsed.success ? parsed.data : null;
|
|
70
|
+
},
|
|
71
|
+
save(session) {
|
|
72
|
+
const attempt = async () => {
|
|
73
|
+
const result = await storage.write({
|
|
74
|
+
key: windowSessionKey,
|
|
75
|
+
scope: "member",
|
|
76
|
+
basedOn: revision,
|
|
77
|
+
value: session,
|
|
78
|
+
});
|
|
79
|
+
revision = result.revision;
|
|
80
|
+
};
|
|
81
|
+
const write = async () => {
|
|
82
|
+
try {
|
|
83
|
+
await attempt();
|
|
84
|
+
}
|
|
85
|
+
catch (cause) {
|
|
86
|
+
// Another tab saved first. This tab's state is the current one, so
|
|
87
|
+
// take the stored revision and save over it once; anything else is a
|
|
88
|
+
// real failure.
|
|
89
|
+
if (!(cause instanceof AppStorageError) || cause.code !== "conflict")
|
|
90
|
+
throw cause;
|
|
91
|
+
const resolved = await storage.read(windowSessionKey);
|
|
92
|
+
revision = resolved.member?.revision ?? null;
|
|
93
|
+
await attempt();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// Each save waits for the previous one to settle, then runs; the caller
|
|
97
|
+
// of a failed save receives that failure.
|
|
98
|
+
const saving = queue.then(write, write);
|
|
99
|
+
queue = saving;
|
|
100
|
+
return saving;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Restore the member's windows once the App directory is known, then keep
|
|
106
|
+
* the stored session current. Frames seed panes as they register.
|
|
107
|
+
*/
|
|
108
|
+
export function useWindowSession(input) {
|
|
109
|
+
const latest = useRef(input);
|
|
110
|
+
latest.current = input;
|
|
111
|
+
const seeds = useRef(new Map());
|
|
112
|
+
const [store] = useState(() => createWindowSessionStore(input.storage));
|
|
113
|
+
const [restored, setRestored] = useState(false);
|
|
114
|
+
const started = useRef(false);
|
|
115
|
+
const preferredTiled = useRef(true);
|
|
116
|
+
const ready = input.apps !== undefined;
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (!ready || started.current)
|
|
119
|
+
return;
|
|
120
|
+
started.current = true;
|
|
121
|
+
void (async () => {
|
|
122
|
+
try {
|
|
123
|
+
const session = await store.load();
|
|
124
|
+
const current = latest.current;
|
|
125
|
+
if (!session || !current.apps)
|
|
126
|
+
return;
|
|
127
|
+
preferredTiled.current = session.tiled;
|
|
128
|
+
current.onTiledChange?.(session.tiled);
|
|
129
|
+
const launches = restorableLaunches(session, current.apps, current.launchFor);
|
|
130
|
+
for (const { launch, frame } of launches)
|
|
131
|
+
seeds.current.set(launch.windowId, frame);
|
|
132
|
+
for (const { launch, minimized } of launches) {
|
|
133
|
+
if (current.manager
|
|
134
|
+
.read()
|
|
135
|
+
.windows.some((item) => item.windowId === launch.windowId))
|
|
136
|
+
continue;
|
|
137
|
+
await current.manager.open(launch);
|
|
138
|
+
if (minimized)
|
|
139
|
+
await current.manager.minimize(launch.windowId);
|
|
140
|
+
}
|
|
141
|
+
const active = session.active && windowIdFor(session.active);
|
|
142
|
+
if (active &&
|
|
143
|
+
current.manager.read().windows.some((w) => w.windowId === active))
|
|
144
|
+
latest.current.focusWindow(active);
|
|
145
|
+
}
|
|
146
|
+
catch (cause) {
|
|
147
|
+
console.error("Open windows could not be restored", cause);
|
|
148
|
+
latest.current.onError("Your open windows could not be restored.");
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
setRestored(true);
|
|
152
|
+
}
|
|
153
|
+
})();
|
|
154
|
+
}, [ready, store]);
|
|
155
|
+
const { snapshot, interacting, phone } = input;
|
|
156
|
+
// Where each window floats: restored positions, then whatever panes report.
|
|
157
|
+
const [reported, setReported] = useState(new Map());
|
|
158
|
+
const reportFrame = useCallback((windowId, frame) => {
|
|
159
|
+
setReported((current) => {
|
|
160
|
+
const known = current.get(windowId);
|
|
161
|
+
if (known?.x === frame.x &&
|
|
162
|
+
known.y === frame.y &&
|
|
163
|
+
known.width === frame.width &&
|
|
164
|
+
known.height === frame.height)
|
|
165
|
+
return current;
|
|
166
|
+
return new Map(current).set(windowId, frame);
|
|
167
|
+
});
|
|
168
|
+
}, []);
|
|
169
|
+
const session = windowSessionFrom({
|
|
170
|
+
...snapshot,
|
|
171
|
+
frames: new Map([...seeds.current, ...reported]),
|
|
172
|
+
tiled: phone ? preferredTiled.current : snapshot.tiled,
|
|
173
|
+
});
|
|
174
|
+
const body = JSON.stringify(session);
|
|
175
|
+
const pending = useRef(session);
|
|
176
|
+
pending.current = session;
|
|
177
|
+
const saved = useRef(null);
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
if (!restored || interacting || saved.current === body)
|
|
180
|
+
return;
|
|
181
|
+
const timer = setTimeout(() => {
|
|
182
|
+
saved.current = body;
|
|
183
|
+
void store.save(pending.current).catch((cause) => {
|
|
184
|
+
saved.current = null;
|
|
185
|
+
console.error("Open windows were not saved", cause);
|
|
186
|
+
latest.current.onError("Your open windows could not be saved.");
|
|
187
|
+
});
|
|
188
|
+
}, 400);
|
|
189
|
+
return () => {
|
|
190
|
+
clearTimeout(timer);
|
|
191
|
+
};
|
|
192
|
+
}, [body, interacting, restored, store]);
|
|
193
|
+
return {
|
|
194
|
+
reportFrame,
|
|
195
|
+
seedFrame: (windowId) => seeds.current.get(windowId),
|
|
196
|
+
};
|
|
197
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"author": "Levi <levi@technomancy.dev>",
|
|
5
5
|
"description": "Tourtois: the trusted desktop shell for Oyster and Fungi, with host-supplied Settings sections",
|
|
6
6
|
"type": "module",
|
|
@@ -79,11 +79,11 @@
|
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@fungi.computer/agar": "0.10.0",
|
|
81
81
|
"@fungi.computer/cairn": "0.1.0",
|
|
82
|
-
"@fungi.computer/caps": "0.11.
|
|
82
|
+
"@fungi.computer/caps": "0.11.3",
|
|
83
83
|
"@fungi.computer/ear-tag": "0.1.0",
|
|
84
84
|
"@fungi.computer/gills": "0.3.0",
|
|
85
85
|
"@fungi.computer/maosaico": "0.1.2",
|
|
86
|
-
"@fungi.computer/parakeet": "0.11.
|
|
86
|
+
"@fungi.computer/parakeet": "0.11.21",
|
|
87
87
|
"@fungi.computer/puffball": "0.5.5",
|
|
88
88
|
"@fungi.computer/shiitake": "0.13.1",
|
|
89
89
|
"@fungi.computer/sigils": "0.3.1",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"react": "^18.3.1 || ^19.2.0"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@fungi.computer/oyster": "0.21.
|
|
109
|
+
"@fungi.computer/oyster": "0.21.8",
|
|
110
110
|
"@cloudflare/workers-types": "5.20260828.1",
|
|
111
111
|
"@fungi.computer/forage": "0.3.5",
|
|
112
112
|
"@fungi.computer/mycelium": "0.3.8",
|
|
@@ -154,6 +154,13 @@
|
|
|
154
154
|
"member"
|
|
155
155
|
],
|
|
156
156
|
"maxBytes": 256
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"key": "windows",
|
|
160
|
+
"scopes": [
|
|
161
|
+
"member"
|
|
162
|
+
],
|
|
163
|
+
"maxBytes": 4096
|
|
157
164
|
}
|
|
158
165
|
],
|
|
159
166
|
"backend": {
|
|
@@ -247,7 +254,7 @@
|
|
|
247
254
|
"workbench:build": "ladle build --outDir ../../.botanical/tourtois-ladle",
|
|
248
255
|
"test:overlay-layering": "node test/overlay-layering.browser.mjs",
|
|
249
256
|
"test:window-new-version": "node test/window-new-version.browser.mjs",
|
|
250
|
-
"test:workbench": "node test/workbench.browser.mjs && node test/desktop-gills.browser.mjs && node test/app-directory-isolation.browser.mjs && node test/workflows-launcher-icon.browser.mjs && node test/landing-bugs.browser.mjs && node test/show-desktop.browser.mjs && node test/window-stack.browser.mjs && node test/window-chrome-back.browser.mjs && node test/tile-backdrop.browser.mjs && node test/app-bar-menu.browser.mjs && node test/launcher-gill.browser.mjs && node test/desktop-storage.browser.mjs && node test/desktop-method-editing.browser.mjs && node test/arrange-layout-shift.browser.mjs && node test/phone-layout.browser.mjs && node test/phone-app-switcher.browser.mjs && node test/computer-choice.browser.mjs && node test/window-resize.browser.mjs",
|
|
257
|
+
"test:workbench": "node test/workbench.browser.mjs && node test/desktop-gills.browser.mjs && node test/app-directory-isolation.browser.mjs && node test/workflows-launcher-icon.browser.mjs && node test/landing-bugs.browser.mjs && node test/show-desktop.browser.mjs && node test/window-stack.browser.mjs && node test/window-chrome-back.browser.mjs && node test/tile-backdrop.browser.mjs && node test/app-bar-menu.browser.mjs && node test/launcher-gill.browser.mjs && node test/desktop-storage.browser.mjs && node test/desktop-method-editing.browser.mjs && node test/arrange-layout-shift.browser.mjs && node test/phone-layout.browser.mjs && node test/phone-app-switcher.browser.mjs && node test/computer-choice.browser.mjs && node test/window-resize.browser.mjs && node test/window-session.browser.mjs",
|
|
251
258
|
"test": "pnpm run test:unit && pnpm run test:merge",
|
|
252
259
|
"test:settings-icons": "node --import tsx ../../tooling/repository/scripts/workbench-proofs.mjs --output ../../.botanical/tourtois-ladle --origin-env TOURTOIS_WORKBENCH_URL test/settings-icons.browser.mjs",
|
|
253
260
|
"format:check": "node ../../tooling/repository/scripts/format-package-check.mjs",
|