@wildwinter/app-shell 0.26.0 → 0.27.0
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/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/session.cjs +3 -4
- package/dist/session.cjs.map +1 -1
- package/dist/session.d.cts +12 -2
- package/dist/session.d.ts +12 -2
- package/dist/session.js +3 -4
- package/dist/session.js.map +1 -1
- package/package.json +1 -1
package/dist/session.cjs
CHANGED
|
@@ -24,16 +24,15 @@ function createProjectSession(opts) {
|
|
|
24
24
|
}
|
|
25
25
|
if (session !== void 0) opts.close?.(session);
|
|
26
26
|
session = opened.session;
|
|
27
|
-
opts.store.touchProject(opened.root);
|
|
27
|
+
opts.store.touchProject(opened.root, opened.name);
|
|
28
28
|
invalidateSatellites();
|
|
29
29
|
opts.refreshMenu?.();
|
|
30
30
|
return opened.reply;
|
|
31
31
|
},
|
|
32
32
|
isKnownPath(path$1) {
|
|
33
33
|
const s = opts.store.get();
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
);
|
|
34
|
+
const paths = [s.lastProject, ...s.recents.map((r) => r.path)];
|
|
35
|
+
const known = new Set(paths.filter((p) => !!p).map((p) => path.resolve(p)));
|
|
37
36
|
return known.has(path.resolve(path$1));
|
|
38
37
|
},
|
|
39
38
|
addSatellite(satellite) {
|
package/dist/session.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session.ts"],"names":["path","resolve"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../src/session.ts"],"names":["path","resolve"],"mappings":";;;;;AAgHO,SAAS,qBAA2B,IAAA,EAAyD;AAClG,EAAA,IAAI,OAAA;AACJ,EAAA,MAAM,aAA0B,CAAC,GAAI,IAAA,CAAK,UAAA,IAAc,EAAG,CAAA;AAE3D,EAAA,MAAM,uBAAuB,MAAY;AACvC,IAAA,KAAA,MAAW,OAAO,UAAA,EAAY;AAC5B,MAAA,GAAA,CAAI,KAAA,IAAQ;AACZ,MAAA,MAAM,GAAA,GAAM,IAAI,MAAA,EAAO;AACvB,MAAA,IAAI,GAAA,IAAO,CAAC,GAAA,CAAI,WAAA,IAAe,GAAA,CAAI,WAAA,CAAY,IAAA,CAAK,GAAA,CAAI,OAAO,CAAA;AAAA,IACjE;AAAA,EACF,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,SAAS,MAAM,OAAA;AAAA,IAEf,OAAO,IAAA,EAAM;AACX,MAAA,MAAM,MAAA,GAAS,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA;AAC7B,MAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,QAAA,IAAA,CAAK,KAAA,CAAM,cAAc,IAAI,CAAA;AAC7B,QAAA,IAAA,CAAK,WAAA,IAAc;AACnB,QAAA,OAAO,MAAA;AAAA,MACT;AACA,MAAA,IAAI,OAAA,KAAY,MAAA,EAAW,IAAA,CAAK,KAAA,GAAQ,OAAO,CAAA;AAC/C,MAAA,OAAA,GAAU,MAAA,CAAO,OAAA;AACjB,MAAA,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAA,CAAO,IAAA,EAAM,OAAO,IAAI,CAAA;AAChD,MAAA,oBAAA,EAAqB;AACrB,MAAA,IAAA,CAAK,WAAA,IAAc;AACnB,MAAA,OAAO,MAAA,CAAO,KAAA;AAAA,IAChB,CAAA;AAAA,IAEA,YAAYA,MAAA,EAAM;AAChB,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,GAAA,EAAI;AAQzB,MAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,CAAE,WAAA,EAAa,GAAG,CAAA,CAAE,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAC,CAAA;AAC7D,MAAA,MAAM,QAAQ,IAAI,GAAA,CAAI,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,KAAmB,CAAC,CAAC,CAAC,EAAE,GAAA,CAAI,CAAC,MAAMC,YAAA,CAAQ,CAAC,CAAC,CAAC,CAAA;AAClF,MAAA,OAAO,KAAA,CAAM,GAAA,CAAIA,YAAA,CAAQD,MAAI,CAAC,CAAA;AAAA,IAChC,CAAA;AAAA,IAEA,aAAa,SAAA,EAAW;AACtB,MAAA,UAAA,CAAW,KAAK,SAAS,CAAA;AACzB,MAAA,OAAO,MAAM;AACX,QAAA,MAAM,CAAA,GAAI,UAAA,CAAW,OAAA,CAAQ,SAAS,CAAA;AACtC,QAAA,IAAI,CAAA,IAAK,CAAA,EAAG,UAAA,CAAW,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,MACpC,CAAA;AAAA,IACF,CAAA;AAAA,IAEA;AAAA,GACF;AACF","file":"session.cjs","sourcesContent":["// ---------------------------------------------------------------------------\n// The project session: what happens around opening a project, as opposed to\n// the opening itself.\n//\n// Both apps have a function - `openAt` here, `openAndRecord` there - and under\n// two different names they do the same six things in the same order:\n//\n// 1. Ask the app to open it, which is the only app-specific step.\n// 2. On failure, drop it from recents (a project that has moved should stop\n// being offered) and rebuild the menu.\n// 3. On success, finish with the outgoing session.\n// 4. Record the opened ROOT in the store, which also clears the remembered\n// place when it is a different project.\n// 5. Invalidate everything main was caching FOR THE OLD PROJECT, and tell\n// each satellite tool window that the ground moved.\n// 6. Rebuild the menu, so File > Open Recent is current.\n//\n// Step 5 is the one worth extracting on its own. Both apps hand-wire it per\n// window - a cached result nulled, then `if (win && !win.isDestroyed())\n// win.webContents.send(...)` - Storyletter three times, Patterpad twice, and\n// every new tool window is another chance to forget one and leave a window\n// describing a project that is no longer open. Registering a satellite once\n// makes forgetting it impossible.\n//\n// It also carries `isKnownPath`, which only Patterpad had and which is a real\n// guard rather than a tidiness: a renderer must not be able to name an\n// arbitrary directory and have main open it. Fresh paths enter through the\n// native dialogs, which run in main where the person actually chose them;\n// everything else must already be in recents.\n//\n// Electron-free: a satellite is anything with the two methods it needs, which\n// a BrowserWindow satisfies and a test can fake.\n// ---------------------------------------------------------------------------\n\nimport { resolve } from \"node:path\";\nimport type { RecentProject } from \"./app-store.js\";\n\n/** As much of a BrowserWindow as this file has any business knowing. */\nexport interface SatelliteWindow {\n isDestroyed(): boolean;\n webContents: { send(channel: string, ...args: unknown[]): void };\n}\n\n/**\n * A tool window that shows something about the open project, and any state\n * main is holding on its behalf.\n */\nexport interface Satellite {\n /** Looked up each time rather than held: these windows open and close. */\n window: () => SatelliteWindow | undefined | null;\n /** What to send when the project changes. The window re-fetches; it is a\n * nudge, not a payload, because by then the new project is already open. */\n channel: string;\n /** Drop what main was caching for the old project - a coverage report, a\n * search anchor. Called before the window is told. */\n clear?: () => void;\n}\n\n/** The slice of the app store this needs. Structural, so the real store fits\n * without dragging its generic parameters in here. */\nexport interface SessionStore {\n get(): { recents: RecentProject[]; lastProject?: string };\n /** The name is what the app just learned by opening the project. Omitting it\n * keeps whatever was known, which is `createAppStore`'s rule. */\n touchProject(path: string, name?: string): void;\n forgetProject(path: string): void;\n}\n\nexport interface ProjectSessionOptions<S, R> {\n store: SessionStore;\n /**\n * Open it. The one app-specific step.\n *\n * `root` is what gets recorded, and it is not always the path asked for: a\n * file-association launch names a shard INSIDE a project, and it is the\n * project that belongs in recents. `reply` is whatever the app sends back to\n * its renderer - this never looks inside it.\n *\n * `name` is the project's display name, if opening it revealed one. Return it\n * and the session records it with the path; leave it out and whatever was\n * known is kept. This is here so no app has to touch the store a second time\n * just to name what it has already opened.\n */\n open: (path: string) => { session: S; root: string; name?: string; reply: R } | { error: string };\n /**\n * The outgoing session is finished with: sweep its temporary files, close its\n * handles. Called only once the replacement has opened successfully, so a\n * failed open leaves the current project entirely alone.\n */\n close?: (session: S) => void;\n /** Rebuild the application menu. Called after a change either way, because a\n * failed open changes recents too. */\n refreshMenu?: () => void;\n satellites?: Satellite[];\n}\n\nexport interface ProjectSession<S, R> {\n /** The open project, or undefined before the first one. */\n current: () => S | undefined;\n /** Open, with everything in the comment above. */\n openAt: (path: string) => R | { error: string };\n /** May the renderer ask for this path? See the note above: only paths the app\n * already knows, because a native dialog put them there. */\n isKnownPath: (path: string) => boolean;\n /** Register a tool window after construction, which is when they usually\n * appear. Returns a function that unregisters it. */\n addSatellite: (satellite: Satellite) => () => void;\n /** Fire every satellite by hand. For the cases that are not an open but do\n * invalidate the same things - a merge landing new content underneath. */\n invalidateSatellites: () => void;\n}\n\nexport function createProjectSession<S, R>(opts: ProjectSessionOptions<S, R>): ProjectSession<S, R> {\n let session: S | undefined;\n const satellites: Satellite[] = [...(opts.satellites ?? [])];\n\n const invalidateSatellites = (): void => {\n for (const sat of satellites) {\n sat.clear?.();\n const win = sat.window();\n if (win && !win.isDestroyed()) win.webContents.send(sat.channel);\n }\n };\n\n return {\n current: () => session,\n\n openAt(path) {\n const opened = opts.open(path);\n if (\"error\" in opened) {\n opts.store.forgetProject(path);\n opts.refreshMenu?.();\n return opened;\n }\n if (session !== undefined) opts.close?.(session);\n session = opened.session;\n opts.store.touchProject(opened.root, opened.name);\n invalidateSatellites();\n opts.refreshMenu?.();\n return opened.reply;\n },\n\n isKnownPath(path) {\n const s = opts.store.get();\n // Read `path` off each recent EXPLICITLY rather than filtering the list to\n // whatever looks like a string. The old form did the latter, and when\n // recents became objects in 0.25.0 every entry quietly failed the test and\n // was dropped: no error, no empty list to notice, just a launcher that had\n // stopped recognising every project but the last one. A defensive filter is\n // what turns a shape change into a silent behaviour change, so this one\n // states the shape it wants and lets the compiler enforce it.\n const paths = [s.lastProject, ...s.recents.map((r) => r.path)];\n const known = new Set(paths.filter((p): p is string => !!p).map((p) => resolve(p)));\n return known.has(resolve(path));\n },\n\n addSatellite(satellite) {\n satellites.push(satellite);\n return () => {\n const i = satellites.indexOf(satellite);\n if (i >= 0) satellites.splice(i, 1);\n };\n },\n\n invalidateSatellites,\n };\n}\n"]}
|
package/dist/session.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RecentProject } from './app-store.cjs';
|
|
2
|
+
|
|
1
3
|
/** As much of a BrowserWindow as this file has any business knowing. */
|
|
2
4
|
interface SatelliteWindow {
|
|
3
5
|
isDestroyed(): boolean;
|
|
@@ -23,10 +25,12 @@ interface Satellite {
|
|
|
23
25
|
* without dragging its generic parameters in here. */
|
|
24
26
|
interface SessionStore {
|
|
25
27
|
get(): {
|
|
26
|
-
recents:
|
|
28
|
+
recents: RecentProject[];
|
|
27
29
|
lastProject?: string;
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
/** The name is what the app just learned by opening the project. Omitting it
|
|
32
|
+
* keeps whatever was known, which is `createAppStore`'s rule. */
|
|
33
|
+
touchProject(path: string, name?: string): void;
|
|
30
34
|
forgetProject(path: string): void;
|
|
31
35
|
}
|
|
32
36
|
interface ProjectSessionOptions<S, R> {
|
|
@@ -38,10 +42,16 @@ interface ProjectSessionOptions<S, R> {
|
|
|
38
42
|
* file-association launch names a shard INSIDE a project, and it is the
|
|
39
43
|
* project that belongs in recents. `reply` is whatever the app sends back to
|
|
40
44
|
* its renderer - this never looks inside it.
|
|
45
|
+
*
|
|
46
|
+
* `name` is the project's display name, if opening it revealed one. Return it
|
|
47
|
+
* and the session records it with the path; leave it out and whatever was
|
|
48
|
+
* known is kept. This is here so no app has to touch the store a second time
|
|
49
|
+
* just to name what it has already opened.
|
|
41
50
|
*/
|
|
42
51
|
open: (path: string) => {
|
|
43
52
|
session: S;
|
|
44
53
|
root: string;
|
|
54
|
+
name?: string;
|
|
45
55
|
reply: R;
|
|
46
56
|
} | {
|
|
47
57
|
error: string;
|
package/dist/session.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { RecentProject } from './app-store.js';
|
|
2
|
+
|
|
1
3
|
/** As much of a BrowserWindow as this file has any business knowing. */
|
|
2
4
|
interface SatelliteWindow {
|
|
3
5
|
isDestroyed(): boolean;
|
|
@@ -23,10 +25,12 @@ interface Satellite {
|
|
|
23
25
|
* without dragging its generic parameters in here. */
|
|
24
26
|
interface SessionStore {
|
|
25
27
|
get(): {
|
|
26
|
-
recents:
|
|
28
|
+
recents: RecentProject[];
|
|
27
29
|
lastProject?: string;
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
/** The name is what the app just learned by opening the project. Omitting it
|
|
32
|
+
* keeps whatever was known, which is `createAppStore`'s rule. */
|
|
33
|
+
touchProject(path: string, name?: string): void;
|
|
30
34
|
forgetProject(path: string): void;
|
|
31
35
|
}
|
|
32
36
|
interface ProjectSessionOptions<S, R> {
|
|
@@ -38,10 +42,16 @@ interface ProjectSessionOptions<S, R> {
|
|
|
38
42
|
* file-association launch names a shard INSIDE a project, and it is the
|
|
39
43
|
* project that belongs in recents. `reply` is whatever the app sends back to
|
|
40
44
|
* its renderer - this never looks inside it.
|
|
45
|
+
*
|
|
46
|
+
* `name` is the project's display name, if opening it revealed one. Return it
|
|
47
|
+
* and the session records it with the path; leave it out and whatever was
|
|
48
|
+
* known is kept. This is here so no app has to touch the store a second time
|
|
49
|
+
* just to name what it has already opened.
|
|
41
50
|
*/
|
|
42
51
|
open: (path: string) => {
|
|
43
52
|
session: S;
|
|
44
53
|
root: string;
|
|
54
|
+
name?: string;
|
|
45
55
|
reply: R;
|
|
46
56
|
} | {
|
|
47
57
|
error: string;
|
package/dist/session.js
CHANGED
|
@@ -22,16 +22,15 @@ function createProjectSession(opts) {
|
|
|
22
22
|
}
|
|
23
23
|
if (session !== void 0) opts.close?.(session);
|
|
24
24
|
session = opened.session;
|
|
25
|
-
opts.store.touchProject(opened.root);
|
|
25
|
+
opts.store.touchProject(opened.root, opened.name);
|
|
26
26
|
invalidateSatellites();
|
|
27
27
|
opts.refreshMenu?.();
|
|
28
28
|
return opened.reply;
|
|
29
29
|
},
|
|
30
30
|
isKnownPath(path) {
|
|
31
31
|
const s = opts.store.get();
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
);
|
|
32
|
+
const paths = [s.lastProject, ...s.recents.map((r) => r.path)];
|
|
33
|
+
const known = new Set(paths.filter((p) => !!p).map((p) => resolve(p)));
|
|
35
34
|
return known.has(resolve(path));
|
|
36
35
|
},
|
|
37
36
|
addSatellite(satellite) {
|
package/dist/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/session.ts"],"names":[],"mappings":";;;AAgHO,SAAS,qBAA2B,IAAA,EAAyD;AAClG,EAAA,IAAI,OAAA;AACJ,EAAA,MAAM,aAA0B,CAAC,GAAI,IAAA,CAAK,UAAA,IAAc,EAAG,CAAA;AAE3D,EAAA,MAAM,uBAAuB,MAAY;AACvC,IAAA,KAAA,MAAW,OAAO,UAAA,EAAY;AAC5B,MAAA,GAAA,CAAI,KAAA,IAAQ;AACZ,MAAA,MAAM,GAAA,GAAM,IAAI,MAAA,EAAO;AACvB,MAAA,IAAI,GAAA,IAAO,CAAC,GAAA,CAAI,WAAA,IAAe,GAAA,CAAI,WAAA,CAAY,IAAA,CAAK,GAAA,CAAI,OAAO,CAAA;AAAA,IACjE;AAAA,EACF,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,SAAS,MAAM,OAAA;AAAA,IAEf,OAAO,IAAA,EAAM;AACX,MAAA,MAAM,MAAA,GAAS,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA;AAC7B,MAAA,IAAI,WAAW,MAAA,EAAQ;AACrB,QAAA,IAAA,CAAK,KAAA,CAAM,cAAc,IAAI,CAAA;AAC7B,QAAA,IAAA,CAAK,WAAA,IAAc;AACnB,QAAA,OAAO,MAAA;AAAA,MACT;AACA,MAAA,IAAI,OAAA,KAAY,MAAA,EAAW,IAAA,CAAK,KAAA,GAAQ,OAAO,CAAA;AAC/C,MAAA,OAAA,GAAU,MAAA,CAAO,OAAA;AACjB,MAAA,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,MAAA,CAAO,IAAA,EAAM,OAAO,IAAI,CAAA;AAChD,MAAA,oBAAA,EAAqB;AACrB,MAAA,IAAA,CAAK,WAAA,IAAc;AACnB,MAAA,OAAO,MAAA,CAAO,KAAA;AAAA,IAChB,CAAA;AAAA,IAEA,YAAY,IAAA,EAAM;AAChB,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,GAAA,EAAI;AAQzB,MAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,CAAE,WAAA,EAAa,GAAG,CAAA,CAAE,OAAA,CAAQ,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAC,CAAA;AAC7D,MAAA,MAAM,QAAQ,IAAI,GAAA,CAAI,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,KAAmB,CAAC,CAAC,CAAC,EAAE,GAAA,CAAI,CAAC,MAAM,OAAA,CAAQ,CAAC,CAAC,CAAC,CAAA;AAClF,MAAA,OAAO,KAAA,CAAM,GAAA,CAAI,OAAA,CAAQ,IAAI,CAAC,CAAA;AAAA,IAChC,CAAA;AAAA,IAEA,aAAa,SAAA,EAAW;AACtB,MAAA,UAAA,CAAW,KAAK,SAAS,CAAA;AACzB,MAAA,OAAO,MAAM;AACX,QAAA,MAAM,CAAA,GAAI,UAAA,CAAW,OAAA,CAAQ,SAAS,CAAA;AACtC,QAAA,IAAI,CAAA,IAAK,CAAA,EAAG,UAAA,CAAW,MAAA,CAAO,GAAG,CAAC,CAAA;AAAA,MACpC,CAAA;AAAA,IACF,CAAA;AAAA,IAEA;AAAA,GACF;AACF","file":"session.js","sourcesContent":["// ---------------------------------------------------------------------------\n// The project session: what happens around opening a project, as opposed to\n// the opening itself.\n//\n// Both apps have a function - `openAt` here, `openAndRecord` there - and under\n// two different names they do the same six things in the same order:\n//\n// 1. Ask the app to open it, which is the only app-specific step.\n// 2. On failure, drop it from recents (a project that has moved should stop\n// being offered) and rebuild the menu.\n// 3. On success, finish with the outgoing session.\n// 4. Record the opened ROOT in the store, which also clears the remembered\n// place when it is a different project.\n// 5. Invalidate everything main was caching FOR THE OLD PROJECT, and tell\n// each satellite tool window that the ground moved.\n// 6. Rebuild the menu, so File > Open Recent is current.\n//\n// Step 5 is the one worth extracting on its own. Both apps hand-wire it per\n// window - a cached result nulled, then `if (win && !win.isDestroyed())\n// win.webContents.send(...)` - Storyletter three times, Patterpad twice, and\n// every new tool window is another chance to forget one and leave a window\n// describing a project that is no longer open. Registering a satellite once\n// makes forgetting it impossible.\n//\n// It also carries `isKnownPath`, which only Patterpad had and which is a real\n// guard rather than a tidiness: a renderer must not be able to name an\n// arbitrary directory and have main open it. Fresh paths enter through the\n// native dialogs, which run in main where the person actually chose them;\n// everything else must already be in recents.\n//\n// Electron-free: a satellite is anything with the two methods it needs, which\n// a BrowserWindow satisfies and a test can fake.\n// ---------------------------------------------------------------------------\n\nimport { resolve } from \"node:path\";\nimport type { RecentProject } from \"./app-store.js\";\n\n/** As much of a BrowserWindow as this file has any business knowing. */\nexport interface SatelliteWindow {\n isDestroyed(): boolean;\n webContents: { send(channel: string, ...args: unknown[]): void };\n}\n\n/**\n * A tool window that shows something about the open project, and any state\n * main is holding on its behalf.\n */\nexport interface Satellite {\n /** Looked up each time rather than held: these windows open and close. */\n window: () => SatelliteWindow | undefined | null;\n /** What to send when the project changes. The window re-fetches; it is a\n * nudge, not a payload, because by then the new project is already open. */\n channel: string;\n /** Drop what main was caching for the old project - a coverage report, a\n * search anchor. Called before the window is told. */\n clear?: () => void;\n}\n\n/** The slice of the app store this needs. Structural, so the real store fits\n * without dragging its generic parameters in here. */\nexport interface SessionStore {\n get(): { recents: RecentProject[]; lastProject?: string };\n /** The name is what the app just learned by opening the project. Omitting it\n * keeps whatever was known, which is `createAppStore`'s rule. */\n touchProject(path: string, name?: string): void;\n forgetProject(path: string): void;\n}\n\nexport interface ProjectSessionOptions<S, R> {\n store: SessionStore;\n /**\n * Open it. The one app-specific step.\n *\n * `root` is what gets recorded, and it is not always the path asked for: a\n * file-association launch names a shard INSIDE a project, and it is the\n * project that belongs in recents. `reply` is whatever the app sends back to\n * its renderer - this never looks inside it.\n *\n * `name` is the project's display name, if opening it revealed one. Return it\n * and the session records it with the path; leave it out and whatever was\n * known is kept. This is here so no app has to touch the store a second time\n * just to name what it has already opened.\n */\n open: (path: string) => { session: S; root: string; name?: string; reply: R } | { error: string };\n /**\n * The outgoing session is finished with: sweep its temporary files, close its\n * handles. Called only once the replacement has opened successfully, so a\n * failed open leaves the current project entirely alone.\n */\n close?: (session: S) => void;\n /** Rebuild the application menu. Called after a change either way, because a\n * failed open changes recents too. */\n refreshMenu?: () => void;\n satellites?: Satellite[];\n}\n\nexport interface ProjectSession<S, R> {\n /** The open project, or undefined before the first one. */\n current: () => S | undefined;\n /** Open, with everything in the comment above. */\n openAt: (path: string) => R | { error: string };\n /** May the renderer ask for this path? See the note above: only paths the app\n * already knows, because a native dialog put them there. */\n isKnownPath: (path: string) => boolean;\n /** Register a tool window after construction, which is when they usually\n * appear. Returns a function that unregisters it. */\n addSatellite: (satellite: Satellite) => () => void;\n /** Fire every satellite by hand. For the cases that are not an open but do\n * invalidate the same things - a merge landing new content underneath. */\n invalidateSatellites: () => void;\n}\n\nexport function createProjectSession<S, R>(opts: ProjectSessionOptions<S, R>): ProjectSession<S, R> {\n let session: S | undefined;\n const satellites: Satellite[] = [...(opts.satellites ?? [])];\n\n const invalidateSatellites = (): void => {\n for (const sat of satellites) {\n sat.clear?.();\n const win = sat.window();\n if (win && !win.isDestroyed()) win.webContents.send(sat.channel);\n }\n };\n\n return {\n current: () => session,\n\n openAt(path) {\n const opened = opts.open(path);\n if (\"error\" in opened) {\n opts.store.forgetProject(path);\n opts.refreshMenu?.();\n return opened;\n }\n if (session !== undefined) opts.close?.(session);\n session = opened.session;\n opts.store.touchProject(opened.root, opened.name);\n invalidateSatellites();\n opts.refreshMenu?.();\n return opened.reply;\n },\n\n isKnownPath(path) {\n const s = opts.store.get();\n // Read `path` off each recent EXPLICITLY rather than filtering the list to\n // whatever looks like a string. The old form did the latter, and when\n // recents became objects in 0.25.0 every entry quietly failed the test and\n // was dropped: no error, no empty list to notice, just a launcher that had\n // stopped recognising every project but the last one. A defensive filter is\n // what turns a shape change into a silent behaviour change, so this one\n // states the shape it wants and lets the compiler enforce it.\n const paths = [s.lastProject, ...s.recents.map((r) => r.path)];\n const known = new Set(paths.filter((p): p is string => !!p).map((p) => resolve(p)));\n return known.has(resolve(path));\n },\n\n addSatellite(satellite) {\n satellites.push(satellite);\n return () => {\n const i = satellites.indexOf(satellite);\n if (i >= 0) satellites.splice(i, 1);\n };\n },\n\n invalidateSatellites,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildwinter/app-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "The shared shell for the editor family (Patterpad, Storylet Studio): the app-agnostic design-token grammar, the per-entity colour hash, and the vanilla-TS DOM primitive. Two palettes, one grammar - each app supplies its own palette/fonts over these tokens.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|