akanjs 3.4.0-rc.0 → 3.4.0-rc.1

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.
Files changed (28) hide show
  1. package/common/pipelinePlan.ts +2 -1
  2. package/package.json +1 -1
  3. package/server/console.ts +1 -1
  4. package/server/gateway/childSupervisor.ts +20 -7
  5. package/server/gateway/gatewayConfig.ts +9 -2
  6. package/server/lifecycle/unixSocketPath.ts +79 -0
  7. package/server/logging/logControlSocket.ts +6 -4
  8. package/types/common/pipelinePlan.d.ts +2 -1
  9. package/types/server/gateway/gatewayConfig.d.ts +2 -0
  10. package/types/server/lifecycle/unixSocketPath.d.ts +22 -0
  11. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  12. package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +6 -4
  13. package/types/vendor/@akanjs/native/packages/desktop/src/commands.d.ts +7 -3
  14. package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +2 -1
  15. package/types/vendor/@akanjs/native/plugins/dock/src/index.d.ts +3 -2
  16. package/types/vendor/@akanjs/native/plugins/menu/src/index.d.ts +4 -4
  17. package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +6 -3
  18. package/vendor/@akanjs/native/native/desktop/src/lib.rs +1 -1
  19. package/vendor/@akanjs/native/native/desktop/src/linux/dock.rs +3 -2
  20. package/vendor/@akanjs/native/native/desktop/src/linux/menu.rs +13 -10
  21. package/vendor/@akanjs/native/native/desktop/src/linux/mod.rs +5 -3
  22. package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +19 -4
  23. package/vendor/@akanjs/native/packages/desktop/src/commands.ts +14 -7
  24. package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +2 -1
  25. package/vendor/@akanjs/native/plugins/dock/src/index.ts +3 -2
  26. package/vendor/@akanjs/native/plugins/menu/src/index.ts +4 -4
  27. package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +1 -1
  28. package/vendor/@akanjs/native/plugins/window/src/index.ts +6 -3
