@cossackframework/desktop 0.9.0 → 0.9.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/README.md CHANGED
@@ -15,7 +15,10 @@ import { fileURLToPath } from 'node:url';
15
15
  import { App } from '../App';
16
16
  import { template } from '../root';
17
17
 
18
- export const env = { ...process.env };
18
+ export function createEnv(variables: Record<string, string | undefined> = process.env) {
19
+ return { ...variables };
20
+ }
21
+ export const env = import.meta.env.DEV ? {} : createEnv();
19
22
  export const frameworkApp = createApp({
20
23
  AppComponent: App,
21
24
  htmlTemplate: template,
@@ -40,16 +43,21 @@ if (!import.meta.env.DEV) {
40
43
  ```
41
44
 
42
45
  Do not top-level `await` `createDesktopApp()` in an ESM entry. Electron emits
43
- `ready` after the main module's first event-loop tick; Desktop creation waits
46
+ `ready` after the main module's first event-loop tick. Desktop creation waits
44
47
  for that event. Development calls the exported bootstrap once. Production starts
45
48
  it through the guarded call above.
46
49
 
47
50
  `pnpm desktop:dev` requires Vite 8.1.4 or later in the 8.x series. The CLI
48
51
  supervises Electron, which runs the development module loader and asset server.
49
52
  Pages retain the private origin and native request checks. Source edits reload
50
- managed windows; changes under `src/desktop/`, to the Vite config or root `.env*`
51
- files restart Electron. Reloads do not undo application side effects. Page syntax
52
- errors remain visible and source repair can recover without restarting the CLI.
53
+ managed windows. Changes under `src/desktop/`, to the Vite configuration, or to
54
+ root `.env*` files restart Electron. Reloads do not undo application side effects.
55
+ Development passes only declared bindings: the `env` given to
56
+ `createDesktopApp()` and the bootstrap's `env` export, or the result of an
57
+ exported `createEnv(variables)`, which receives the root `.env*` values for the
58
+ `desktop` mode and the process variables. Other host variables are not exposed.
59
+ Page syntax errors remain visible and source repair can recover without
60
+ restarting the CLI.
53
61
 
54
62
  Keep `ssr.noExternal: true` restricted to production Desktop builds:
55
63
  `mode === 'desktop' && command === 'build'`. Development needs normal external
@@ -57,28 +65,38 @@ package resolution. Do not register another server that exposes native handlers
57
65
  on HTTP. Enable `developmentTraces: true` in `cossackPages()` to use the shared
58
66
  inspector and CLI/MCP capture readers.
59
67
 
68
+ `createDesktopApp()` serves only hashed build output under `/assets/` before
69
+ the application, with `Cache-Control: public, max-age=31536000, immutable` for
70
+ hashed names. A missing `/assets/` file continues to the application. Every
71
+ other request, including `public/` files, goes to the application. The
72
+ framework serves those files from `ASSETS` after global and page policies, with
73
+ `Cache-Control: public, max-age=0, must-revalidate`.
74
+
60
75
  The optional `assets.fetch(request)` provider on `createDesktopApp()` replaces
61
- filesystem asset lookup. A 404 falls through to application dispatch after its
62
- body is canceled. The development runner supplies this provider for Vite assets;
63
- ordinary packaged apps use `assetsRoot`. Native proof headers are stripped
64
- before either provider or application code receives a request.
76
+ filesystem lookup in `assetsRoot`. The runtime asks it for `/assets/*` before
77
+ the application and cancels the body of a 404. It is also the application's
78
+ `ASSETS` binding. The development runner supplies a Vite provider. It sends
79
+ requests for `publicDir` files to the application, so their policies run, and
80
+ lets Vite answer its client and modules first. Ordinary packaged apps use
81
+ `assetsRoot`. Native proof headers are stripped before either provider or
82
+ application code receives a request.
65
83
 
66
84
  `createDesktopApp()` forces context isolation and renderer sandboxing, with Node
67
85
  integration and preload bridges disabled. Only same-origin navigation is
68
- allowed; valid HTTP(S) popups are opened in the operating-system browser.
69
- Desktop pages currently require `@Page({ transport: 'http' })`.
86
+ allowed. Valid HTTP(S) popups are opened in the operating-system browser.
87
+ Desktop pages require `@Page({ transport: 'http' })`.
70
88
 
71
- Use Electron 43.7+ in the 43.x series, or 44.4+. The runtime verifies native
89
+ Use Electron 43.7+ in the 43.x series, or 44.4+. The runtime enforces native
72
90
  request initiators and managed window identity before dispatching local actions.
73
91
  Cossack reserves the `persist:cossack.<identifier>` session and its
74
92
  `onBeforeSendHeaders` hook. Default-session cookies/storage are not migrated.
75
- Keep the identifier stable; native app files retain their existing paths.
93
+ Keep the identifier stable. Native app files retain their existing paths.
76
94
 
77
- On Linux, `desktop:dev` checks Electron's local `chrome-sandbox` helper. pnpm's
95
+ On Linux, `desktop:dev` inspects Electron's local `chrome-sandbox` helper. pnpm's
78
96
  download is normally user-owned rather than root-owned/setuid, so the runner
79
97
  prints a warning and applies Electron's testing-only `--no-sandbox` flag to the
80
98
  development process. Forge packages and installed DEB applications do not use
81
- this fallback; the DEB installs its helper with the required permissions.
99
+ this fallback. The DEB installs its helper with the required permissions.
82
100
  For Wayland sessions that expose XWayland, the development runner selects X11
83
101
  to avoid Chromium's current Wayland/Vulkan incompatibility and hides nonfatal
84
102
  GPU probe noise. Set `COSSACK_DESKTOP_OZONE_PLATFORM=wayland` to force native
@@ -87,13 +105,13 @@ Desktop lifecycle tracing.
87
105
 
88
106
  The generated Linux desktop entry also starts the installed DEB through
89
107
  XWayland so Electron can register its tray with GNOME's StatusNotifier host.
90
- An unpacked Forge executable bypasses that desktop entry; launch it with both
91
- `--no-sandbox` and `--ozone-platform=x11` when testing directly from `out/`.
108
+ An unpacked Forge executable bypasses that desktop entry. Launch it with both
109
+ `--no-sandbox` and `--ozone-platform=x11` when you test it directly from `out/`.
92
110
  The sandbox flag is only appropriate for that uninstalled test package.
93
111
 
94
112
  Node 22 or 24 LTS is recommended for Forge packaging. Node 26 is supported, but
95
113
  the current Forge/Packager ZIP stack can extract Electron pathologically slowly
96
- there; generated Desktop projects declare `node: ">=22"`.
114
+ there. Generated Desktop projects declare `node: ">=22"`.
97
115
 
98
116
  Use Electron APIs in the bootstrap or through ordinary `@Server()` methods via
99
117
  `this.env.COSSACK_DESKTOP`. There is deliberately no renderer client or generic
@@ -123,6 +141,12 @@ const close = configureDesktopClose({
123
141
  });
124
142
  ```
125
143
 
144
+ `desktop.mainWindow` is a live getter. It changes when the main window closes
145
+ while another managed window stays open, and when macOS activation, a second
146
+ instance or `desktop.show()` must create a new window. `desktop.shell` is
147
+ stable and its window methods always target the current main window. A close
148
+ policy applies to the window it was given.
149
+
126
150
  `quit` closes the application, `hide-to-tray` hides only while its tray is
127
151
  alive and otherwise quits, and `confirm-quit` uses an asynchronous native
128
152
  dialog. Linux tray activation varies by desktop host, so prefer
@@ -0,0 +1,7 @@
1
+ /**
2
+ * True when Vite would answer this request with a plain file from `publicDir`.
3
+ * Desktop development sends these requests through the application, so global
4
+ * and page policies run before the file is served, as in production. Vite
5
+ * still answers its client, modules and other requests first.
6
+ */
7
+ export declare function isPublicFileRequest(request: Request, publicDir: string): Promise<boolean>;
@@ -1,9 +1,10 @@
1
- import { a as e, s as t, t as n } from "./src-DHWIBc8l.js";
2
- import { relative as r } from "node:path";
3
- import { createServer as i, isRunnableDevEnvironment as a, loadEnv as o } from "vite";
4
- import { createServer as s } from "node:http";
1
+ import { c as e, o as t, t as n } from "./src-LxY0vJPo.js";
2
+ import { stat as r } from "node:fs/promises";
3
+ import i, { relative as a } from "node:path";
4
+ import { createServer as o, isRunnableDevEnvironment as s, loadEnv as c } from "vite";
5
+ import { createServer as l } from "node:http";
5
6
  //#region src/development-error.ts
6
- function c(e) {
7
+ function u(e) {
7
8
  let t = (e instanceof Error ? e.stack ?? e.message : String(e)).slice(0, 8192).replace(/[&<>"']/g, (e) => ({
8
9
  "&": "&amp;",
9
10
  "<": "&lt;",
@@ -20,8 +21,29 @@ function c(e) {
20
21
  });
21
22
  }
22
23
  //#endregion
24
+ //#region src/development-assets.ts
25
+ var d = /(?:\?|&)import=?(?:&|$)/, f = /(?:\?|&)url(?:&|$)/, p = /^\/@(?:fs\/|id\/|vite\/client|vite\/env)/;
26
+ async function m(e, t) {
27
+ if (!t || e.method !== "GET" && e.method !== "HEAD") return !1;
28
+ let n = new URL(e.url), a = n.pathname + n.search;
29
+ if (d.test(a) || f.test(a) || p.test(n.pathname)) return !1;
30
+ let o;
31
+ try {
32
+ o = decodeURI(n.pathname);
33
+ } catch {
34
+ return !1;
35
+ }
36
+ let s = i.resolve(t), c = i.resolve(s, `.${o}`);
37
+ if (!c.startsWith(s + i.sep)) return !1;
38
+ try {
39
+ return (await r(c)).isFile();
40
+ } catch {
41
+ return !1;
42
+ }
43
+ }
44
+ //#endregion
23
45
  //#region src/development-response.ts
24
- async function l(e, t, n) {
46
+ async function h(e, t, n) {
25
47
  if (e.method !== "GET" || !e.headers.get("accept")?.includes("text/html") || t.headers.get("X-Cossack-Rpc-Response") === "native" || !t.body || !t.headers.get("content-type")?.includes("text/html")) return t;
26
48
  let r = await n(new URL(e.url).pathname, await t.text()), i = new Headers(t.headers);
27
49
  return i.delete("content-length"), new Response(r, {
@@ -32,57 +54,62 @@ async function l(e, t, n) {
32
54
  }
33
55
  //#endregion
34
56
  //#region src/development-runtime.ts
35
- async function u() {
36
- let u, d, f, p, m = !1, h = !1, g = 0, _, v = !1, y = () => {
37
- e.exit(0);
57
+ var g = "/@cossack-desktop/startup-recovered.html";
58
+ async function _() {
59
+ let r, i, d, f, p = !1, _ = !1, v = 0, y, b = !1, x = () => {
60
+ t.exit(0);
38
61
  };
39
- process.once("SIGINT", () => y()), process.once("SIGTERM", () => y()), process.once("disconnect", () => y());
40
- let b = () => {
62
+ process.once("SIGINT", () => x()), process.once("SIGTERM", () => x()), process.once("disconnect", () => x());
63
+ let S = () => {
41
64
  process.connected ? process.send?.({ type: "cossack:desktop-restart" }) : console.error("[desktop] Native configuration changed; restart desktop:dev to apply it.");
42
- }, x = () => m ? Promise.reject(/* @__PURE__ */ Error("Desktop development is closing")) : f ? Promise.resolve(f) : p ??= (async () => {
43
- let e = u.environments.ssr;
44
- if (!a(e)) throw Error("Desktop requires a runnable Vite SSR environment");
45
- for (; !m;) {
46
- let t = g;
47
- h &&= (e.moduleGraph.invalidateAll(), e.runner.clearCache(), !1);
65
+ }, C = () => p ? Promise.reject(/* @__PURE__ */ Error("Desktop development is closing")) : d ? Promise.resolve(d) : f ??= (async () => {
66
+ let e = r.environments.ssr;
67
+ if (!s(e)) throw Error("Desktop requires a runnable Vite SSR environment");
68
+ for (; !p;) {
69
+ let t = v;
70
+ _ &&= (e.moduleGraph.invalidateAll(), e.runner.clearCache(), !1);
48
71
  let n = await e.runner.import("/src/desktop/index.ts");
49
72
  if (typeof n.startDesktop != "function" || typeof n.frameworkApp?.fetch != "function") throw TypeError("Desktop entry must export startDesktop(factory) and frameworkApp.fetch. Apply the Desktop bootstrap migration.");
50
- if (t === g) return f = n, n;
73
+ let r = (n.createEnv ? await n.createEnv(k) : n.env) ?? {};
74
+ if (t === v) return d = {
75
+ entry: n,
76
+ env: r
77
+ }, d;
51
78
  }
52
79
  throw Error("Desktop development is closing");
53
80
  })().finally(() => {
54
- p = void 0;
55
- }), S = (e) => u.config.logger.error(`[desktop] ${e instanceof Error ? e.stack : e}`), C = {
81
+ f = void 0;
82
+ }), w = (e) => r.config.logger.error(`[desktop] ${e instanceof Error ? e.stack : e}`), T = {
56
83
  name: "cossack-desktop-development",
57
84
  enforce: "post",
58
85
  hotUpdate({ file: e }) {
59
- let t = r(u.config.root, e).replaceAll("\\", "/");
60
- if (!(!(t.startsWith("src/") && /\.(?:[cm]?[jt]sx?|mdx?)$/.test(t)) && !u.environments.ssr.moduleGraph.getModulesByFile(e)?.size)) return this.environment.name === "ssr" ? t.startsWith("src/desktop/") ? (b(), []) : (f = void 0, h = !0, g++, (d ? x().then(() => {
86
+ let t = a(r.config.root, e).replaceAll("\\", "/");
87
+ if (!(!(t.startsWith("src/") && /\.(?:[cm]?[jt]sx?|mdx?)$/.test(t)) && !r.environments.ssr.moduleGraph.getModulesByFile(e)?.size)) return this.environment.name === "ssr" ? t.startsWith("src/desktop/") ? (S(), []) : (d = void 0, _ = !0, v++, (i ? C().then(() => {
61
88
  for (let e of n.getAllWindows()) e.webContents.getURL().startsWith("cossack://app/") && e.webContents.reload();
62
- }) : j()).catch(S), []) : [];
89
+ }) : N()).catch(w), []) : [];
63
90
  }
64
- }, w = s((e, t) => {
65
- u ? u.middlewares(e, t) : t.writeHead(503).end();
91
+ }, E = l((e, t) => {
92
+ r ? r.middlewares(e, t) : t.writeHead(503).end();
66
93
  });
67
94
  await new Promise((e, t) => {
68
- w.once("error", t), w.listen(0, "127.0.0.1", e);
95
+ E.once("error", t), E.listen(0, "127.0.0.1", e);
69
96
  });
70
- let T = w.address();
71
- if (!T || typeof T == "string") throw Error("Desktop development could not bind its asset server");
72
- let E = `http://127.0.0.1:${T.port}`;
73
- u = await i({
97
+ let D = E.address();
98
+ if (!D || typeof D == "string") throw Error("Desktop development could not bind its asset server");
99
+ let O = `http://127.0.0.1:${D.port}`;
100
+ r = await o({
74
101
  root: process.cwd(),
75
102
  mode: "desktop",
76
103
  appType: "custom",
77
- plugins: [C],
104
+ plugins: [T],
78
105
  server: {
79
106
  host: "127.0.0.1",
80
107
  middlewareMode: !0,
81
108
  ws: {
82
- server: w,
109
+ server: E,
83
110
  host: "127.0.0.1",
84
111
  protocol: "ws",
85
- clientPort: T.port
112
+ clientPort: D.port
86
113
  }
87
114
  },
88
115
  environments: { ssr: { resolve: {
@@ -94,17 +121,17 @@ async function u() {
94
121
  ]
95
122
  } } }
96
123
  });
97
- let D = {
98
- ...o(u.config.mode, u.config.envDir, ""),
124
+ let k = {
125
+ ...c(r.config.mode, r.config.envDir, ""),
99
126
  ...process.env
100
- }, O = (e) => {
101
- let t = r(u.config.root, e).replaceAll("\\", "/");
102
- (e === u.config.configFile || /^\.env(?:\.[^/]+)?$/.test(t)) && b();
127
+ }, A = (e) => {
128
+ let t = a(r.config.root, e).replaceAll("\\", "/");
129
+ (e === r.config.configFile || /^\.env(?:\.[^/]+)?$/.test(t)) && S();
103
130
  };
104
- u.watcher.on("change", O).on("add", O).on("unlink", O);
105
- let k = { async fetch(e) {
131
+ r.watcher.on("change", A).on("add", A).on("unlink", A);
132
+ let j = { async fetch(e) {
106
133
  if (e.method !== "GET" && e.method !== "HEAD") return new Response(null, { status: 404 });
107
- let t = new URL(e.url), n = await fetch(E + t.pathname + t.search, {
134
+ let t = new URL(e.url), n = await fetch(O + t.pathname + t.search, {
108
135
  method: e.method,
109
136
  signal: e.signal
110
137
  }), r = new Headers(n.headers);
@@ -113,49 +140,57 @@ async function u() {
113
140
  statusText: n.statusText,
114
141
  headers: r
115
142
  });
116
- } }, A = (e) => t({
117
- ...e,
118
- assets: k,
143
+ } }, M = (t) => e({
144
+ ...t,
145
+ assets: j,
119
146
  fetch: async (e, t) => {
147
+ let n = await m(e, r.config.publicDir);
148
+ if (!n) {
149
+ let t = await j.fetch(e);
150
+ if (t.status !== 404) return t;
151
+ await t.body?.cancel();
152
+ }
120
153
  try {
121
- let n = await x();
122
- return await l(e, await n.frameworkApp.fetch(e, {
154
+ let { entry: i, env: a } = await C(), o = await i.frameworkApp.fetch(e, {
123
155
  ...t,
124
- ...D,
125
- ...n.env,
156
+ ...a,
126
157
  ASSETS: t?.ASSETS,
127
158
  COSSACK_DESKTOP: t?.COSSACK_DESKTOP
128
- }), (e, t) => u.transformIndexHtml(e, t));
159
+ });
160
+ return n ? o : await h(e, o, (e, t) => r.transformIndexHtml(e, t));
129
161
  } catch (e) {
130
- return S(e), c(e);
162
+ return w(e), u(e);
131
163
  }
132
164
  }
133
165
  });
134
- function j() {
135
- return _ ??= x().then(async (e) => {
136
- !m && !d && (v && u.ws.send({ type: "full-reload" }), v = !1, d = await e.startDesktop(A), console.log(`[desktop] Development ready at cossack://app (assets ${E})`));
166
+ function N() {
167
+ return y ??= C().then(async ({ entry: e }) => {
168
+ !p && !i && (b && r.ws.send({
169
+ type: "full-reload",
170
+ path: g
171
+ }), b = !1, i = await e.startDesktop(M), console.log(`[desktop] Development ready at cossack://app (assets ${O})`));
137
172
  }).catch((e) => {
138
- throw v = !0, e;
173
+ throw b = !0, e;
139
174
  }).finally(() => {
140
- _ = void 0;
175
+ y = void 0;
141
176
  });
142
177
  }
143
- let M, N = () => M ??= (async () => {
144
- m = !0;
145
- let t = setTimeout(() => e.exit(1), 5e3);
178
+ let P, F = () => P ??= (async () => {
179
+ p = !0;
180
+ let e = setTimeout(() => t.exit(1), 5e3);
146
181
  try {
147
- await u.close(), w.closeAllConnections(), await new Promise((e) => w.close(() => e())), e.exit(0);
182
+ await r.close(), E.closeAllConnections(), await new Promise((e) => E.close(() => e())), t.exit(0);
148
183
  } finally {
149
- clearTimeout(t);
184
+ clearTimeout(e);
150
185
  }
151
186
  })();
152
- e.on("before-quit", (e) => {
153
- e.preventDefault(), N();
154
- }), y = () => {
155
- N();
156
- }, await j().catch(S);
187
+ t.on("before-quit", (e) => {
188
+ e.preventDefault(), F();
189
+ }), x = () => {
190
+ F();
191
+ }, await N().catch(w);
157
192
  }
158
- u().catch((t) => {
159
- console.error("[desktop] Development startup failed", t), e.exit(1);
193
+ _().catch((e) => {
194
+ console.error("[desktop] Development startup failed", e), t.exit(1);
160
195
  });
161
196
  //#endregion
package/dist/index.d.ts CHANGED
@@ -21,8 +21,14 @@ export type SafeBrowserWindowOptions = Omit<BrowserWindowConstructorOptions, 'we
21
21
  export interface CreateDesktopAppOptions {
22
22
  identifier: string;
23
23
  productName: string;
24
+ /** Client build output (`dist/client`), read when `assets` is not given. */
24
25
  assetsRoot: string;
25
- /** Optional asset provider. Return 404 to continue to the application router. */
26
+ /**
27
+ * Optional asset provider that replaces filesystem lookup in `assetsRoot`.
28
+ * It answers hashed build output under `/assets/` before the application,
29
+ * and it is the application's `ASSETS` binding, which serves every other
30
+ * file after global and page policies. Return 404 for a missing file.
31
+ */
26
32
  assets?: {
27
33
  fetch(request: Request): Response | Promise<Response>;
28
34
  };
@@ -30,12 +36,24 @@ export interface CreateDesktopAppOptions {
30
36
  env?: Record<string, unknown>;
31
37
  startPath?: string;
32
38
  window?: SafeBrowserWindowOptions;
39
+ /**
40
+ * Electron permissions the app's own pages may use besides the defaults
41
+ * (`DESKTOP_DEFAULT_PERMISSIONS`: copying to the clipboard and fullscreen),
42
+ * such as `media` (camera and microphone), `geolocation` or `notifications`.
43
+ * Every other permission request and check is denied, and so is any request
44
+ * from a page outside `cossack://app`.
45
+ */
46
+ permissions?: readonly string[];
33
47
  }
34
48
  export interface CreateDesktopWindowOptions extends SafeBrowserWindowOptions {
35
49
  path?: string;
36
50
  }
37
51
  export interface DesktopShell {
38
52
  readonly app: typeof app;
53
+ /**
54
+ * The window this shell controls. For `DesktopApplication.shell` it always
55
+ * resolves to the application's current main window.
56
+ */
39
57
  readonly window: BrowserWindow;
40
58
  readonly Menu: typeof Menu;
41
59
  readonly Tray: typeof Tray;
@@ -53,7 +71,13 @@ export interface DesktopShell {
53
71
  }
54
72
  export interface DesktopApplication {
55
73
  readonly app: typeof app;
74
+ /**
75
+ * The current main window. It is replaced when the main window closes while
76
+ * another managed window stays open, and when activation (macOS) or a second
77
+ * instance needs a new window. Read it when needed instead of caching it.
78
+ */
56
79
  readonly mainWindow: BrowserWindow;
80
+ /** A stable shell whose window methods always target the current main window. */
57
81
  readonly shell: DesktopShell;
58
82
  readonly quitting: boolean;
59
83
  createWindow(options?: CreateDesktopWindowOptions): BrowserWindow;
@@ -89,4 +113,11 @@ export declare function createDesktopShell(options?: {
89
113
  window?: BrowserWindow;
90
114
  }): DesktopShell;
91
115
  /** Initialize the process-wide Desktop application exactly once. */
116
+ /**
117
+ * Permissions every app page has without naming them: writing to the clipboard
118
+ * (copy buttons) and fullscreen (video, `requestFullscreen`). Opening external
119
+ * protocol handlers (`openExternal`) is not among them: http(s) links already
120
+ * open in the browser, and other schemes need the app to name it.
121
+ */
122
+ export declare const DESKTOP_DEFAULT_PERMISSIONS: readonly string[];
92
123
  export declare function createDesktopApp(options: CreateDesktopAppOptions): Promise<DesktopApplication>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, h as i, i as a, l as o, m as s, n as c, o as l, p as u, r as d, s as f, t as p, u as m } from "./src-DHWIBc8l.js";
2
- export { p as BrowserWindow, i as DesktopUnavailableError, c as Menu, d as Notification, a as Tray, e as app, l as configureDesktopClose, f as createDesktopApp, t as createDesktopShell, o as createDesktopTray, m as dialog, n as electronRuntimeAdapter, r as electronShell, r as shell, u as nativeImage, s as protocol };
1
+ import { a as e, c as t, d as n, f as r, g as i, h as a, i as o, l as s, m as c, n as l, o as u, p as d, r as f, s as p, t as m, u as h } from "./src-LxY0vJPo.js";
2
+ export { m as BrowserWindow, l as DESKTOP_DEFAULT_PERMISSIONS, i as DesktopUnavailableError, f as Menu, o as Notification, e as Tray, u as app, p as configureDesktopClose, t as createDesktopApp, s as createDesktopShell, h as createDesktopTray, n as dialog, r as electronRuntimeAdapter, d as electronShell, d as shell, c as nativeImage, a as protocol };
@@ -19,25 +19,29 @@ function u(e, t, n) {
19
19
  if (!(i !== null && i !== "cossack://app")) return r.set(s, String(e.webContentsId)), r.set(c, n), Object.fromEntries(r);
20
20
  }
21
21
  //#endregion
22
+ //#region ../core/dist/shared/static-assets.js
23
+ var d = "assets";
24
+ Object.freeze(["/*", `!/${d}/*`]);
25
+ //#endregion
22
26
  //#region src/error.ts
23
- var d = class extends Error {
27
+ var f = class extends Error {
24
28
  constructor() {
25
29
  super("@cossackframework/desktop can only create applications and shells in the Electron main process."), this.name = "DesktopUnavailableError";
26
30
  }
27
- }, f = typeof o == "object" && o ? o : {}, { app: p, BrowserWindow: m, dialog: h, Menu: g, nativeImage: _, Notification: v, protocol: y, shell: b, Tray: x } = f, S = {
31
+ }, p = typeof o == "object" && o ? o : {}, { app: m, BrowserWindow: h, dialog: g, Menu: _, nativeImage: v, Notification: y, protocol: b, shell: x, Tray: S } = p, C = {
28
32
  name: "electron",
29
33
  supportedTransports: ["http"],
30
34
  getClientMetadata: () => ({
31
35
  platform: "desktop",
32
36
  adapter: "electron"
33
37
  })
34
- }, C = "cossack", w = "cossack://app", T = !1, E, D = 0;
35
- function O(e) {
38
+ }, w = "cossack", T = "cossack://app", E = !1, D, O = 0;
39
+ function k(e) {
36
40
  process.env.COSSACK_DESKTOP_DEBUG === "1" && console.error(`[Cossack Desktop] ${e}`);
37
41
  }
38
- function k() {
39
- T || y?.registerSchemesAsPrivileged && (y.registerSchemesAsPrivileged([{
40
- scheme: C,
42
+ function A() {
43
+ E || b?.registerSchemesAsPrivileged && (b.registerSchemesAsPrivileged([{
44
+ scheme: w,
41
45
  privileges: {
42
46
  standard: !0,
43
47
  secure: !0,
@@ -45,15 +49,15 @@ function k() {
45
49
  corsEnabled: !0,
46
50
  stream: !0
47
51
  }
48
- }]), T = !0);
52
+ }]), E = !0);
49
53
  }
50
- k();
51
- function A() {
52
- if (!process.versions.electron || process.type === "renderer" || !p || !m) throw new d();
54
+ A();
55
+ function j() {
56
+ if (!process.versions.electron || process.type === "renderer" || !m || !h) throw new f();
53
57
  let [e, t] = process.versions.electron.split(".").map(Number);
54
58
  if (e < 43 || e === 43 && t < 7 || e === 44 && t < 4) throw Error("Cossack Desktop requires Electron 43.7+ or 44.4+ for native request initiator verification.");
55
59
  }
56
- function j(e, n) {
60
+ function M(e, n) {
57
61
  if (process.platform !== "linux") return;
58
62
  let r = `org.freedesktop.StatusNotifierItem-${process.pid}-${n}`;
59
63
  setTimeout(() => {
@@ -66,29 +70,29 @@ function j(e, n) {
66
70
  "org.kde.StatusNotifierWatcher.RegisterStatusNotifierItem",
67
71
  `string:${r}`
68
72
  ], { timeout: 2e3 }, (e) => {
69
- e && O(`could not repair Linux tray registration: ${e.message}`);
73
+ e && k(`could not repair Linux tray registration: ${e.message}`);
70
74
  });
71
75
  }, 4e3).unref();
72
76
  }
73
- function M(e) {
74
- A();
75
- let t = ++D, n = e.guid ? new x(e.image, e.guid) : new x(e.image);
76
- return e.toolTip && n.setToolTip(e.toolTip), e.menu !== void 0 && n.setContextMenu(e.menu), j(n, t), n;
77
- }
78
77
  function N(e) {
79
- A();
80
- let t = e.window ?? m.getFocusedWindow() ?? m.getAllWindows()[0];
81
- if (!t) throw new d();
78
+ j();
79
+ let t = ++O, n = e.guid ? new S(e.image, e.guid) : new S(e.image);
80
+ return e.toolTip && n.setToolTip(e.toolTip), e.menu !== void 0 && n.setContextMenu(e.menu), M(n, t), n;
81
+ }
82
+ function P(e) {
83
+ j();
84
+ let t = e.window ?? h.getFocusedWindow() ?? h.getAllWindows()[0];
85
+ if (!t) throw new f();
82
86
  if (e.behavior === "hide-to-tray" && !e.tray) throw TypeError("Desktop hide-to-tray behavior requires a tray.");
83
87
  let n = !1, r = !1, i = !1, a = () => {
84
88
  r = !0;
85
89
  }, o = () => {
86
- r || (r = !0, (e.onQuit ?? (() => p.quit()))());
90
+ r || (r = !0, (e.onQuit ?? (() => m.quit()))());
87
91
  }, s = {
88
92
  behavior: e.behavior,
89
93
  quit: o,
90
94
  dispose() {
91
- n || (n = !0, t.removeListener("close", c), p.removeListener("before-quit", a));
95
+ n || (n = !0, t.removeListener("close", c), m.removeListener("before-quit", a));
92
96
  }
93
97
  }, c = (a) => {
94
98
  if (n || r) return;
@@ -102,8 +106,8 @@ function N(e) {
102
106
  }
103
107
  if (i) return;
104
108
  i = !0;
105
- let s = p.getName();
106
- h.showMessageBox(t, {
109
+ let s = m.getName();
110
+ g.showMessageBox(t, {
107
111
  type: "question",
108
112
  title: s,
109
113
  message: `Quit ${s}?`,
@@ -120,9 +124,9 @@ function N(e) {
120
124
  i = !1;
121
125
  });
122
126
  };
123
- return t.on("close", c), p.on("before-quit", a), s;
127
+ return t.on("close", c), m.on("before-quit", a), s;
124
128
  }
125
- function P(e) {
129
+ function F(e) {
126
130
  let t;
127
131
  try {
128
132
  t = decodeURIComponent(e);
@@ -133,12 +137,12 @@ function P(e) {
133
137
  if (t.split("/").includes("..")) throw URIError("Desktop URL traversal is not allowed.");
134
138
  return t.replace(/^\/+/, "");
135
139
  }
136
- function F(e, t) {
140
+ function I(e, t) {
137
141
  let n = a.resolve(e), r = a.resolve(n, t || "__cossack_ssr__"), i = a.relative(n, r);
138
142
  if (i.startsWith("..") || a.isAbsolute(i)) throw URIError("Desktop URL traversal is not allowed.");
139
143
  return r;
140
144
  }
141
- var I = {
145
+ var L = {
142
146
  ".css": "text/css; charset=utf-8",
143
147
  ".gif": "image/gif",
144
148
  ".html": "text/html; charset=utf-8",
@@ -156,34 +160,46 @@ var I = {
156
160
  ".webp": "image/webp",
157
161
  ".woff": "font/woff",
158
162
  ".woff2": "font/woff2"
159
- };
160
- async function L(e, t) {
163
+ }, R = `${d}/`, z = /\.[a-zA-Z0-9_-]{8,}\.[^/]+$/;
164
+ function B(e) {
165
+ return e.method !== "GET" && e.method !== "HEAD" ? !1 : F(new URL(e.url).pathname).startsWith(R);
166
+ }
167
+ function V(e) {
168
+ return e.startsWith(R) && z.test(e) ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate";
169
+ }
170
+ async function H(e, t) {
161
171
  if (t.method !== "GET" && t.method !== "HEAD") return;
162
- let o = P(new URL(t.url).pathname);
172
+ let o = F(new URL(t.url).pathname);
163
173
  if (!o) return;
164
- let s = F(e, o);
174
+ let s = I(e, o);
165
175
  try {
166
- let [o, c] = await Promise.all([r(e), r(s)]), l = a.relative(o, c);
167
- if (l === ".." || l.startsWith(`..${a.sep}`) || a.isAbsolute(l)) return;
168
- let u = await i(c);
169
- if (!u.isFile()) return;
170
- let d = new Headers({
171
- "content-type": I[a.extname(s).toLowerCase()] ?? "application/octet-stream",
172
- "content-length": String(u.size)
176
+ let [c, l] = await Promise.all([r(e), r(s)]), u = a.relative(c, l);
177
+ if (u === ".." || u.startsWith(`..${a.sep}`) || a.isAbsolute(u)) return;
178
+ let d = await i(l);
179
+ if (!d.isFile()) return;
180
+ let f = new Headers({
181
+ "content-type": L[a.extname(s).toLowerCase()] ?? "application/octet-stream",
182
+ "content-length": String(d.size),
183
+ "cache-control": V(o)
173
184
  });
174
- return new Response(t.method === "HEAD" ? null : await n(c), { headers: d });
185
+ return new Response(t.method === "HEAD" ? null : await n(l), { headers: f });
175
186
  } catch (e) {
176
187
  if (e.code === "ENOENT" || e.code === "ENOTDIR") return;
177
188
  throw e;
178
189
  }
179
190
  }
180
- function R(e) {
191
+ function U(e) {
181
192
  let t = new URL(e.url), n = new URL(`${t.pathname}${t.search}`, "https://app");
182
193
  n.searchParams.delete("__cossack_window");
183
194
  let r = new Request(n, e);
184
195
  return r.headers.delete(s), r.headers.delete(c), r.headers.set("origin", n.origin), r;
185
196
  }
186
- function z(e = {}) {
197
+ var W = /* @__PURE__ */ new Set([s, c]);
198
+ function G(e) {
199
+ let t = Object.entries(e), n = t.filter(([e]) => !W.has(e.toLowerCase()));
200
+ return n.length === t.length ? {} : { requestHeaders: Object.fromEntries(n) };
201
+ }
202
+ function K(e = {}) {
187
203
  let { webPreferences: t, ...n } = e;
188
204
  return {
189
205
  width: 1e3,
@@ -204,143 +220,171 @@ function z(e = {}) {
204
220
  }
205
221
  };
206
222
  }
207
- function B(e) {
223
+ function q(e) {
208
224
  e.webContents.on("will-navigate", (e, t) => {
209
225
  try {
210
226
  let n = new URL(t);
211
- l(n) || (e.preventDefault(), (n.protocol === "https:" || n.protocol === "http:") && b.openExternal(n.href));
227
+ l(n) || (e.preventDefault(), (n.protocol === "https:" || n.protocol === "http:") && x.openExternal(n.href));
212
228
  } catch {
213
229
  e.preventDefault();
214
230
  }
215
231
  }), e.webContents.setWindowOpenHandler(({ url: e }) => {
216
232
  try {
217
233
  let t = new URL(e);
218
- (t.protocol === "https:" || t.protocol === "http:") && b.openExternal(t.href);
234
+ (t.protocol === "https:" || t.protocol === "http:") && x.openExternal(t.href);
219
235
  } catch {}
220
236
  return { action: "deny" };
221
237
  });
222
238
  }
223
- function V(e = {}) {
224
- A();
225
- let t = e.window ?? m.getFocusedWindow() ?? m.getAllWindows()[0];
226
- if (!t) throw new d();
239
+ function J(e = {}) {
240
+ j();
241
+ let t = e.window ?? h.getFocusedWindow() ?? h.getAllWindows()[0];
242
+ if (!t) throw new f();
243
+ return Y(() => t);
244
+ }
245
+ function Y(e) {
227
246
  return {
228
- app: p,
229
- window: t,
230
- Menu: g,
231
- Tray: x,
232
- dialog: h,
233
- Notification: v,
234
- nativeImage: _,
235
- shell: b,
247
+ app: m,
248
+ get window() {
249
+ return e();
250
+ },
251
+ Menu: _,
252
+ Tray: S,
253
+ dialog: g,
254
+ Notification: y,
255
+ nativeImage: v,
256
+ shell: x,
236
257
  get dock() {
237
- return p.dock;
258
+ return m.dock;
238
259
  },
239
260
  show() {
240
- t.show();
261
+ e().show();
241
262
  },
242
263
  hide() {
243
- t.hide();
264
+ e().hide();
244
265
  },
245
266
  focus() {
246
- t.focus();
267
+ e().focus();
247
268
  },
248
269
  quit() {
249
- p.quit();
270
+ m.quit();
250
271
  },
251
272
  setBadge(e) {
252
- return p.setBadgeCount(e === null ? 0 : typeof e == "number" ? e : Number(e) || 0);
273
+ return m.setBadgeCount(e === null ? 0 : typeof e == "number" ? e : Number(e) || 0);
253
274
  },
254
- setOverlayIcon(e, n = "") {
255
- t.setOverlayIcon(e, n);
275
+ setOverlayIcon(t, n = "") {
276
+ e().setOverlayIcon(t, n);
256
277
  }
257
278
  };
258
279
  }
259
- async function H(t) {
260
- if (A(), O("initializing Electron application"), !t.identifier.trim()) throw TypeError("Desktop identifier is required.");
280
+ async function X(t) {
281
+ if (j(), k("initializing Electron application"), !t.identifier.trim()) throw TypeError("Desktop identifier is required.");
261
282
  if (!t.productName.trim()) throw TypeError("Desktop productName is required.");
262
- let n = a.resolve(t.assetsRoot), r = `/${(t.startPath ?? "/").replace(/^\/+/, "")}`, i = !1, o;
263
- p.setName(t.productName), process.platform === "linux" && p.commandLine.appendSwitch("class", t.identifier), process.platform === "win32" && p.setAppUserModelId(t.identifier), O("requesting single-instance lock");
264
- let d = p.requestSingleInstanceLock();
265
- if (O(`single-instance lock ${d ? "acquired" : "unavailable"}`), !d) throw p.quit(), Error(`[Cossack] Another ${t.productName} instance is already running.`);
266
- await p.whenReady(), O("Electron app is ready");
267
- let h = f.session.fromPartition(`persist:cossack.${t.identifier}`), g = /* @__PURE__ */ new Map(), _ = e();
268
- h.webRequest.onBeforeSendHeaders((e, t) => {
269
- if (!e.url.startsWith(`${C}:`)) {
270
- let n = new Headers(e.requestHeaders);
271
- n.delete(s), n.delete(c), t({ requestHeaders: Object.fromEntries(n) });
283
+ let n = a.resolve(t.assetsRoot), r = `/${(t.startPath ?? "/").replace(/^\/+/, "")}`, i = !1, o, c = !1;
284
+ m.setName(t.productName), process.platform === "linux" && m.commandLine.appendSwitch("class", t.identifier), process.platform === "win32" && m.setAppUserModelId(t.identifier), k("requesting single-instance lock");
285
+ let d = m.requestSingleInstanceLock();
286
+ if (k(`single-instance lock ${d ? "acquired" : "unavailable"}`), !d) throw m.quit(), Error(`[Cossack] Another ${t.productName} instance is already running.`);
287
+ await m.whenReady(), k("Electron app is ready");
288
+ let f = p.session.fromPartition(`persist:cossack.${t.identifier}`), g = /* @__PURE__ */ new Map(), _ = e(), v = /* @__PURE__ */ new Set([...Z, ...t.permissions ?? []]), y = (e) => {
289
+ try {
290
+ return e !== void 0 && l(new URL(e));
291
+ } catch {
292
+ return !1;
293
+ }
294
+ };
295
+ f.setPermissionRequestHandler((e, t, n, r) => {
296
+ let i = v.has(t) && g.has(e?.id ?? -1) && y(r?.requestingUrl ?? e?.getURL());
297
+ i || k(`denied permission ${t}`), n(i);
298
+ }), f.setPermissionCheckHandler((e, t, n) => v.has(t) && g.has(e?.id ?? -1) && y(n)), f.webRequest.onBeforeSendHeaders((e, t) => {
299
+ if (!e.url.startsWith(`${w}:`)) {
300
+ t(G(e.requestHeaders));
272
301
  return;
273
302
  }
274
303
  let n = u(e, g.has(e.webContentsId ?? -1), _);
275
- n || O(`rejected ${e.resourceType} from ${e.initiatorOrigin ?? "browser"} (owned: ${g.has(e.webContentsId ?? -1)})`), t(n ? { requestHeaders: n } : { cancel: !0 });
304
+ n || k(`rejected ${e.resourceType} from ${e.initiatorOrigin ?? "browser"} (owned: ${g.has(e.webContentsId ?? -1)})`), t(n ? { requestHeaders: n } : { cancel: !0 });
276
305
  });
277
- let v = (e = {}) => {
278
- let { path: n = r, ...i } = e, a = new URL(n, `${w}/`);
306
+ let b = (e = {}) => {
307
+ let { path: n = r, ...i } = e, a = new URL(n, `${T}/`);
279
308
  if (!l(a)) throw TypeError("Desktop window paths must stay within cossack://app.");
280
- let o = z({
309
+ let o = K({
281
310
  ...t.window,
282
311
  ...i
283
- }), s = new m({
312
+ }), s = new h({
284
313
  ...o,
285
314
  webPreferences: {
286
315
  ...o.webPreferences,
287
- session: h
316
+ session: f
288
317
  }
289
318
  }), c = s.webContents.id;
290
- return g.set(c, s), s.once("closed", () => g.delete(c)), O(`created BrowserWindow ${s.id}`), B(s), s.loadURL(a.href).then(() => O(`loaded ${a.href}`), (e) => console.error(`[Cossack Desktop] Failed to load ${a.href}`, e)), s.once("ready-to-show", () => s.show()), s;
291
- };
292
- await h.protocol.handle(C, async (e) => {
293
- O(`handling ${e.method} ${e.url}`);
294
- let r;
319
+ return g.set(c, s), s.once("closed", () => g.delete(c)), k(`created BrowserWindow ${s.id}`), q(s), s.loadURL(a.href).then(() => k(`loaded ${a.href}`), (e) => console.error(`[Cossack Desktop] Failed to load ${a.href}`, e)), s.once("ready-to-show", () => s.show()), s;
320
+ }, x = { fetch: async (e) => await H(n, e) ?? new Response("Not found", { status: 404 }) };
321
+ await f.protocol.handle(w, async (e) => {
322
+ k(`handling ${e.method} ${e.url}`);
323
+ let n;
295
324
  try {
296
- if (r = new URL(e.url), !l(r)) return new Response("Forbidden Desktop authority", { status: 403 });
325
+ if (n = new URL(e.url), !l(n)) return new Response("Forbidden Desktop authority", { status: 403 });
297
326
  let t = e.headers.get("origin");
298
- if (t && t !== w) return new Response("Forbidden Desktop origin", { status: 403 });
299
- P(r.pathname);
300
- let n = e.headers.get("referer");
301
- if (!l(new URL(n || e.url))) return new Response("Forbidden Desktop authority", { status: 403 });
327
+ if (t && t !== T) return new Response("Forbidden Desktop origin", { status: 403 });
328
+ F(n.pathname);
329
+ let r = e.headers.get("referer");
330
+ if (!l(new URL(r || e.url))) return new Response("Forbidden Desktop authority", { status: 403 });
302
331
  } catch {
303
332
  return new Response("Invalid Desktop URL", { status: 400 });
304
333
  }
305
- let i = e.headers.get(s), a = i === null ? void 0 : g.get(Number(i));
306
- if (e.headers.get("x-cossack-desktop-token") !== _ || !a) return new Response("Unverified Desktop request", { status: 403 });
307
- let o = V({ window: a }), c = R(e), u = t.assets ?? { fetch: async (e) => await L(n, e) ?? new Response("Not found", { status: 404 }) }, d = await u.fetch(c);
308
- return d.status === 404 ? (await d.body?.cancel(), t.fetch(c, {
334
+ let r = e.headers.get(s), i = r === null ? void 0 : g.get(Number(r));
335
+ if (e.headers.get("x-cossack-desktop-token") !== _ || !i) return new Response("Unverified Desktop request", { status: 403 });
336
+ let a = J({ window: i }), o = U(e), c = t.assets ?? x;
337
+ if (B(o)) {
338
+ let e = await c.fetch(o);
339
+ if (e.status !== 404) return e;
340
+ await e.body?.cancel();
341
+ }
342
+ return t.fetch(o, {
309
343
  ...t.env ?? {},
310
- ASSETS: u,
311
- COSSACK_DESKTOP: o
312
- })) : d;
313
- }), O("registered cossack:// protocol handler"), o = v();
314
- let y = V({ window: o }), b = {
315
- app: p,
316
- mainWindow: o,
317
- shell: y,
344
+ ASSETS: c,
345
+ COSSACK_DESKTOP: a
346
+ });
347
+ }), k("registered cossack:// protocol handler");
348
+ let S = (e) => (o = e, c = !0, e.once("closed", () => {
349
+ if (o !== e) return;
350
+ let t = g.values().next().value;
351
+ t ? S(t) : c = !1;
352
+ }), e), C = () => c ? o : S(b());
353
+ S(b());
354
+ let E = {
355
+ app: m,
356
+ get mainWindow() {
357
+ return o;
358
+ },
359
+ shell: Y(() => o),
318
360
  get quitting() {
319
361
  return i;
320
362
  },
321
- createWindow: v,
363
+ createWindow: b,
322
364
  show() {
323
- o.show(), o.focus();
365
+ let e = C();
366
+ e.show(), e.focus();
324
367
  },
325
368
  hide() {
326
- o.hide();
369
+ c && o.hide();
327
370
  },
328
371
  quit() {
329
- i = !0, p.quit();
372
+ i = !0, m.quit();
330
373
  }
331
374
  };
332
- return p.on("before-quit", () => {
375
+ return m.on("before-quit", () => {
333
376
  i = !0;
334
- }), p.on("activate", () => {
335
- m.getAllWindows().length === 0 ? o = v() : b.show();
336
- }), p.on("second-instance", () => b.show()), process.on("message", (e) => {
337
- if (e?.type === "cossack:renderer-reload") for (let e of m.getAllWindows()) e.webContents.reloadIgnoringCache();
338
- }), b;
377
+ }), m.on("activate", () => {
378
+ h.getAllWindows().length === 0 ? S(b()) : E.show();
379
+ }), m.on("second-instance", () => E.show()), process.on("message", (e) => {
380
+ if (e?.type === "cossack:renderer-reload") for (let e of h.getAllWindows()) e.webContents.reloadIgnoringCache();
381
+ }), E;
339
382
  }
340
- function U(e) {
341
- return A(), E ??= H(e).catch((e) => {
342
- throw E = void 0, e;
383
+ var Z = ["clipboard-sanitized-write", "fullscreen"];
384
+ function Q(e) {
385
+ return j(), D ??= X(e).catch((e) => {
386
+ throw D = void 0, e;
343
387
  });
344
388
  }
345
389
  //#endregion
346
- export { p as a, V as c, S as d, b as f, d as h, x as i, M as l, y as m, g as n, N as o, _ as p, v as r, U as s, m as t, h as u };
390
+ export { S as a, Q as c, g as d, C as f, f as g, b as h, y as i, J as l, v as m, Z as n, m as o, x as p, _ as r, P as s, h as t, N as u };
package/docs/guide.md CHANGED
@@ -15,18 +15,21 @@ Electron unless the application supplies an Electron-compatible equivalent.
15
15
 
16
16
  `createDesktopApp()` registers and serves `cossack://app`, injects `ASSETS` and
17
17
  a window-scoped `COSSACK_DESKTOP`, and starts a sandboxed, context-isolated
18
- `BrowserWindow`. Use only HTTP-transport pages. Native work belongs in the
19
- bootstrap or ordinary `@Server()` methods:
18
+ `BrowserWindow`. It serves hashed `/assets/*` build output directly. Every
19
+ other file, including `public/`, reaches the application, so global and page
20
+ policies run first. `desktop:dev` applies those policies to `public/` files too,
21
+ while Vite answers its client and modules first. Use only HTTP-transport pages.
22
+ Native work belongs in the bootstrap or ordinary `@Server()` methods:
20
23
 
21
24
  Keep the generated `frameworkApp`, `env` and `startDesktop(factory)` exports.
22
25
  Use the supplied factory to create the application and return its Desktop result.
23
26
  Put native menus, tray and close handlers inside that bootstrap. The development
24
- runner calls it once; only production calls it at module scope, guarded by
27
+ runner calls it once. Only production calls it at module scope, guarded by
25
28
  `if (!import.meta.env.DEV)`. Do not top-level `await` Desktop creation: Electron
26
29
  must complete the first event-loop tick before it emits `ready`.
27
30
 
28
31
  `desktop:dev` runs Vite inside Electron and keeps the renderer on `cossack://app`.
29
- Page edits reload managed windows; native bootstrap, Vite config and root `.env*`
32
+ Page edits reload managed windows. Native bootstrap, Vite configuration and root `.env*`
30
33
  changes restart Electron. Page syntax repair recovers the development window. Reloads
31
34
  reset in-memory modules, so store durable application data explicitly. The Vite
32
35
  asset listener never dispatches native application actions over loopback HTTP.
@@ -41,46 +44,46 @@ const result = await shell.dialog.showMessageBox(shell.window, options);
41
44
  Electron dialogs are asynchronous. Test `Notification.isSupported()` before
42
45
  showing a native notification. Treat `app.dock`, Linux badges, Windows overlay
43
46
  icons, taskbar buttons, menus, and trays as platform-native APIs rather than
44
- cross-platform emulations. Keep a strong `Tray` reference, intercept close
45
- only after tray creation succeeds, and maintain an explicit quitting flag.
46
- Create trays with `createDesktopTray({ image, menu, toolTip })`; it returns the
47
+ cross-platform emulations. Keep a strong `Tray` reference. Intercept close
48
+ only after tray creation succeeds. Maintain an explicit quitting flag.
49
+ Create trays with `createDesktopTray({ image, menu, toolTip })`. It returns the
47
50
  native Electron object and repairs Ubuntu AppIndicator's StatusNotifier
48
51
  registration through the standard Linux `dbus-send` utility.
49
52
 
50
53
  Configure window close handling with `configureDesktopClose()`. Its
51
54
  `behavior` is one of `quit`, `hide-to-tray`, or `confirm-quit`. The hide policy
52
- requires a live tray and safely quits if that tray is later destroyed; the
53
- confirmation policy uses an asynchronous native message box and ignores
54
- duplicate close attempts while it is open. A conservative OS policy is
55
+ requires a live tray. It quits safely if that tray is later destroyed. The
56
+ confirmation policy uses an asynchronous native message box. It ignores
57
+ duplicate close attempts while the message box is open. A safe OS policy is
55
58
  `confirm-quit` on Linux and `hide-to-tray` on Windows/macOS only after tray
56
59
  construction succeeds. Generated projects start with `quit`.
57
60
 
58
61
  On Linux, the development runner inspects Electron's local SUID sandbox helper.
59
62
  If the pnpm copy is not root-owned with mode `4755`, it warns and uses
60
63
  Electron's testing-only `--no-sandbox` flag for `desktop:dev`. Packaged
61
- applications never receive this flag; DEB installation gives the helper its
64
+ applications never receive this flag. DEB installation gives the helper its
62
65
  required permissions.
63
66
 
64
- On a Wayland session with XWayland available, `desktop:dev` selects X11 to
65
- avoid Chromium's Wayland/Vulkan incompatibility and suppresses nonfatal GPU
66
- probe logs. Set `COSSACK_DESKTOP_OZONE_PLATFORM=wayland` to test native Wayland,
67
+ On a Wayland session with XWayland available, `desktop:dev` selects X11.
68
+ This avoids Chromium's Wayland/Vulkan incompatibility. The runner suppresses
69
+ nonfatal GPU probe logs. Set `COSSACK_DESKTOP_OZONE_PLATFORM=wayland` to test native Wayland,
67
70
  or `COSSACK_DESKTOP_DEBUG=1` to retain Chromium diagnostics and enable Desktop
68
71
  lifecycle tracing.
69
72
 
70
- The generated DEB desktop entry includes `--ozone-platform=x11` for reliable
73
+ The generated DEB desktop entry includes `--ozone-platform=x11` for
71
74
  GNOME StatusNotifier tray integration. A binary launched directly from Forge's
72
75
  unpacked `out/` directory does not use the desktop entry. Test that artifact as
73
- `./your-app --no-sandbox --ozone-platform=x11`; do not add `--no-sandbox` to an
76
+ `./your-app --no-sandbox --ozone-platform=x11`. Do not add `--no-sandbox` to an
74
77
  installed application's launcher.
75
78
 
76
79
  Forge uses ASAR and the host Electron/Chromium runtime. Run `desktop:package`
77
80
  for an unpacked app and `desktop:make` for the current host's `.deb`, `.msi`, or
78
- `.dmg`; installers are not cross-built. Signing and notarization are optional
81
+ `.dmg`. Installers are not cross-built. Signing and notarization are optional
79
82
  until credentials are supplied.
80
83
 
81
- Node 22 or 24 LTS is recommended for packaging. Node 26 is supported, but
82
- Electron Packager's current ZIP extraction path is extremely slow there;
83
- generated Desktop manifests declare `node: ">=22"`.
84
+ Use Node 22 or 24 LTS for packaging. Node 26 is supported, but
85
+ Electron Packager's current ZIP extraction path is slow there.
86
+ Generated Desktop manifests declare `node: ">=22"`.
84
87
 
85
88
  References: [security checklist](https://www.electronjs.org/docs/latest/tutorial/security),
86
89
  [protocol API](https://www.electronjs.org/docs/latest/api/protocol),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cossackframework/desktop",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "type": "module",
5
5
  "description": "Secure Electron desktop runtime for Cossack applications",
6
6
  "license": "MIT",
@@ -29,18 +29,19 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@cossackframework/core": "0.9.0"
32
+ "@cossackframework/core": "0.9.2"
33
33
  },
34
34
  "peerDependencies": {
35
- "electron": "^43.7.0 || >=44.4.0",
36
- "vite": "^8.1.4"
35
+ "electron": "^43.8.1 || >=44.4.0",
36
+ "vite": "^8.1.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^22.19.0",
40
- "electron": "^43.7.0",
40
+ "electron": "^43.8.4",
41
+ "image-size": "^2.0.4",
41
42
  "typescript": "^7.0.2",
42
- "vite": "^8.1.4",
43
- "vitest": "^4.1.11"
43
+ "vite": "^8.1.6",
44
+ "vitest": "^4.1.12"
44
45
  },
45
46
  "peerDependenciesMeta": {
46
47
  "vite": {