@fungi.computer/tourtois 0.15.0 → 0.15.2
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 +14 -2
- package/dist/AppPane.js +15 -14
- package/dist/AppWorkbench.js +28 -3
- 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 +1 -1
- package/dist/oyster-setup.d.ts +4 -4
- package/dist/shell.css +7 -0
- package/dist/window-session.d.ts +78 -0
- package/dist/window-session.js +191 -0
- package/package.json +12 -5
package/dist/AppPane.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type WindowPlacement } from "./window-session.js";
|
|
2
|
+
import { WindowHeader } from "@fungi.computer/caps/components/window";
|
|
3
|
+
import { type AppNavigationState, type AppStatusAction } from "@fungi.computer/agar";
|
|
4
|
+
import { type ComponentProps } from "react";
|
|
2
5
|
import { createAppWindowManager, type AppWindowProjection, type AppLaunchDescriptor } from "./app-windows.js";
|
|
3
6
|
import { type AppDirectoryApp } from "./app-launch.js";
|
|
4
7
|
/** The focused window's App-level settings; its Computer lives in its status bar. */
|
|
@@ -8,13 +11,22 @@ export declare function FocusedWindowControls({ app, onOpenSettings, onOpenPermi
|
|
|
8
11
|
onOpenPermissions: () => void;
|
|
9
12
|
projection: AppWindowProjection;
|
|
10
13
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Back and Forward on every window, disabled while the App cannot move (or
|
|
16
|
+
* has published no history), so every title keeps its place.
|
|
17
|
+
*/
|
|
18
|
+
export declare function historyProps(navigation: AppNavigationState | null, title: string, onBack: () => void, onForward: () => void): Pick<ComponentProps<typeof WindowHeader>, "back" | "forward">;
|
|
19
|
+
export declare function AppPane({ projection, nextLaunch, icon, manager, onError, index, seedFrame, onFrame, focusWindow, afterHide, onBack, onForward, onSelectComputer, onChooseComputer, }: {
|
|
12
20
|
projection: AppWindowProjection;
|
|
13
21
|
nextLaunch?: AppLaunchDescriptor | null;
|
|
14
22
|
icon: string | null | undefined;
|
|
15
23
|
manager: ReturnType<typeof createAppWindowManager>;
|
|
16
24
|
onError: (message: string) => void;
|
|
17
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;
|
|
18
30
|
focusWindow: (id: string) => void;
|
|
19
31
|
afterHide: (id: string) => void;
|
|
20
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";
|
|
@@ -122,28 +123,26 @@ function AppWindowControls({ phone, navigation, onAction, popover, ...actions })
|
|
|
122
123
|
}, children: command.label }, command.id))), actions.onPromote ? (_jsx(DropdownMenuItem, { onSelect: actions.onPromote, children: "Make main window" })) : null, _jsx(DropdownMenuItem, { onSelect: actions.onToggleMaximize, children: actions.maximized ? "Restore window" : "Maximize window" }), _jsx(DropdownMenuItem, { onSelect: actions.onMinimize, children: "Minimize window" }), _jsx(DropdownMenuItem, { variant: "destructive", onSelect: actions.onClose, children: "Close window" })] })] }));
|
|
123
124
|
}
|
|
124
125
|
/**
|
|
125
|
-
* Back and Forward
|
|
126
|
-
*
|
|
126
|
+
* Back and Forward on every window, disabled while the App cannot move (or
|
|
127
|
+
* has published no history), so every title keeps its place.
|
|
127
128
|
*/
|
|
128
|
-
function historyProps(navigation, title, onBack, onForward) {
|
|
129
|
-
if (navigation === null)
|
|
130
|
-
return {};
|
|
129
|
+
export function historyProps(navigation, title, onBack, onForward) {
|
|
131
130
|
return {
|
|
132
131
|
back: {
|
|
133
132
|
label: `Back in ${title}`,
|
|
134
133
|
hint: backHint(),
|
|
135
|
-
disabled:
|
|
134
|
+
disabled: navigation?.canGoBack !== true,
|
|
136
135
|
onBack,
|
|
137
136
|
},
|
|
138
137
|
forward: {
|
|
139
138
|
label: `Forward in ${title}`,
|
|
140
139
|
hint: forwardHint(),
|
|
141
|
-
disabled:
|
|
140
|
+
disabled: navigation?.canGoForward !== true,
|
|
142
141
|
onForward,
|
|
143
142
|
},
|
|
144
143
|
};
|
|
145
144
|
}
|
|
146
|
-
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, }) {
|
|
147
146
|
const phone = usePhone();
|
|
148
147
|
const containerRef = useRef(null);
|
|
149
148
|
const popover = useLayer("popover");
|
|
@@ -167,15 +166,17 @@ export function AppPane({ projection, nextLaunch, icon, manager, onError, index,
|
|
|
167
166
|
}, [projection.status]);
|
|
168
167
|
const binding = useMaosaicoItem({
|
|
169
168
|
id: projection.windowId,
|
|
170
|
-
frame:
|
|
171
|
-
x: 24 + index * 40,
|
|
172
|
-
y: 24 + index * 32,
|
|
173
|
-
width: 600,
|
|
174
|
-
height: 480,
|
|
175
|
-
},
|
|
169
|
+
frame: seedFrame ?? cascade(index),
|
|
176
170
|
minima: { width: 320, height: 360 },
|
|
177
171
|
}, { participating: projection.status !== "minimized" });
|
|
178
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]);
|
|
179
180
|
const element = useWindowMotion(binding, layout.interacting, layout.bounds);
|
|
180
181
|
const zoomed = layout.zoomedId === projection.windowId;
|
|
181
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)
|
|
@@ -170,6 +171,10 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
170
171
|
const focusWindow = useCallback((id) => {
|
|
171
172
|
focus(id);
|
|
172
173
|
requestAnimationFrame(() => {
|
|
174
|
+
// Focus the person moved into an open App dial since this request must
|
|
175
|
+
// stay there; landing in a window would dismiss the dial.
|
|
176
|
+
if (appDialContainer?.contains(document.activeElement))
|
|
177
|
+
return;
|
|
173
178
|
const pane = [
|
|
174
179
|
...(paneLayerRef.current?.querySelectorAll("[data-window-id]") ?? []),
|
|
175
180
|
].find((candidate) => candidate.dataset.windowId === id);
|
|
@@ -177,7 +182,7 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
177
182
|
?.querySelector("[data-caps-window-handle]")
|
|
178
183
|
?.focus();
|
|
179
184
|
});
|
|
180
|
-
}, [focus, paneLayerRef]);
|
|
185
|
+
}, [appDialContainer, focus, paneLayerRef]);
|
|
181
186
|
const afterHide = (id) => {
|
|
182
187
|
if (layout.zoomedId === id)
|
|
183
188
|
layout.zoom(null);
|
|
@@ -453,6 +458,26 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
453
458
|
});
|
|
454
459
|
}, [appWindows, listedApps, initialComputerId, computers]);
|
|
455
460
|
const directory = useMemo(() => listedApps ?? [], [listedApps]);
|
|
461
|
+
const windowSession = useWindowSession({
|
|
462
|
+
storage: desktopStorage,
|
|
463
|
+
manager: appWindows,
|
|
464
|
+
apps: listedApps,
|
|
465
|
+
launchFor: (app) => launchFor(app),
|
|
466
|
+
snapshot: {
|
|
467
|
+
tiled: mode === "tiled",
|
|
468
|
+
activeWindowId: activeId,
|
|
469
|
+
windows: appProjection.windows.map((item) => ({
|
|
470
|
+
windowId: item.windowId,
|
|
471
|
+
surfaceId: item.launch.surfaceId,
|
|
472
|
+
status: item.status,
|
|
473
|
+
})),
|
|
474
|
+
},
|
|
475
|
+
interacting: layout.interacting,
|
|
476
|
+
phone,
|
|
477
|
+
onTiledChange: onLayoutChange,
|
|
478
|
+
focusWindow,
|
|
479
|
+
onError: setAppStatus,
|
|
480
|
+
});
|
|
456
481
|
const launchApp = (installation, requestedLaunch) => {
|
|
457
482
|
const windowId = "app:" + installation.surfaceId;
|
|
458
483
|
const launch = requestedLaunch ?? launchFor(installation);
|
|
@@ -614,9 +639,9 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
|
|
|
614
639
|
return app ? (launchFor(app)?.computers ?? []) : [];
|
|
615
640
|
}, storage: desktopStorage, methods: desktopMethods, transport: gills, onRetryApps: () => {
|
|
616
641
|
void appsQuery.refetch();
|
|
617
|
-
} }) }), _jsxs(MaosaicoRegion, { layer: "windows", style: { height: "100%", pointerEvents: "none" }, ref: paneLayerRef, className: "tourtois-pane-layer", "data-layout-mode": mode, children: [appProjection.windows.map((projection, index) => {
|
|
642
|
+
} }) }), _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
643
|
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) => {
|
|
644
|
+
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
645
|
void selectWindowComputer(windowId, computerId);
|
|
621
646
|
}, onChooseComputer: openAppPermissions }, projection.windowId));
|
|
622
647
|
}), extraPanes?.({ activeId, order, focus }), layout.snapPreview && (_jsx(WindowSnapPreview, { "data-snap-side": layout.snapPreview.side, style: {
|
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<{
|
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>;
|
package/dist/shell.css
CHANGED
|
@@ -575,6 +575,13 @@
|
|
|
575
575
|
width: 100%;
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
+
/* Tiled windows cover the desktop: the gaps between them paint a plain face,
|
|
579
|
+
never the widgets underneath. The layer ignores the pointer, so the divider
|
|
580
|
+
handle above the backdrop keeps working. */
|
|
581
|
+
.tourtois-pane-layer[data-desktop="covered"] {
|
|
582
|
+
background: var(--color-base-200);
|
|
583
|
+
}
|
|
584
|
+
|
|
578
585
|
.tourtois-pane {
|
|
579
586
|
pointer-events: auto;
|
|
580
587
|
position: absolute;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
}, z.core.$strip>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export type WindowSession = z.infer<typeof windowSessionSchema>;
|
|
27
|
+
export type WindowPlacement = z.infer<typeof frameSchema>;
|
|
28
|
+
/** What the shell reads from layout and windows to describe the session. */
|
|
29
|
+
export type WindowSessionSnapshot = Readonly<{
|
|
30
|
+
tiled: boolean;
|
|
31
|
+
activeWindowId: string | null;
|
|
32
|
+
windows: readonly Readonly<{
|
|
33
|
+
windowId: string;
|
|
34
|
+
surfaceId: string;
|
|
35
|
+
status: string;
|
|
36
|
+
}>[];
|
|
37
|
+
frames: ReadonlyMap<string, WindowPlacement>;
|
|
38
|
+
}>;
|
|
39
|
+
/** Where a new window floats until the person moves it. */
|
|
40
|
+
export declare const cascade: (index: number) => WindowPlacement;
|
|
41
|
+
/** Pure projection of the live desktop into the stored shape. */
|
|
42
|
+
export declare function windowSessionFrom(snapshot: WindowSessionSnapshot): WindowSession;
|
|
43
|
+
/** Launches for the stored windows whose Apps are still installed, in order. */
|
|
44
|
+
export declare function restorableLaunches<App extends Readonly<{
|
|
45
|
+
surfaceId: string;
|
|
46
|
+
roles: readonly string[];
|
|
47
|
+
}>, Launch>(session: WindowSession, apps: readonly App[], launchFor: (app: App) => Launch | null): readonly Readonly<{
|
|
48
|
+
launch: Launch;
|
|
49
|
+
frame: WindowPlacement;
|
|
50
|
+
}>[];
|
|
51
|
+
/** Reads and writes the session through the member's storage layer. */
|
|
52
|
+
export declare function createWindowSessionStore(storage: AppStorage): {
|
|
53
|
+
load(): Promise<WindowSession | null>;
|
|
54
|
+
save(session: WindowSession): Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
export type WindowSessionInput = Readonly<{
|
|
57
|
+
storage: AppStorage;
|
|
58
|
+
manager: AppWindowManager;
|
|
59
|
+
apps: readonly AppDirectoryApp[] | undefined;
|
|
60
|
+
launchFor: (app: AppDirectoryApp) => AppLaunchDescriptor | null;
|
|
61
|
+
snapshot: Omit<WindowSessionSnapshot, "frames">;
|
|
62
|
+
interacting: boolean;
|
|
63
|
+
/** A phone is always tiled, so it neither reads nor overwrites the choice. */
|
|
64
|
+
phone: boolean;
|
|
65
|
+
onTiledChange: ((tiled: boolean) => void) | undefined;
|
|
66
|
+
focusWindow: (windowId: string) => void;
|
|
67
|
+
/** Shown to the person as a toast; the session is never lost silently. */
|
|
68
|
+
onError: (message: string) => void;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Restore the member's windows once the App directory is known, then keep
|
|
72
|
+
* the stored session current. Frames seed panes as they register.
|
|
73
|
+
*/
|
|
74
|
+
export declare function useWindowSession(input: WindowSessionInput): {
|
|
75
|
+
reportFrame: (windowId: string, frame: WindowPlacement) => void;
|
|
76
|
+
seedFrame: (windowId: string) => WindowPlacement | undefined;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** The member's own storage key for the windows they had open. */
|
|
4
|
+
export const windowSessionKey = "windows";
|
|
5
|
+
const frameSchema = z.object({
|
|
6
|
+
x: z.number(),
|
|
7
|
+
y: z.number(),
|
|
8
|
+
width: z.number().positive(),
|
|
9
|
+
height: z.number().positive(),
|
|
10
|
+
});
|
|
11
|
+
export const windowSessionSchema = z.object({
|
|
12
|
+
tiled: z.boolean(),
|
|
13
|
+
/** The focused window's surface, raised last so it stays on top. */
|
|
14
|
+
active: z.string().nullable(),
|
|
15
|
+
/** Open windows in tiling order; minimized windows are not kept. */
|
|
16
|
+
windows: z
|
|
17
|
+
.array(z.object({ surfaceId: z.string().min(1), frame: frameSchema }))
|
|
18
|
+
.max(16),
|
|
19
|
+
});
|
|
20
|
+
const windowIdFor = (surfaceId) => "app:" + surfaceId;
|
|
21
|
+
/** Where a new window floats until the person moves it. */
|
|
22
|
+
export const cascade = (index) => ({
|
|
23
|
+
x: 24 + index * 40,
|
|
24
|
+
y: 24 + index * 32,
|
|
25
|
+
width: 600,
|
|
26
|
+
height: 480,
|
|
27
|
+
});
|
|
28
|
+
/** Pure projection of the live desktop into the stored shape. */
|
|
29
|
+
export function windowSessionFrom(snapshot) {
|
|
30
|
+
const windows = snapshot.windows.flatMap((item, index) => item.status === "minimized"
|
|
31
|
+
? []
|
|
32
|
+
: [
|
|
33
|
+
{
|
|
34
|
+
surfaceId: item.surfaceId,
|
|
35
|
+
frame: {
|
|
36
|
+
...(snapshot.frames.get(item.windowId) ?? cascade(index)),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
const active = snapshot.windows.find((item) => item.windowId === snapshot.activeWindowId);
|
|
41
|
+
return windowSessionSchema.parse({
|
|
42
|
+
tiled: snapshot.tiled,
|
|
43
|
+
active: active && windows.some((item) => item.surfaceId === active.surfaceId)
|
|
44
|
+
? active.surfaceId
|
|
45
|
+
: null,
|
|
46
|
+
windows: windows.slice(0, 16),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Launches for the stored windows whose Apps are still installed, in order. */
|
|
50
|
+
export function restorableLaunches(session, apps, launchFor) {
|
|
51
|
+
return session.windows.flatMap((saved) => {
|
|
52
|
+
const app = apps.find((item) => item.surfaceId === saved.surfaceId && !item.roles.includes("dashboard"));
|
|
53
|
+
const launch = app ? launchFor(app) : null;
|
|
54
|
+
return launch ? [{ launch, frame: saved.frame }] : [];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Reads and writes the session through the member's storage layer. */
|
|
58
|
+
export function createWindowSessionStore(storage) {
|
|
59
|
+
let revision = null;
|
|
60
|
+
let queue = Promise.resolve();
|
|
61
|
+
return {
|
|
62
|
+
async load() {
|
|
63
|
+
const resolved = await storage.read(windowSessionKey);
|
|
64
|
+
revision = resolved.member?.revision ?? null;
|
|
65
|
+
const parsed = windowSessionSchema.safeParse(resolved.member?.value);
|
|
66
|
+
return parsed.success ? parsed.data : null;
|
|
67
|
+
},
|
|
68
|
+
save(session) {
|
|
69
|
+
const write = async () => {
|
|
70
|
+
try {
|
|
71
|
+
const result = await storage.write({
|
|
72
|
+
key: windowSessionKey,
|
|
73
|
+
scope: "member",
|
|
74
|
+
basedOn: revision,
|
|
75
|
+
value: session,
|
|
76
|
+
});
|
|
77
|
+
revision = result.revision;
|
|
78
|
+
}
|
|
79
|
+
catch (cause) {
|
|
80
|
+
// Re-read the revision so the next change is not stuck on a
|
|
81
|
+
// conflict; a failed re-read is reported together with the write.
|
|
82
|
+
try {
|
|
83
|
+
const resolved = await storage.read(windowSessionKey);
|
|
84
|
+
revision = resolved.member?.revision ?? null;
|
|
85
|
+
}
|
|
86
|
+
catch (readCause) {
|
|
87
|
+
throw new AggregateError([cause, readCause], "Open windows could not be saved", { cause: readCause });
|
|
88
|
+
}
|
|
89
|
+
throw cause;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
// Each save waits for the previous one to settle, then runs; the caller
|
|
93
|
+
// of a failed save receives that failure.
|
|
94
|
+
const saving = queue.then(write, write);
|
|
95
|
+
queue = saving;
|
|
96
|
+
return saving;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Restore the member's windows once the App directory is known, then keep
|
|
102
|
+
* the stored session current. Frames seed panes as they register.
|
|
103
|
+
*/
|
|
104
|
+
export function useWindowSession(input) {
|
|
105
|
+
const latest = useRef(input);
|
|
106
|
+
latest.current = input;
|
|
107
|
+
const seeds = useRef(new Map());
|
|
108
|
+
const [store] = useState(() => createWindowSessionStore(input.storage));
|
|
109
|
+
const [restored, setRestored] = useState(false);
|
|
110
|
+
const started = useRef(false);
|
|
111
|
+
const preferredTiled = useRef(true);
|
|
112
|
+
const ready = input.apps !== undefined;
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!ready || started.current)
|
|
115
|
+
return;
|
|
116
|
+
started.current = true;
|
|
117
|
+
void (async () => {
|
|
118
|
+
try {
|
|
119
|
+
const session = await store.load();
|
|
120
|
+
const current = latest.current;
|
|
121
|
+
if (!session || !current.apps)
|
|
122
|
+
return;
|
|
123
|
+
preferredTiled.current = session.tiled;
|
|
124
|
+
current.onTiledChange?.(session.tiled);
|
|
125
|
+
const launches = restorableLaunches(session, current.apps, current.launchFor);
|
|
126
|
+
for (const { launch, frame } of launches)
|
|
127
|
+
seeds.current.set(launch.windowId, frame);
|
|
128
|
+
for (const { launch } of launches) {
|
|
129
|
+
if (current.manager
|
|
130
|
+
.read()
|
|
131
|
+
.windows.some((item) => item.windowId === launch.windowId))
|
|
132
|
+
continue;
|
|
133
|
+
await current.manager.open(launch);
|
|
134
|
+
}
|
|
135
|
+
const active = session.active && windowIdFor(session.active);
|
|
136
|
+
if (active &&
|
|
137
|
+
current.manager.read().windows.some((w) => w.windowId === active))
|
|
138
|
+
latest.current.focusWindow(active);
|
|
139
|
+
}
|
|
140
|
+
catch (cause) {
|
|
141
|
+
console.error("Open windows could not be restored", cause);
|
|
142
|
+
latest.current.onError("Your open windows could not be restored.");
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
setRestored(true);
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
}, [ready, store]);
|
|
149
|
+
const { snapshot, interacting, phone } = input;
|
|
150
|
+
// Where each window floats: restored positions, then whatever panes report.
|
|
151
|
+
const [reported, setReported] = useState(new Map());
|
|
152
|
+
const reportFrame = useCallback((windowId, frame) => {
|
|
153
|
+
setReported((current) => {
|
|
154
|
+
const known = current.get(windowId);
|
|
155
|
+
if (known?.x === frame.x &&
|
|
156
|
+
known.y === frame.y &&
|
|
157
|
+
known.width === frame.width &&
|
|
158
|
+
known.height === frame.height)
|
|
159
|
+
return current;
|
|
160
|
+
return new Map(current).set(windowId, frame);
|
|
161
|
+
});
|
|
162
|
+
}, []);
|
|
163
|
+
const session = windowSessionFrom({
|
|
164
|
+
...snapshot,
|
|
165
|
+
frames: new Map([...seeds.current, ...reported]),
|
|
166
|
+
tiled: phone ? preferredTiled.current : snapshot.tiled,
|
|
167
|
+
});
|
|
168
|
+
const body = JSON.stringify(session);
|
|
169
|
+
const pending = useRef(session);
|
|
170
|
+
pending.current = session;
|
|
171
|
+
const saved = useRef(null);
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!restored || interacting || saved.current === body)
|
|
174
|
+
return;
|
|
175
|
+
const timer = setTimeout(() => {
|
|
176
|
+
saved.current = body;
|
|
177
|
+
void store.save(pending.current).catch((cause) => {
|
|
178
|
+
saved.current = null;
|
|
179
|
+
console.error("Open windows were not saved", cause);
|
|
180
|
+
latest.current.onError("Your open windows could not be saved.");
|
|
181
|
+
});
|
|
182
|
+
}, 400);
|
|
183
|
+
return () => {
|
|
184
|
+
clearTimeout(timer);
|
|
185
|
+
};
|
|
186
|
+
}, [body, interacting, restored, store]);
|
|
187
|
+
return {
|
|
188
|
+
reportFrame,
|
|
189
|
+
seedFrame: (windowId) => seeds.current.get(windowId),
|
|
190
|
+
};
|
|
191
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/tourtois",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
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.2",
|
|
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.20",
|
|
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.7",
|
|
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/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",
|