@@ -17,7 +17,8 @@ export type PipelineTrigger = (typeof pipelineTriggers)[number];
17
17
  /**
18
18
  * The executor's own operations, declared per app. Within one app each appears at most once, in this order, and
19
19
  * `docker` needs a `build` before it: the image is made from this run's `akan build` output. An action whose app's
20
- * previous action in the run was skipped or did not succeed is skipped, never run. `deploy` is the only way any part
20
+ * previous action in the run was skipped or did not succeed is skipped, never run; for `desktop-ota` that is the action
21
+ * before `ota`, since a phone bundle and a desktop app are separate releases. `deploy` is the only way any part
21
22
  * of a plan reaches the master host, and its phase runs the apps one at a time. `ota` packs an over-the-air update of
22
23
  * the app's native web bundle per target and platform (`akan pack-update`) for the executor to sign and publish; it
23
24
  * makes its own CSR build, so it needs no `build` before it. `desktop-ota` is the same for a desktop app, which is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.4.0-rc.0",
3
+ "version": "3.4.0-rc.1",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/server/console.ts CHANGED
@@ -49,7 +49,7 @@ const createAkanConsoleLogCommands = (appName: string, runtimeDir: string): Reco
49
49
  });
50
50
  } catch (error) {
51
51
  if (error instanceof LogControlUnavailableError) {
52
- session.write(`${appName} is not running (no akan-control.sock in ${runtimeDir})\n`);
52
+ session.write(`${appName} is not running (no log control socket at ${socketPath})\n`);
53
53
  return null;
54
54
  }
55
55
  throw error;
@@ -5,6 +5,7 @@ import type { AkanChildRole, AkanIpcMessage } from "akanjs/service";
5
5
  import { RestartSchedule } from "../../common/restartSchedule";
6
6
  import { CrossSiteGuard } from "../../signal/CrossSiteGuard";
7
7
  import type { BuilderMessage } from "../artifact";
8
+ import { UnixSocketPath, UnixSocketPathTooLongError } from "../lifecycle/unixSocketPath";
8
9
  import { ChildOutputReader } from "../logging/childOutputReader";
9
10
  import type { DevHostChannel } from "./devHostChannel";
10
11
  import type { ChildState, GatewayChildren } from "./gatewayChildren";
@@ -50,14 +51,26 @@ export class ChildSupervisor {
50
51
  }
51
52
 
52
53
  async prepareRuntimeDir() {
53
- await mkdir(this.#config.runtimeDir, { recursive: true });
54
+ const { runtimeDir, childSocketDir, replica } = this.#config;
55
+ try {
56
+ await UnixSocketPath.prepare(runtimeDir, this.#config.childSocketName(replica.total - 1));
57
+ } catch (error) {
58
+ if (error instanceof UnixSocketPathTooLongError) {
59
+ this.#logger.error(error.message);
60
+ this.#host.reportBackendBuildStatus({ ok: false, message: error.message });
61
+ }
62
+ throw error;
63
+ }
64
+ await mkdir(runtimeDir, { recursive: true });
54
65
 
55
- const entries = await readdir(this.#config.runtimeDir).catch(() => []);
56
- await Promise.all(
57
- entries
58
- .filter((name) => /^akan-(child-.*|control)\.sock$/.test(name))
59
- .map((name) => rm(path.join(this.#config.runtimeDir, name), { force: true }).catch(() => undefined)),
60
- );
66
+ for (const dir of new Set([runtimeDir, childSocketDir])) {
67
+ const entries = await readdir(dir).catch(() => []);
68
+ await Promise.all(
69
+ entries
70
+ .filter((name) => /^akan-(child-.*|control)\.sock$/.test(name))
71
+ .map((name) => rm(path.join(dir, name), { force: true }).catch(() => undefined)),
72
+ );
73
+ }
61
74
  }
62
75
 
63
76
  spawn(idx: number) {
@@ -5,6 +5,7 @@ import { getApiPrefix, getWsPrefix, normalizeRoutePrefix } from "../../base/base
5
5
  import type { RestartPolicy } from "../../common/restartSchedule";
6
6
  import { ClientReportId } from "../clientReportId";
7
7
  import { resolveRuntimeDir } from "../lifecycle/runtimeDir";
8
+ import { UnixSocketPath } from "../lifecycle/unixSocketPath";
8
9
  import { getWebConfigFromEnv } from "../types";
9
10
 
10
11
  export interface AkanAppOptions {
@@ -58,7 +59,8 @@ export class GatewayConfig {
58
59
  readonly artifactDir: string;
59
60
  readonly replica: AkanReplicaConfig;
60
61
  readonly runtimeDir: string;
61
- readonly socketRunId = `${process.pid}-${Date.now().toString(36)}`;
62
+ readonly socketRunId = randomBytes(4).toString("hex");
63
+ readonly childSocketDir: string;
62
64
  readonly port: number;
63
65
  readonly wsBasePort: number;
64
66
  readonly openapi?: boolean;
@@ -86,6 +88,7 @@ export class GatewayConfig {
86
88
  this.disableModules = options.disableModules ?? [];
87
89
  this.disableLibs = options.disableLibs ?? [];
88
90
  this.solo = GatewayConfig.#resolveSolo(options, this.replica);
91
+ this.childSocketDir = UnixSocketPath.dirFor(this.runtimeDir, this.childSocketName(this.replica.total - 1));
89
92
  }
90
93
 
91
94
  static #resolveSolo(options: AkanAppOptions, replica: AkanReplicaConfig) {
@@ -174,9 +177,13 @@ export class GatewayConfig {
174
177
  return "all";
175
178
  }
176
179
 
180
+ childSocketName(idx: number) {
181
+ return `akan-child-${this.socketRunId}-${String(idx).padStart(2, "0")}.sock`;
182
+ }
183
+
177
184
  childUpstreamOf(idx: number, role: AkanChildRole): GatewayUpstream {
178
185
  return {
179
- http: { type: "unix", socketPath: path.join(this.runtimeDir, `akan-child-${this.socketRunId}-${idx}.sock`) },
186
+ http: { type: "unix", socketPath: path.join(this.childSocketDir, this.childSocketName(idx)) },
180
187
  ws: role === "batch" ? undefined : { type: "tcp", host: "127.0.0.1", port: this.wsBasePort + idx },
181
188
  };
182
189
  }
@@ -0,0 +1,79 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { AkanError } from "akanjs/base";
6
+
7
+ export interface UnixSocketSite {
8
+ platform?: NodeJS.Platform;
9
+ limit?: number | null;
10
+ tempDir?: string;
11
+ }
12
+
13
+ export class UnixSocketPathTooLongError extends AkanError<"unixSocketPathTooLong"> {
14
+ readonly socketPath: string;
15
+ readonly length: number;
16
+ readonly limit: number;
17
+
18
+ constructor(socketPath: string, limit: number, platform: NodeJS.Platform) {
19
+ const length = UnixSocketPath.lengthOf(socketPath);
20
+ const system = platform === "win32" ? "Windows" : platform;
21
+ super(
22
+ "unixSocketPathTooLong",
23
+ `The unix socket path ${socketPath} is ${length} bytes long, and ${system} allows at most ${limit}, so nothing could listen on it. Move the runtime folder (AKAN_RUNTIME_DIR) or the temp folder its sockets fall back to (TEMP on Windows) to a shorter path.`,
24
+ );
25
+ this.name = "UnixSocketPathTooLongError";
26
+ this.socketPath = socketPath;
27
+ this.length = length;
28
+ this.limit = limit;
29
+ }
30
+ }
31
+
32
+ export class UnixSocketPath {
33
+
34
+ static limitOf(platform: NodeJS.Platform = process.platform): number | null {
35
+ return platform === "win32" ? 107 : null;
36
+ }
37
+
38
+ static lengthOf(socketPath: string) {
39
+ return Buffer.byteLength(socketPath);
40
+ }
41
+
42
+ static fallbackDirOf(runtimeDir: string, { platform = process.platform, tempDir }: UnixSocketSite = {}) {
43
+
44
+ const key = platform === "win32" ? runtimeDir.toLowerCase() : runtimeDir;
45
+ const hash = createHash("sha256").update(key).digest("hex").slice(0, 12);
46
+ const temp = tempDir ?? ((platform !== "win32" && process.env.XDG_RUNTIME_DIR) || tmpdir());
47
+ return UnixSocketPath.#join(platform, temp, `akan-${hash}`);
48
+ }
49
+
50
+ static dirFor(runtimeDir: string, name: string, site: UnixSocketSite = {}) {
51
+ const fits = UnixSocketPath.#limitPassed(UnixSocketPath.#join(site.platform, runtimeDir, name), site) === null;
52
+ return fits ? runtimeDir : UnixSocketPath.fallbackDirOf(runtimeDir, site);
53
+ }
54
+
55
+ static pathFor(runtimeDir: string, name: string, site: UnixSocketSite = {}) {
56
+ return UnixSocketPath.#join(site.platform, UnixSocketPath.dirFor(runtimeDir, name, site), name);
57
+ }
58
+
59
+ static assertFits(socketPath: string, site: UnixSocketSite = {}) {
60
+ const limit = UnixSocketPath.#limitPassed(socketPath, site);
61
+ if (limit !== null) throw new UnixSocketPathTooLongError(socketPath, limit, site.platform ?? process.platform);
62
+ }
63
+
64
+ static async prepare(runtimeDir: string, name: string) {
65
+ const dir = UnixSocketPath.dirFor(runtimeDir, name);
66
+ const socketPath = path.join(dir, name);
67
+ UnixSocketPath.assertFits(socketPath);
68
+ await mkdir(dir, { recursive: true, ...(dir === runtimeDir ? {} : { mode: 0o700 }) });
69
+ return socketPath;
70
+ }
71
+
72
+ static #limitPassed(socketPath: string, { platform, limit = UnixSocketPath.limitOf(platform) }: UnixSocketSite) {
73
+ return limit !== null && UnixSocketPath.lengthOf(socketPath) > limit ? limit : null;
74
+ }
75
+
76
+ static #join(platform = process.platform, ...parts: string[]) {
77
+ return (platform === "win32" ? path.win32 : path.posix).join(...parts);
78
+ }
79
+ }
@@ -1,6 +1,6 @@
1
- import { chmod, mkdir, rm } from "node:fs/promises";
2
- import path from "node:path";
1
+ import { chmod, rm } from "node:fs/promises";
3
2
  import { Logger } from "akanjs/common";
3
+ import { UnixSocketPath } from "../lifecycle/unixSocketPath";
4
4
  import type { LogHub, LogHubCoverage, LogHubEntry } from "./logHub";
5
5
  import { type LogQuery, LogQueryMatcher } from "./logQuery";
6
6
 
@@ -34,10 +34,11 @@ export class LogControlSocket {
34
34
  static readonly #turns = new Map<string, Promise<void>>();
35
35
 
36
36
  static pathIn(runtimeDir: string) {
37
- return path.join(runtimeDir, LogControlSocket.fileName);
37
+ return UnixSocketPath.pathFor(runtimeDir, LogControlSocket.fileName);
38
38
  }
39
39
 
40
40
  readonly path: string;
41
+ readonly #runtimeDir: string;
41
42
  readonly #hub: LogHub;
42
43
  readonly #logger = new Logger("LogControlSocket");
43
44
  #server: ReturnType<typeof Bun.listen<ClientState>> | null = null;
@@ -45,6 +46,7 @@ export class LogControlSocket {
45
46
 
46
47
  constructor(hub: LogHub, runtimeDir: string) {
47
48
  this.#hub = hub;
49
+ this.#runtimeDir = runtimeDir;
48
50
  this.path = LogControlSocket.pathIn(runtimeDir);
49
51
  }
50
52
 
@@ -88,7 +90,7 @@ export class LogControlSocket {
88
90
  }
89
91
 
90
92
  async #listen(generation: number) {
91
- await mkdir(path.dirname(this.path), { recursive: true });
93
+ await UnixSocketPath.prepare(this.#runtimeDir, LogControlSocket.fileName);
92
94
 
93
95
  if (await LogControlSocket.#answers(this.path)) throw new Error("another server is listening on it");
94
96
  if (this.#abandoned(generation)) return;
@@ -12,7 +12,8 @@ export type PipelineTrigger = (typeof pipelineTriggers)[number];
12
12
  /**
13
13
  * The executor's own operations, declared per app. Within one app each appears at most once, in this order, and
14
14
  * `docker` needs a `build` before it: the image is made from this run's `akan build` output. An action whose app's
15
- * previous action in the run was skipped or did not succeed is skipped, never run. `deploy` is the only way any part
15
+ * previous action in the run was skipped or did not succeed is skipped, never run; for `desktop-ota` that is the action
16
+ * before `ota`, since a phone bundle and a desktop app are separate releases. `deploy` is the only way any part
16
17
  * of a plan reaches the master host, and its phase runs the apps one at a time. `ota` packs an over-the-air update of
17
18
  * the app's native web bundle per target and platform (`akan pack-update`) for the executor to sign and publish; it
18
19
  * makes its own CSR build, so it needs no `build` before it. `desktop-ota` is the same for a desktop app, which is
@@ -49,6 +49,7 @@ export declare class GatewayConfig {
49
49
  readonly replica: AkanReplicaConfig;
50
50
  readonly runtimeDir: string;
51
51
  readonly socketRunId: string;
52
+ readonly childSocketDir: string;
52
53
  readonly port: number;
53
54
  readonly wsBasePort: number;
54
55
  readonly openapi?: boolean;
@@ -77,6 +78,7 @@ export declare class GatewayConfig {
77
78
  AKAN_CLIENT_REPORT_KEY: string;
78
79
  };
79
80
  roleOf(idx: number): AkanChildRole;
81
+ childSocketName(idx: number): string;
80
82
  childUpstreamOf(idx: number, role: AkanChildRole): GatewayUpstream;
81
83
  isWebSocketPath(pathname: string): boolean;
82
84
  }
@@ -0,0 +1,22 @@
1
+ import { AkanError } from "akanjs/base";
2
+ export interface UnixSocketSite {
3
+ platform?: NodeJS.Platform;
4
+ limit?: number | null;
5
+ tempDir?: string;
6
+ }
7
+ export declare class UnixSocketPathTooLongError extends AkanError<"unixSocketPathTooLong"> {
8
+ readonly socketPath: string;
9
+ readonly length: number;
10
+ readonly limit: number;
11
+ constructor(socketPath: string, limit: number, platform: NodeJS.Platform);
12
+ }
13
+ export declare class UnixSocketPath {
14
+ #private;
15
+ static limitOf(platform?: NodeJS.Platform): number | null;
16
+ static lengthOf(socketPath: string): number;
17
+ static fallbackDirOf(runtimeDir: string, { platform, tempDir }?: UnixSocketSite): string;
18
+ static dirFor(runtimeDir: string, name: string, site?: UnixSocketSite): string;
19
+ static pathFor(runtimeDir: string, name: string, site?: UnixSocketSite): string;
20
+ static assertFits(socketPath: string, site?: UnixSocketSite): void;
21
+ static prepare(runtimeDir: string, name: string): Promise<string>;
22
+ }
@@ -19,5 +19,5 @@ export declare class RotatingLogWriter {
19
19
  static sanitizeFilePart(value: string): string;
20
20
  write(processKey: string, chunk: string): void;
21
21
  close(): Promise<void>;
22
- static fileMode(value?: string | undefined, warn?: typeof RotatingLogWriter.__#181@#defaultWarn): number;
22
+ static fileMode(value?: string | undefined, warn?: typeof RotatingLogWriter.__#182@#defaultWarn): number;
23
23
  }
@@ -166,17 +166,19 @@ export interface ManifestRelease {
166
166
  }
167
167
  /**
168
168
  * A pack's manifest template made the manifest of one release. Refuses what no app would take: a channel none could
169
- * be configured for, a sequence or a bundle id that is not one, a revocation list a manifest may not hold.
169
+ * be configured for, a sequence or a bundle id that is not one, a desktop sequence not past its app's build, a
170
+ * revocation list a manifest may not hold.
170
171
  */
