@fungi.computer/tourtois 0.30.4 → 0.30.5

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.
@@ -172,7 +172,10 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
172
172
  }
173
173
  };
174
174
  const reconciledDirectoryRef = useRef(null);
175
+ // The stored-window restore yields to the latest request in this page.
176
+ const focusRequest = useRef(null);
175
177
  const focusWindow = useCallback((id) => {
178
+ focusRequest.current = { windowId: id };
176
179
  focus(id);
177
180
  requestAnimationFrame(() => {
178
181
  // Focus the person moved into an open App dial since this request must
@@ -480,6 +483,7 @@ export function AppWorkbench({ paneLayerRef, phone, teamId, teamName, initialCom
480
483
  phone,
481
484
  onTiledChange: onLayoutChange,
482
485
  focusWindow,
486
+ focusRequest: () => focusRequest.current,
483
487
  onError: setAppStatus,
484
488
  });
485
489
  /** An App that is already open comes forward instead of opening twice. */
@@ -50,6 +50,30 @@ export declare function restorableLaunches<App extends Readonly<{
50
50
  frame: WindowPlacement;
51
51
  minimized: boolean;
52
52
  }>[];
53
+ /** The workbench's latest focus request in this page, or null for none yet. */
54
+ export type FocusRequest = Readonly<{
55
+ windowId: string;
56
+ }> | null;
57
+ /**
58
+ * Reopen the stored windows one by one and name the window to focus. The
59
+ * restore runs once per page and waits for the stored session, so the person
60
+ * may open or bring forward an App before it starts or while it runs; their
61
+ * latest choice in this page keeps focus over the stored active window.
62
+ */
63
+ export declare function restoreWindows<Launch extends Readonly<{
64
+ windowId: string;
65
+ }>>(launches: readonly Readonly<{
66
+ launch: Launch;
67
+ minimized: boolean;
68
+ }>[], storedActive: string | null, manager: Readonly<{
69
+ read: () => Readonly<{
70
+ windows: readonly Readonly<{
71
+ windowId: string;
72
+ }>[];
73
+ }>;
74
+ open: (launch: Launch) => Promise<void>;
75
+ minimize: (windowId: string) => Promise<void>;
76
+ }>, focusRequest: () => FocusRequest): Promise<string | null>;
53
77
  /** Reads and writes the session through the member's storage layer. */
54
78
  export declare function createWindowSessionStore(storage: AppStorage): {
55
79
  load(): Promise<WindowSession | null>;
@@ -66,6 +90,8 @@ export type WindowSessionInput = Readonly<{
66
90
  phone: boolean;
67
91
  onTiledChange: ((tiled: boolean) => void) | undefined;
68
92
  focusWindow: (windowId: string) => void;
93
+ /** The workbench's latest focus request, mid-restore ones included. */
94
+ focusRequest: () => FocusRequest;
69
95
  /** Shown to the person as a toast; the session is never lost silently. */
70
96
  onError: (message: string) => void;
71
97
  }>;
@@ -57,6 +57,27 @@ export function restorableLaunches(session, apps, launchFor) {
57
57
  : [];
58
58
  });
59
59
  }
60
+ /**
61
+ * Reopen the stored windows one by one and name the window to focus. The
62
+ * restore runs once per page and waits for the stored session, so the person
63
+ * may open or bring forward an App before it starts or while it runs; their
64
+ * latest choice in this page keeps focus over the stored active window.
65
+ */
66
+ export async function restoreWindows(launches, storedActive, manager, focusRequest) {
67
+ const isOpen = (windowId) => manager.read().windows.some((item) => item.windowId === windowId);
68
+ for (const { launch, minimized } of launches) {
69
+ if (isOpen(launch.windowId))
70
+ continue;
71
+ await manager.open(launch);
72
+ if (minimized)
73
+ await manager.minimize(launch.windowId);
74
+ }
75
+ const chosen = focusRequest();
76
+ if (chosen !== null && isOpen(chosen.windowId))
77
+ return chosen.windowId;
78
+ const active = storedActive && windowIdFor(storedActive);
79
+ return active && isOpen(active) ? active : null;
80
+ }
60
81
  /** Reads and writes the session through the member's storage layer. */
61
82
  export function createWindowSessionStore(storage) {
62
83
  let revision = null;
@@ -129,19 +150,9 @@ export function useWindowSession(input) {
129
150
  const launches = restorableLaunches(session, current.apps, current.launchFor);
130
151
  for (const { launch, frame } of launches)
131
152
  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);
153
+ const focused = await restoreWindows(launches, session.active, current.manager, current.focusRequest);
154
+ if (focused)
155
+ latest.current.focusWindow(focused);
145
156
  }
146
157
  catch (cause) {
147
158
  console.error("Open windows could not be restored", cause);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/tourtois",
3
- "version": "0.30.4",
3
+ "version": "0.30.5",
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",
@@ -106,7 +106,7 @@
106
106
  "react": "^18.3.1 || ^19.2.0"
107
107
  },
108
108
  "devDependencies": {
109
- "@fungi.computer/oyster": "0.51.0",
109
+ "@fungi.computer/oyster": "0.52.0",
110
110
  "@cloudflare/workers-types": "5.20260828.1",
111
111
  "@fungi.computer/forage": "0.4.0",
112
112
  "@fungi.computer/mycelium": "0.4.8",