171
172
  export declare function fillManifest(template: UpdateManifest, release: ManifestRelease): UpdateManifest;
172
173
  /** A manifest's exact bytes as `update publish` writes them: what the signature is over and the envelope holds. */
173
174
  export declare function manifestBytes(manifest: UpdateManifest): Uint8Array;
174
175
  /**
175
176
  * The envelope of manifest bytes signed elsewhere (a key service, a host that signs in process): `signature` is Ed25519
176
- * over `bytes` by the private half of `publicKey`. Verified as an app verifies it before it is returned, so another
177
- * key's signature, or one over other bytes, is refused here and not by every installed app.
177
+ * over `bytes` by the private half of `publicKey`, one of `publicKeys` (the config's `updates.publicKeys`). Verified as
178
+ * an app verifies it before it is returned, so a key the apps do not trust, another key's signature, or one over other
179
+ * bytes, is refused here and not by every installed app.
178
180
  */
179
- export declare function updateEnvelope(bytes: Uint8Array, publicKey: string, signature: string | Uint8Array): UpdateEnvelope;
181
+ export declare function updateEnvelope(bytes: Uint8Array, publicKey: string, signature: string | Uint8Array, publicKeys: readonly string[]): UpdateEnvelope;
180
182
  /** Verifies like the apps do: raw public key, base64 signature over the exact manifest bytes. */
181
183
  export declare function verifyManifest(bytes: Uint8Array, signature: string, publicKey: string): boolean;
182
184
  export declare const sha256: (data: Uint8Array | string) => string;
@@ -55,11 +55,12 @@ export declare const REAP_GRACE = 2000;
55
55
  export declare function appBinFirst(resources: string): string | null;
56
56
  /**
57
57
  * `name` in `dirs`, the first hit. Windows tries each PATHEXT ending unless the name already has one of them. A name
58
- * with a folder in it is looked up as that path alone.
58
+ * with a folder in it is looked up as that path alone, from `cwd` (this process's by default).
59
59
  */
60
- export declare function findCommand(name: string, dirs: readonly string[], { platform, pathExt }?: {
60
+ export declare function findCommand(name: string, dirs: readonly string[], { platform, pathExt, cwd }?: {
61
61
  platform?: NodeJS.Platform;
62
62
  pathExt?: string;
63
+ cwd?: string;
63
64
  }): ResolvedCommand | null;
64
65
  /**
65
66
  * A command line cmd.exe hands to a batch file unchanged: each argument quoted as CommandLineToArgvW reads it, then
@@ -67,7 +68,10 @@ export declare function findCommand(name: string, dirs: readonly string[], { pla
67
68
  * (`node "%~dp0\…" %*`) puts through cmd.exe again.
68
69
  */
69
70
  export declare function batchCommandLine(file: string, args: readonly string[]): string;
70
- /** The user's shell's PATH: as an interactive login shell first, then as a login shell only; null when neither told. */
71
+ /**
72
+ * The user's shell's PATH: as an interactive login shell first, then as a login shell only, both within one `timeout`;
73
+ * null when neither told.
74
+ */
71
75
  export declare function loginShellPath(env: Record<string, string | undefined>, { shell, timeout }?: {
72
76
  shell?: string;
73
77
  timeout?: number;
@@ -70,7 +70,8 @@ export interface DesktopContext {
70
70
  /**
71
71
  * Starts a program the user installed (or one in binDir) as a child that ends with the app however the app ends, a
72
72
  * crash or a kill included; with `document: ctx.document`, also when the calling page does. A bare name is looked up
73
- * as resolveCommand does, on the PATH the child gets. Rejects NOT_FOUND when there is no such program.
73
+ * as resolveCommand does, on the PATH the child gets, and a relative path (`./tool`) from `options.cwd`. Rejects
74
+ * NOT_FOUND when there is no such program.
74
75
  */
75
76
  spawn(cmd: string[], options?: DesktopSpawnOptions): Promise<DesktopProcess>;
76
77
  /**
@@ -16,8 +16,9 @@
16
16
  * - Linux: the launcher entry of the desktop file "<app id>.desktop" (the Unity LauncherEntry
17
17
  * API, which Ubuntu's dock, Dash to Dock and KDE Plasma show): setBadge takes whole numbers
18
18
  * only (other labels reject UNSUPPORTED), setProgress draws paused and error like normal, and
19
- * setVisible(false) sets the windows' skip-taskbar hint. Nothing shows until the app is
20
- * installed with a desktop file of that name; the state is kept meanwhile.
19
+ * setVisible(false) sets the windows' skip-taskbar hint (setVisible(true) leaves it on a window
20
+ * created with skipTaskbar). Nothing shows until the app is installed with a desktop file of
21
+ * that name; the state is kept meanwhile.
21
22
  * - Web, iOS and Android: UNSUPPORTED.
22
23
  */
23
24
  export type DockProgressState = "normal" | "paused" | "error";
@@ -5,10 +5,10 @@
5
5
  * with the app's name). Until setAppMenu is called the app has the default menu: App, Edit and
6
6
  * Window (D1). Keep an Edit menu (role "editMenu" or its items): without it Cmd+C/V/X/A do
7
7
  * nothing in the page.
8
- * - Windows and Linux: a menu bar in every window, from the same item tree (the bar holds only
9
- * submenus there too, so one tree fits every OS). No menu bar until setAppMenu, and
10
- * getAppMenu() is [] then: the webview handles Ctrl+C/V itself. CmdOrCtrl is Ctrl; Cmd is the
11
- * Windows (Super) key, which Windows menus show but cannot fire.
8
+ * - Windows and Linux: a menu bar in every window (on Linux not in an auxiliary one), from the
9
+ * same item tree (the bar holds only submenus there too, so one tree fits every OS). No menu
10
+ * bar until setAppMenu, and getAppMenu() is [] then: the webview handles Ctrl+C/V itself.
11
+ * CmdOrCtrl is Ctrl; Cmd is the Windows (Super) key, which Windows menus show but cannot fire.
12
12
  * Roles: appMenu is a "File" menu with About and Exit (Windows) or Quit (Linux); editMenu,
13
13
  * windowMenu (Minimize, Maximize, Full Screen, Close) and helpMenu (only with items) are the
14
14
  * usual menus. about shows a small About box, quit asks the app to quit as Cmd+Q does, the
@@ -50,7 +50,10 @@ export interface CreateWindowOptions {
50
50
  */
51
51
  shadow?: boolean;
52
52
  alwaysOnTop?: boolean;
53
- /** No taskbar button and no Alt+Tab entry (Windows, Linux). macOS has no taskbar. */
53
+ /**
54
+ * No taskbar button. Windows still lists the window in Alt+Tab; on Linux it is a hint, and the window manager decides
55
+ * about Alt+Tab too. macOS has no taskbar.
56
+ */
54
57
  skipTaskbar?: boolean;
55
58
  /** False: the window stays hidden after its page has loaded, until `show()`, so the page can place it first. */
56
59
  visible?: boolean;
@@ -63,8 +66,8 @@ export interface CreateWindowOptions {
63
66
  visibleOnAllWorkspaces?: boolean;
64
67
  /**
65
68
  * A companion to the app's windows rather than one of them: closing the last other window quits or hides as if this
66
- * one were not there, the Dock and a second launch bring forward another window, and macOS leaves it out of the
67
- * Window menu.
69
+ * one were not there, the Dock and a second launch bring forward another window, macOS leaves it out of the Window
70
+ * menu, and Linux gives it no app menu bar.
68
71
  */
69
72
  auxiliary?: boolean;
70
73
  }
@@ -1716,7 +1716,7 @@ fn open_window(target: &EventLoopWindowTarget<UserEvent>, shell: &Shell, context
1716
1716
  win::dialogs::install_js_dialogs(shell.devtools, &webview);
1717
1717
  // The app menu bar, menu accelerators and taskbar state of the menu and dock plugins.
1718
1718
  #[cfg(target_os = "linux")]
1719
- linux::window_opened(id, &window);
1719
+ linux::window_opened(id, &window, &opts);
1720
1720
  #[cfg(target_os = "windows")]
1721
1721
  win::window_opened(id, &window, &webview);
1722
1722
  // Show the window even if the page never finishes loading.
@@ -1,7 +1,8 @@
1
1
  //! The dock plugin (and the badge plugin's count) on Linux, with the ops and state of dock.rs:
2
2
  //! dock.setBadge → the launcher entry's count: com.canonical.Unity.LauncherEntry
3
3
  //! dock.setProgress → its progress bar (paused and error draw like normal)
4
- //! dock.setVisible → the windows' skip-taskbar and skip-pager hints
4
+ //! dock.setVisible → the windows' skip-taskbar and skip-pager hints, but for those created with
5
+ //! skipTaskbar, which stay off the taskbar
5
6
  //! dock.getState
6
7
  //!
7
8
  //! The LauncherEntry API is a D-Bus signal, Update(s app_uri, a{sv} properties), which docks and
@@ -135,7 +136,7 @@ pub fn shell_op(op: &str, cmd: &V, app_id: &str) -> Option<Result<String, String
135
136
  }
136
137
  "dock.setVisible" => {
137
138
  state.hidden = !chrome::parse_visible(cmd)?;
138
- for (_, window) in super::menu::gtk_windows() {
139
+ for window in super::menu::taskbar_windows() {
139
140
  hide(&window, state.hidden);
140
141
  }
141
142
  }
@@ -1,6 +1,7 @@
1
- //! Menus on Linux (menu plugin, plugins.md §5): a GtkMenuBar at the top of every window and
2
- //! context menus, from the item trees and roles of chrome.rs, with the ops and events of menu.rs.
3
- //! Also the shell's windows as the chrome plugins see them (menu bars, dock.rs taskbar hints).
1
+ //! Menus on Linux (menu plugin, plugins.md §5): a GtkMenuBar at the top of every window but an
2
+ //! auxiliary one and context menus, from the item trees and roles of chrome.rs, with the ops and
3
+ //! events of menu.rs. Also the shell's windows as the chrome plugins see them (menu bars, dock.rs
4
+ //! taskbar hints).
4
5
  //!
5
6
  //! Know-how from the references:
6
7
  //! - tao puts a vertical GtkBox into its ApplicationWindow (tao-0.37.0/src/platform_impl/linux/
@@ -49,6 +50,8 @@ struct Window {
49
50
  gtk: glib::WeakRef<gtk::ApplicationWindow>,
50
51
  vbox: glib::WeakRef<gtk::Box>,
51
52
  bar: Option<Bar>,
53
+ auxiliary: bool,
54
+ skip_taskbar: bool,
52
55
  }
53
56
 
54
57
  /// A window's menu bar: its widgets and accel group.
@@ -71,12 +74,12 @@ thread_local! {
71
74
  // ───────────────────────── windows ─────────────────────────
72
75
 
73
76
  /// lib.rs open_window, for every window: the app menu and the dock's taskbar hint.
74
- pub fn window_opened(id: u32, window: &tao::window::Window) {
77
+ pub fn window_opened(id: u32, window: &tao::window::Window, opts: &crate::WindowOptions) {
75
78
  let Some(vbox) = window.default_vbox() else { return };
76
79
  let gtk_window = window.gtk_window();
77
- let mut entry = Window { id, gtk: gtk_window.downgrade(), vbox: vbox.downgrade(), bar: None };
80
+ let mut entry = Window { id, gtk: gtk_window.downgrade(), vbox: vbox.downgrade(), bar: None, auxiliary: opts.auxiliary, skip_taskbar: opts.skip_taskbar };
78
81
  APP.with(|app| {
79
- if let Some(tree) = app.borrow().as_ref() {
82
+ if let (Some(tree), false) = (app.borrow().as_ref(), entry.auxiliary) {
80
83
  entry.bar = Some(install(&entry, tree));
81
84
  }
82
85
  });
@@ -87,9 +90,9 @@ pub fn window_opened(id: u32, window: &tao::window::Window) {
87
90
  });
88
91
  }
89
92
 
90
- /// The shell's GTK windows (dock.rs), with their ids.
91
- pub fn gtk_windows() -> Vec<(u32, gtk::ApplicationWindow)> {
92
- WINDOWS.with(|w| w.borrow().iter().filter_map(|w| Some((w.id, w.gtk.upgrade()?))).collect())
93
+ /// The shell's GTK windows on the taskbar (dock.rs): all but those created with skipTaskbar.
94
+ pub fn taskbar_windows() -> Vec<gtk::ApplicationWindow> {
95
+ WINDOWS.with(|w| w.borrow().iter().filter(|w| !w.skip_taskbar).filter_map(|w| w.gtk.upgrade()).collect())
93
96
  }
94
97
 
95
98
  fn gtk_window_of(id: u32) -> Option<gtk::ApplicationWindow> {
@@ -189,7 +192,7 @@ fn set_app(tree: Option<Tree>) {
189
192
  if let Some(bar) = window.bar.take() {
190
193
  uninstall(window, bar);
191
194
  }
192
- if let Some(tree) = &tree {
195
+ if let (Some(tree), false) = (&tree, window.auxiliary) {
193
196
  window.bar = Some(install(window, tree));
194
197
  }
195
198
  }
@@ -100,10 +100,12 @@ pub fn async_op(id: u64, json: &str, windows: &Windows) -> bool {
100
100
  }
101
101
 
102
102
  /// lib.rs open_window, for every window: the app menu bar and the dock's taskbar hint.
103
- pub fn window_opened(id: u32, window: &tao::window::Window) {
103
+ pub fn window_opened(id: u32, window: &tao::window::Window, opts: &crate::WindowOptions) {
104
104
  use tao::platform::unix::WindowExtUnix;
105
- menu::window_opened(id, window);
106
- dock::window_opened(window.gtk_window());
105
+ menu::window_opened(id, window, opts);
106
+ if !opts.skip_taskbar {
107
+ dock::window_opened(window.gtk_window());
108
+ }
107
109
  }
108
110
 
109
111
  /// Opens a URL (or file) with its default handler (xdg-open's database, through GIO).
@@ -445,13 +445,18 @@ export interface ManifestRelease {
445
445
 
446
446
  /**
447
447
  * A pack's manifest template made the manifest of one release. Refuses what no app would take: a channel none could
448
- * be configured for, a sequence or a bundle id that is not one, a revocation list a manifest may not hold.
448
+ * be configured for, a sequence or a bundle id that is not one, a desktop sequence not past its app's build, a
449
+ * revocation list a manifest may not hold.
449
450
  */
450
451
  export function fillManifest(template: UpdateManifest, release: ManifestRelease): UpdateManifest {
451
452
  assertChannel(release.channel);
452
453
  const { sequence, revokeKeys = [], patches } = release;
453
454
  if (!Number.isSafeInteger(sequence) || sequence <= 0)
454
455
  throw new CliError(`a release's sequence is a positive whole number, not ${sequence}`);
456
+ if (template.kind === "app" && typeof template.build === "number" && sequence <= template.build)
457
+ throw new CliError(
458
+ `a desktop release's sequence must be larger than its app's build (${template.build}), not ${sequence}`,
459
+ );
455
460
  const bundle = release.bundle ?? (template.kind === "app" ? `${template.version}-${sequence}` : "");
456
461
  if (!isBundleId(bundle))
457
462
  throw new CliError(
@@ -491,11 +496,21 @@ export function manifestBytes(manifest: UpdateManifest): Uint8Array {
491
496
 
492
497
  /**
493
498
  * The envelope of manifest bytes signed elsewhere (a key service, a host that signs in process): `signature` is Ed25519
494
- * over `bytes` by the private half of `publicKey`. Verified as an app verifies it before it is returned, so another
495
- * key's signature, or one over other bytes, is refused here and not by every installed app.
499
+ * over `bytes` by the private half of `publicKey`, one of `publicKeys` (the config's `updates.publicKeys`). Verified as
500
+ * an app verifies it before it is returned, so a key the apps do not trust, another key's signature, or one over other
501
+ * bytes, is refused here and not by every installed app.
496
502
  */
497
- export function updateEnvelope(bytes: Uint8Array, publicKey: string, signature: string | Uint8Array): UpdateEnvelope {
503
+ export function updateEnvelope(
504
+ bytes: Uint8Array,
505
+ publicKey: string,
506
+ signature: string | Uint8Array,
507
+ publicKeys: readonly string[],
508
+ ): UpdateEnvelope {
498
509
  if (!isUpdatePublicKey(publicKey)) throw new CliError("the public key is not a raw 32-byte Ed25519 key in base64");
510
+ if (!Array.isArray(publicKeys))
511
+ throw new CliError("updateEnvelope needs updates.publicKeys, the keys the apps trust");
512
+ if (!publicKeys.includes(publicKey))
513
+ throw new CliError(`key ${keyIdOf(publicKey)} is not one of updates.publicKeys: no app would open what it signs`);
499
514
  if (bytes.length > MAX_UPDATE_MANIFEST)
500
515
  throw new CliError(`the manifest is ${bytes.length} bytes, and an app reads at most ${MAX_UPDATE_MANIFEST}`);
501
516
  const raw =
@@ -90,12 +90,12 @@ const isFile = (path: string, executable: boolean): boolean => {
90
90
 
91
91
  /**
92
92
  * `name` in `dirs`, the first hit. Windows tries each PATHEXT ending unless the name already has one of them. A name
93
- * with a folder in it is looked up as that path alone.
93
+ * with a folder in it is looked up as that path alone, from `cwd` (this process's by default).
94
94
  */
95
95
  export function findCommand(
96
96
  name: string,
97
97
  dirs: readonly string[],
98
- { platform = process.platform, pathExt }: { platform?: NodeJS.Platform; pathExt?: string } = {},
98
+ { platform = process.platform, pathExt, cwd }: { platform?: NodeJS.Platform; pathExt?: string; cwd?: string } = {},
99
99
  ): ResolvedCommand | null {
100
100
  if (!name || name.includes("\0")) return null;
101
101
  const windows = platform === "win32";
@@ -110,7 +110,7 @@ export function findCommand(
110
110
  const within = /[\\/]/.test(name) ? [""] : dirs.filter((dir) => dir && (windows || isAbsolute(dir)));
111
111
  for (const dir of within)
112
112
  for (const candidate of candidates) {
113
- const path = dir ? join(dir, candidate) : resolvePath(candidate);
113
+ const path = dir ? join(dir, candidate) : resolvePath(cwd ?? "", candidate);
114
114
  if (isFile(path, !windows)) return { path, shell: windows && /\.(cmd|bat)$/i.test(path) };
115
115
  }
116
116
  return null;
@@ -228,7 +228,10 @@ async function askShell(
228
228
  }
229
229
  }
230
230
 
231
- /** The user's shell's PATH: as an interactive login shell first, then as a login shell only; null when neither told. */
231
+ /**
232
+ * The user's shell's PATH: as an interactive login shell first, then as a login shell only, both within one `timeout`;
233
+ * null when neither told.
234
+ */
232
235
  export async function loginShellPath(
233
236
  env: Record<string, string | undefined>,
234
237
  { shell, timeout = PROBE_TIMEOUT }: { shell?: string; timeout?: number } = {},
@@ -246,8 +249,11 @@ export async function loginShellPath(
246
249
  ["-l", "-i", "-c"],
247
250
  ["-l", "-c"],
248
251
  ];
252
+ const deadline = performance.now() + timeout;
249
253
  for (const flags of attempts) {
250
- const path = await askShell(asked, flags, env, timeout);
254
+ const left = deadline - performance.now();
255
+ if (left <= 0) break;
256
+ const path = await askShell(asked, flags, env, left);
251
257
  if (path) return path;
252
258
  }
253
259
  console.warn(
@@ -294,10 +300,11 @@ export function createCommands(options: CommandsOptions): DesktopCommands {
294
300
  };
295
301
  let user: Promise<string> | undefined;
296
302
  const userPath = () => (user ??= readUserPath());
297
- const resolveIn = (name: string, path: string) =>
303
+ const resolveIn = (name: string, path: string, cwd?: string) =>
298
304
  findCommand(name, [...(binDir ? [binDir] : []), ...path.split(separator)], {
299
305
  platform,
300
306
  pathExt: envValue(env, "PATHEXT", platform),
307
+ cwd,
301
308
  });
302
309
  const reaper = windows ? null : createReaper(grace);
303
310
 
@@ -308,7 +315,7 @@ export function createCommands(options: CommandsOptions): DesktopCommands {
308
315
  ...Object.fromEntries(Object.entries(env).filter(([key]) => key.toUpperCase() !== "PATH")),
309
316
  PATH: [binDir, await userPath()].filter(Boolean).join(separator),
310
317
  };
311
- const found = resolveIn(name, envValue(childEnv, "PATH", platform) ?? "");
318
+ const found = resolveIn(name, envValue(childEnv, "PATH", platform) ?? "", spawnOptions.cwd);
312
319
  if (!found)
313
320
  throw new AkanNativeError(
314
321
  "NOT_FOUND",
@@ -74,7 +74,8 @@ export interface DesktopContext {
74
74
  /**
75
75
  * Starts a program the user installed (or one in binDir) as a child that ends with the app however the app ends, a
76
76
  * crash or a kill included; with `document: ctx.document`, also when the calling page does. A bare name is looked up
77
- * as resolveCommand does, on the PATH the child gets. Rejects NOT_FOUND when there is no such program.
77
+ * as resolveCommand does, on the PATH the child gets, and a relative path (`./tool`) from `options.cwd`. Rejects
78
+ * NOT_FOUND when there is no such program.
78
79
  */
79
80
  spawn(cmd: string[], options?: DesktopSpawnOptions): Promise<DesktopProcess>;
80
81
  /**
@@ -18,8 +18,9 @@ import { definePlugin } from "../../../packages/core/src/index.ts";
18
18
  * - Linux: the launcher entry of the desktop file "<app id>.desktop" (the Unity LauncherEntry
19
19
  * API, which Ubuntu's dock, Dash to Dock and KDE Plasma show): setBadge takes whole numbers
20
20
  * only (other labels reject UNSUPPORTED), setProgress draws paused and error like normal, and
21
- * setVisible(false) sets the windows' skip-taskbar hint. Nothing shows until the app is
22
- * installed with a desktop file of that name; the state is kept meanwhile.
21
+ * setVisible(false) sets the windows' skip-taskbar hint (setVisible(true) leaves it on a window
22
+ * created with skipTaskbar). Nothing shows until the app is installed with a desktop file of
23
+ * that name; the state is kept meanwhile.
23
24
  * - Web, iOS and Android: UNSUPPORTED.
24
25
  */
25
26
  export type DockProgressState = "normal" | "paused" | "error";
@@ -7,10 +7,10 @@ import { definePlugin } from "../../../packages/core/src/index.ts";
7
7
  * with the app's name). Until setAppMenu is called the app has the default menu: App, Edit and
8
8
  * Window (D1). Keep an Edit menu (role "editMenu" or its items): without it Cmd+C/V/X/A do
9
9
  * nothing in the page.
10
- * - Windows and Linux: a menu bar in every window, from the same item tree (the bar holds only
11
- * submenus there too, so one tree fits every OS). No menu bar until setAppMenu, and
12
- * getAppMenu() is [] then: the webview handles Ctrl+C/V itself. CmdOrCtrl is Ctrl; Cmd is the
13
- * Windows (Super) key, which Windows menus show but cannot fire.
10
+ * - Windows and Linux: a menu bar in every window (on Linux not in an auxiliary one), from the
11
+ * same item tree (the bar holds only submenus there too, so one tree fits every OS). No menu
12
+ * bar until setAppMenu, and getAppMenu() is [] then: the webview handles Ctrl+C/V itself.
13
+ * CmdOrCtrl is Ctrl; Cmd is the Windows (Super) key, which Windows menus show but cannot fire.
14
14
  * Roles: appMenu is a "File" menu with About and Exit (Windows) or Quit (Linux); editMenu,
15
15
  * windowMenu (Minimize, Maximize, Full Screen, Close) and helpMenu (only with items) are the
16
16
  * usual menus. about shows a small About box, quit asks the app to quit as Cmd+Q does, the
@@ -815,7 +815,6 @@ export function createDesktopUpdates(options: DesktopUpdatesOptions = {}): Deskt
815
815
  if (state.pending?.bundle === m.bundle && existsSync(state.pending.staged)) return { bundle: m.bundle };
816
816
 
817
817
  const staging = `${app}.update-${m.bundle}`;
818
- step = "disk";
819
818
  try {
820
819
  rmSync(staging, { recursive: true, force: true });
821
820
  mkdirSync(staging, { recursive: true });
@@ -827,6 +826,7 @@ export function createDesktopUpdates(options: DesktopUpdatesOptions = {}): Deskt
827
826
  error,
828
827
  );
829
828
  }
829
+ named = undefined;
830
830
  throw new AkanNativeError(
831
831
  "NOT_ALLOWED",
832
832
  `${dirname(app)} is not writable: install the release with its installer`,
@@ -66,7 +66,10 @@ export interface CreateWindowOptions {
66
66
  */
67
67
  shadow?: boolean;
68
68
  alwaysOnTop?: boolean;
69
- /** No taskbar button and no Alt+Tab entry (Windows, Linux). macOS has no taskbar. */
69
+ /**
70
+ * No taskbar button. Windows still lists the window in Alt+Tab; on Linux it is a hint, and the window manager decides
71
+ * about Alt+Tab too. macOS has no taskbar.
72
+ */
70
73
  skipTaskbar?: boolean;
71
74
  /** False: the window stays hidden after its page has loaded, until `show()`, so the page can place it first. */
72
75
  visible?: boolean;
@@ -79,8 +82,8 @@ export interface CreateWindowOptions {
79
82
  visibleOnAllWorkspaces?: boolean;
80
83
  /**
81
84
  * A companion to the app's windows rather than one of them: closing the last other window quits or hides as if this
82
- * one were not there, the Dock and a second launch bring forward another window, and macOS leaves it out of the
83
- * Window menu.
85
+ * one were not there, the Dock and a second launch bring forward another window, macOS leaves it out of the Window
86
+ * menu, and Linux gives it no app menu bar.
84
87
  */
85
88
  auxiliary?: boolean;
86
89
  }