akanjs 3.3.0 → 3.4.0-rc.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.
Files changed (62) hide show
  1. package/common/PipelinePlanSchema.ts +31 -7
  2. package/common/index.ts +6 -0
  3. package/common/pipelinePlan.ts +31 -5
  4. package/index.ts +7 -5
  5. package/package.json +1 -1
  6. package/pipelineConfig.ts +25 -2
  7. package/service/agentLoop/agentLoop.ts +19 -12
  8. package/service/predefinedAdaptor/anthropicTools.ts +8 -2
  9. package/types/common/index.d.ts +1 -1
  10. package/types/common/pipelinePlan.d.ts +35 -6
  11. package/types/index.d.ts +7 -5
  12. package/types/pipelineConfig.d.ts +20 -3
  13. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  14. package/types/service/predefinedAdaptor/anthropicTools.d.ts +1 -0
  15. package/types/vendor/@akanjs/native/packages/cli/src/api-updates.d.ts +149 -0
  16. package/types/vendor/@akanjs/native/packages/cli/src/api.d.ts +16 -162
  17. package/types/vendor/@akanjs/native/packages/cli/src/config.d.ts +3 -2
  18. package/types/vendor/@akanjs/native/packages/cli/src/lib/api-task.d.ts +79 -0
  19. package/types/vendor/@akanjs/native/packages/cli/src/lib/prepare.d.ts +1 -1
  20. package/types/vendor/@akanjs/native/packages/cli/src/lib/publish.d.ts +17 -5
  21. package/types/vendor/@akanjs/native/packages/cli/src/lib/updates.d.ts +29 -2
  22. package/types/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.d.ts +36 -0
  23. package/types/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.d.ts +15 -0
  24. package/types/vendor/@akanjs/native/packages/core/src/kernel.d.ts +16 -5
  25. package/types/vendor/@akanjs/native/packages/desktop/src/commands.d.ts +81 -0
  26. package/types/vendor/@akanjs/native/packages/desktop/src/deeplinks.d.ts +5 -1
  27. package/types/vendor/@akanjs/native/packages/desktop/src/dispatcher.d.ts +3 -0
  28. package/types/vendor/@akanjs/native/packages/desktop/src/lifecycle.d.ts +8 -1
  29. package/types/vendor/@akanjs/native/packages/desktop/src/plugin.d.ts +21 -0
  30. package/types/vendor/@akanjs/native/packages/desktop/src/server.d.ts +1 -0
  31. package/types/vendor/@akanjs/native/plugins/updates/src/desktop.d.ts +4 -4
  32. package/types/vendor/@akanjs/native/plugins/updates/src/reports.d.ts +49 -0
  33. package/types/vendor/@akanjs/native/plugins/updates/src/signer.d.ts +21 -0
  34. package/types/vendor/@akanjs/native/plugins/window/src/index.d.ts +55 -3
  35. package/vendor/@akanjs/native/native/desktop/src/lib.rs +209 -54
  36. package/vendor/@akanjs/native/packages/cli/src/api-updates.ts +332 -0
  37. package/vendor/@akanjs/native/packages/cli/src/api.ts +67 -419
  38. package/vendor/@akanjs/native/packages/cli/src/commands/build.ts +4 -1
  39. package/vendor/@akanjs/native/packages/cli/src/config.ts +3 -2
  40. package/vendor/@akanjs/native/packages/cli/src/lib/api-task.ts +223 -0
  41. package/vendor/@akanjs/native/packages/cli/src/lib/prepare.ts +2 -7
  42. package/vendor/@akanjs/native/packages/cli/src/lib/publish.ts +164 -19
  43. package/vendor/@akanjs/native/packages/cli/src/lib/updates.ts +90 -3
  44. package/vendor/@akanjs/native/packages/cli/src/platforms/desktop-update.ts +195 -43
  45. package/vendor/@akanjs/native/packages/cli/src/platforms/linux-appimage.ts +1 -1
  46. package/vendor/@akanjs/native/packages/cli/src/platforms/linux-install.ts +206 -0
  47. package/vendor/@akanjs/native/packages/cli/src/platforms/linux.ts +5 -1
  48. package/vendor/@akanjs/native/packages/core/src/kernel.ts +21 -6
  49. package/vendor/@akanjs/native/packages/core/vectors/updates.json +2 -1
  50. package/vendor/@akanjs/native/packages/desktop/src/commands.ts +380 -0
  51. package/vendor/@akanjs/native/packages/desktop/src/deeplinks.ts +20 -3
  52. package/vendor/@akanjs/native/packages/desktop/src/dispatcher.ts +28 -13
  53. package/vendor/@akanjs/native/packages/desktop/src/host.ts +6 -18
  54. package/vendor/@akanjs/native/packages/desktop/src/lifecycle.ts +8 -1
  55. package/vendor/@akanjs/native/packages/desktop/src/plugin.ts +21 -0
  56. package/vendor/@akanjs/native/packages/desktop/src/server.ts +1 -1
  57. package/vendor/@akanjs/native/plugins/updates/src/desktop.ts +90 -164
  58. package/vendor/@akanjs/native/plugins/updates/src/reports.ts +255 -0
  59. package/vendor/@akanjs/native/plugins/updates/src/signer.ts +133 -0
  60. package/vendor/@akanjs/native/plugins/window/native-plugin.json +6 -1
  61. package/vendor/@akanjs/native/plugins/window/src/desktop.ts +20 -4
  62. package/vendor/@akanjs/native/plugins/window/src/index.ts +55 -3
@@ -0,0 +1,255 @@
1
+
2
+
3
+ import { randomBytes } from "node:crypto";
4
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
5
+ import { release as osRelease } from "node:os";
6
+ import { join } from "node:path";
7
+ import { isAkanNativeError } from "../../../packages/core/src/index.ts";
8
+ import {
9
+ isBundleId,
10
+ isUpdateKeyId,
11
+ UPDATE_REPORT_BATCH,
12
+ UPDATE_REPORT_LIMIT,
13
+ type UpdateReportBody,
14
+ type UpdateReportDesktopReason,
15
+ type UpdateReportEntry,
16
+ type UpdateReportEvent,
17
+ type UpdateReportReason,
18
+ updateReportKey,
19
+ updateReportOutcome,
20
+ updateReportRetryAt,
21
+ updateReportTime,
22
+ updateReportWaits,
23
+ } from "../../../packages/core/src/kernel.ts";
24
+
25
+ export type ReportReason = UpdateReportReason | UpdateReportDesktopReason;
26
+
27
+ /** The release an event names: an entry of state.json, a manifest, or what a refused envelope claims. */
28
+ export interface ReportedRelease {
29
+ bundle?: unknown;
30
+ sequence?: unknown;
31
+ keyId?: unknown;
32
+ }
33
+
34
+ export interface ReportingApp {
35
+ /** The folder of state.json. */
36
+ dir: string;
37
+ /** A debug build posts in cleartext to any host, as its page loads from one. */
38
+ dev: boolean;
39
+ appVersion: string;
40
+ /** updates.json as it stands when a batch is sent: setChannel() changes the channel. */
41
+ config(): { app: string; platform: string; channel: string; nativeApi: string | null };
42
+ }
43
+
44
+ export interface UpdateReportsOptions {
45
+ /** updates.json `reportUrl`; without one nothing is kept. */
46
+ url: string | undefined;
47
+ platform?: NodeJS.Platform;
48
+ fetch?: typeof fetch;
49
+ /** Unix seconds. */
50
+ now?: () => number;
51
+ retryInterval?: number;
52
+ }
53
+
54
+ export interface UpdateReports {
55
+ start(app: ReportingApp): void;
56
+ /** Kept once per release and reason; a release without a bundle id is not kept. */
57
+ record(event: UpdateReportEvent, release: ReportedRelease, reason?: ReportReason): void;
58
+ /** A download that threw: `failed` under `reason`, unless the page or the app called it off. */
59
+ failed(error: unknown, release: ReportedRelease | undefined, reason: ReportReason): void;
60
+ flush(): Promise<void>;
61
+ }
62
+
63
+ interface Stored {
64
+ installId: string;
65
+ nextId: number;
66
+ events: UpdateReportEntry[];
67
+ retryAt: number | null;
68
+ seen: string[];
69
+ }
70
+
71
+ /** A kept batch goes again at the next event or start, and this often in an app left running. */
72
+ export const RETRY_INTERVAL = 60 * 60_000;
73
+ const REQUEST_TIMEOUT = 30_000;
74
+
75
+ /** https, or http to this machine: a release build posts nothing in cleartext, as a phone's release shell posts none. */
76
+ const secure = (url: string): boolean => {
77
+ try {
78
+ const { protocol, hostname } = new URL(url);
79
+ const local = hostname === "localhost" || hostname === "[::1]" || /^127\.\d+\.\d+\.\d+$/.test(hostname);
80
+ return protocol === "https:" || (protocol === "http:" && local);
81
+ } catch {
82
+ return false;
83
+ }
84
+ };
85
+
86
+ const readText = (path: string): string => {
87
+ try {
88
+ return readFileSync(path, "utf8");
89
+ } catch {
90
+ return "";
91
+ }
92
+ };
93
+
94
+ /** "macOS 15.5", "Windows 10.0.26200", "Linux Ubuntu 24.04.1 LTS": printable ASCII, 64 characters at most. */
95
+ export function osLabel(platform: NodeJS.Platform = process.platform): string {
96
+
97
+ const version =
98
+ platform === "darwin"
99
+ ? /<key>ProductVersion<\/key>\s*<string>([^<]*)<\/string>/.exec(
100
+ readText("/System/Library/CoreServices/SystemVersion.plist"),
101
+ )?.[1]
102
+ : platform === "linux"
103
+ ? /^PRETTY_NAME="?([^"\n]*)"?$/m.exec(readText("/etc/os-release"))?.[1]
104
+ : undefined;
105
+ const name = platform === "darwin" ? "macOS" : platform === "win32" ? "Windows" : "Linux";
106
+ return `${name} ${version?.trim() || osRelease()}`.replace(/[^\x20-\x7e]/g, "").slice(0, 64);
107
+ }
108
+
109
+ /**
110
+ * The release a refused envelope claims, read without trusting it and only to say which release failed: a forged name
111
+ * can at worst count against a release the server already published for this app.
112
+ */
113
+ export function claimedRelease(manifest: string, keyId: string): ReportedRelease {
114
+ try {
115
+ const claimed = JSON.parse(Buffer.from(manifest, "base64").toString("utf8")) as ReportedRelease | null;
116
+ return { bundle: claimed?.bundle, sequence: claimed?.sequence, keyId };
117
+ } catch {
118
+ return {};
119
+ }
120
+ }
121
+
122
+ export function createUpdateReports(options: UpdateReportsOptions): UpdateReports {
123
+ const send = options.fetch ?? fetch;
124
+ const now = options.now ?? (() => Date.now() / 1000);
125
+ let app: ReportingApp | undefined;
126
+ let sending = false;
127
+
128
+ const path = () => join((app as ReportingApp).dir, "report.json");
129
+ const fresh = (): Stored => ({
130
+ installId: randomBytes(16).toString("hex"),
131
+ nextId: 0,
132
+ events: [],
133
+ retryAt: null,
134
+ seen: [],
135
+ });
136
+
137
+ const read = (): Stored => {
138
+ let o: Partial<Stored> | null;
139
+ try {
140
+ o = JSON.parse(readFileSync(path(), "utf8")) as Partial<Stored> | null;
141
+ } catch {
142
+ return fresh();
143
+ }
144
+ if (typeof o?.installId !== "string" || !/^[0-9a-f]{32}$/.test(o.installId)) return fresh();
145
+ return {
146
+ installId: o.installId,
147
+ nextId: Number.isSafeInteger(o.nextId) ? (o.nextId as number) : 0,
148
+ events: Array.isArray(o.events) ? o.events : [],
149
+ retryAt: typeof o.retryAt === "number" && Number.isFinite(o.retryAt) ? o.retryAt : null,
150
+ seen: Array.isArray(o.seen) ? o.seen.filter((key) => typeof key === "string") : [],
151
+ };
152
+ };
153
+ const save = ({ retryAt, ...stored }: Stored) => {
154
+ const dir = (app as ReportingApp).dir;
155
+ mkdirSync(dir, { recursive: true });
156
+ const tmp = `${path()}.tmp`;
157
+ writeFileSync(tmp, JSON.stringify({ ...stored, ...(retryAt === null ? {} : { retryAt }) }));
158
+ renameSync(tmp, path());
159
+ };
160
+
161
+ const settle = (ids: Set<number>, status: number, retryAfter: string | null): boolean => {
162
+ const stored = read();
163
+ if (updateReportOutcome(status) === "kept") {
164
+ const retryAt = updateReportRetryAt(retryAfter, now());
165
+ if (retryAt !== stored.retryAt) save({ ...stored, retryAt });
166
+ return false;
167
+ }
168
+ save({ ...stored, events: stored.events.filter((event) => !ids.has(event.id)), retryAt: null });
169
+ return true;
170
+ };
171
+
172
+ const flush = async (): Promise<void> => {
173
+ if (!app || !options.url || sending) return;
174
+ sending = true;
175
+ try {
176
+ for (;;) {
177
+ const stored = read();
178
+ const events = stored.events.slice(0, UPDATE_REPORT_BATCH);
179
+ if (!events.length || updateReportWaits(stored.retryAt, now())) return;
180
+ const config = app.config();
181
+ const body: UpdateReportBody = {
182
+ app: config.app,
183
+ platform: config.platform,
184
+ channel: config.channel,
185
+ installId: stored.installId,
186
+ nativeApi: config.nativeApi ?? "",
187
+ appVersion: app.appVersion,
188
+ os: osLabel(options.platform),
189
+ arch: process.arch,
190
+ events,
191
+ };
192
+ const response = await send(options.url, {
193
+ method: "POST",
194
+ headers: { "Content-Type": "application/json" },
195
+ body: JSON.stringify(body),
196
+ cache: "no-store",
197
+ credentials: "omit",
198
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT),
199
+ }).catch(() => null);
200
+ void response?.body?.cancel().catch(() => {});
201
+ const ids = new Set(events.map((event) => event.id));
202
+ if (!settle(ids, response?.status ?? 0, response?.headers.get("retry-after") ?? null)) return;
203
+ }
204
+ } catch (error) {
205
+ console.warn("[akan-native] updates: the update reports stay for the next try", error);
206
+ } finally {
207
+ sending = false;
208
+ }
209
+ };
210
+
211
+ const record = (event: UpdateReportEvent, release: ReportedRelease, reason?: ReportReason) => {
212
+ const { bundle, sequence, keyId } = release;
213
+ if (!app || !options.url || typeof bundle !== "string" || !isBundleId(bundle)) return;
214
+ try {
215
+ const stored = read();
216
+ const key = updateReportKey(event, bundle, reason ?? null);
217
+ if (stored.seen.includes(key)) return;
218
+ const entry: UpdateReportEntry = {
219
+ id: stored.nextId,
220
+ event,
221
+ bundle,
222
+ sequence: typeof sequence === "number" && Number.isSafeInteger(sequence) && sequence >= 0 ? sequence : null,
223
+ reason: reason ?? null,
224
+ at: updateReportTime(Math.floor(now() * 1000)),
225
+ ...(typeof keyId === "string" && isUpdateKeyId(keyId) ? { keyId } : {}),
226
+ };
227
+ save({
228
+ ...stored,
229
+ nextId: stored.nextId + 1,
230
+ events: [...stored.events, entry].slice(-UPDATE_REPORT_LIMIT),
231
+ seen: [...stored.seen, key].slice(-UPDATE_REPORT_LIMIT),
232
+ });
233
+ } catch (error) {
234
+
235
+ console.warn("[akan-native] updates: cannot keep an update report", error);
236
+ return;
237
+ }
238
+ void flush();
239
+ };
240
+
241
+ return {
242
+ start(reporting) {
243
+ if (!options.url || (!reporting.dev && !secure(options.url))) return;
244
+ app = reporting;
245
+ setInterval(() => void flush(), options.retryInterval ?? RETRY_INTERVAL).unref();
246
+ void flush();
247
+ },
248
+ record,
249
+ failed(error, release, reason) {
250
+ const cancelled = isAkanNativeError(error, "CANCELLED") || (error as Error | null)?.name === "AbortError";
251
+ if (release && !cancelled) record("failed", release, reason);
252
+ },
253
+ flush,
254
+ };
255
+ }
@@ -0,0 +1,133 @@
1
+
2
+
3
+ import { closeSync, openSync, readSync } from "node:fs";
4
+ import { join } from "node:path";
5
+
6
+ export type SignatureTool = (cmd: string[], env?: Record<string, string>) => Promise<{ code: number; output: string }>;
7
+
8
+ export interface SignerCheck {
9
+ mac: boolean;
10
+ windows: boolean;
11
+ /** Runs codesign (macOS) or PowerShell (Windows) on a signature. */
12
+ tool: SignatureTool;
13
+ /** updates.windowsSigners. */
14
+ pins: string[];
15
+ /** The executable inside an app with the running one's name. */
16
+ executableIn(app: string): string;
17
+ }
18
+
19
+ const powershell = () =>
20
+ join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
21
+
22
+ /**
23
+ * Whether the release's executable is signed by the installed one's signer, decided in PowerShell and printed as one
24
+ * ASCII verdict line: `unsigned` (the installed one has no valid signature), `same` or `other`. With thumbprints in
25
+ * AKAN_NATIVE_SIGNERS, `same` only for a valid signature by one of them, whatever signed the installed one. Constrained
26
+ * Language Mode (WDAC, AppLocker) refuses .NET type literals and method calls, so the script makes none, and an error
27
+ * ends it before any verdict.
28
+ */
29
+ const AUTHENTICODE = `$ErrorActionPreference = 'Stop'
30
+ $ProgressPreference = 'SilentlyContinue'
31
+ $release = Get-AuthenticodeSignature -LiteralPath $env:AKAN_NATIVE_RELEASE_EXE
32
+ $pins = @("$env:AKAN_NATIVE_SIGNERS" -split ',' | Where-Object { $_ })
33
+ if ($pins.Count -gt 0) {
34
+ if ("$($release.Status)" -ceq 'Valid' -and $pins -contains "$($release.SignerCertificate.Thumbprint)") { 'akan-signer: same' }
35
+ else { 'akan-signer: other' }
36
+ } else {
37
+ $own = Get-AuthenticodeSignature -LiteralPath $env:AKAN_NATIVE_INSTALLED_EXE
38
+ if ("$($own.Status)" -cne 'Valid') { 'akan-signer: unsigned' }
39
+ elseif ("$($release.Status)" -ceq 'Valid' -and "$($release.SignerCertificate.Subject)" -ceq "$($own.SignerCertificate.Subject)") { 'akan-signer: same' }
40
+ else { 'akan-signer: other' }
41
+ }`;
42
+
43
+ /**
44
+ * Whether an executable is unsigned, read from its PE header without PowerShell: an x64 or arm64 image (PE32+) whose
45
+ * certificate table, where Authenticode embeds a signature, is empty.
46
+ */
47
+ function isUnsignedImage(exe: string): boolean {
48
+ let fd: number | undefined;
49
+ try {
50
+ fd = openSync(exe, "r");
51
+ const head = Buffer.alloc(4096);
52
+ const size = readSync(fd, head, 0, head.length, 0);
53
+ if (size < 64 || head.toString("latin1", 0, 2) !== "MZ") return false;
54
+ const pe = head.readUInt32LE(0x3c);
55
+ if (pe + 176 > size || head.toString("latin1", pe, pe + 4) !== "PE\0\0") return false;
56
+
57
+ const optional = pe + 24;
58
+ if (head.readUInt16LE(optional) !== 0x20b) return false;
59
+ if (head.readUInt32LE(optional + 108) < 5) return true;
60
+ return head.readUInt32LE(optional + 112 + 32) === 0 && head.readUInt32LE(optional + 112 + 36) === 0;
61
+ } catch {
62
+ return false;
63
+ } finally {
64
+ if (fd !== undefined) closeSync(fd);
65
+ }
66
+ }
67
+
68
+ /** A signature tool's exit code and what it printed; -1 when it could not start. */
69
+ export async function runSignatureTool(
70
+ cmd: string[],
71
+ env?: Record<string, string>,
72
+ ): Promise<{ code: number; output: string }> {
73
+ try {
74
+ const p = Bun.spawn(cmd, {
75
+ stdin: "ignore",
76
+ stdout: "pipe",
77
+ stderr: "pipe",
78
+ windowsHide: true,
79
+ ...(env ? { env: { ...process.env, ...env } } : {}),
80
+ });
81
+ const [out, err, code] = await Promise.all([
82
+ new Response(p.stdout).text(),
83
+ new Response(p.stderr).text(),
84
+ p.exited,
85
+ ]);
86
+ return { code, output: `${out}${err}` };
87
+ } catch (error) {
88
+ return { code: -1, output: String(error) };
89
+ }
90
+ }
91
+
92
+ export async function signerRefusal(check: SignerCheck, staged: string, app: string): Promise<string | null> {
93
+ if (check.mac) {
94
+ const shown = await check.tool(["/usr/bin/codesign", "--display", "--verbose=2", app]);
95
+ const team = shown.code === 0 ? /^TeamIdentifier=([A-Z0-9]{10})$/m.exec(shown.output)?.[1] : undefined;
96
+ if (!team) return null;
97
+ const requirement = `anchor apple generic and certificate leaf[subject.OU] = "${team}"`;
98
+ const { code } = await check.tool(["/usr/bin/codesign", "--verify", `-R=${requirement}`, staged]);
99
+ return code === 0 ? null : `the release is not signed by team ${team}, as this app is; publish it with --sign`;
100
+ }
101
+ if (!check.windows) return null;
102
+ const { pins } = check;
103
+ const { code, output } = await check.tool(
104
+ [
105
+ powershell(),
106
+ "-NoProfile",
107
+ "-NonInteractive",
108
+ "-EncodedCommand",
109
+ Buffer.from(AUTHENTICODE, "utf16le").toString("base64"),
110
+ ],
111
+ {
112
+ AKAN_NATIVE_INSTALLED_EXE: check.executableIn(app),
113
+ AKAN_NATIVE_RELEASE_EXE: check.executableIn(staged),
114
+ AKAN_NATIVE_SIGNERS: pins.join(","),
115
+ },
116
+ );
117
+ const verdict = code === 0 ? /^akan-signer: (unsigned|same|other)\r?$/m.exec(output)?.[1] : undefined;
118
+ if (verdict === "same" || (verdict === "unsigned" && !pins.length)) return null;
119
+ if (verdict && pins.length)
120
+ return "the release is not Authenticode-signed by a certificate of updates.windowsSigners; publish it with --sign";
121
+ if (verdict) return "the release is not Authenticode-signed by the signer of this app; publish it with --sign";
122
+ if (pins.length)
123
+ return "PowerShell could not check the release's signer against updates.windowsSigners; install the release with its installer";
124
+
125
+ if (isUnsignedImage(check.executableIn(app))) return null;
126
+ return "PowerShell could not check the release's signer against this app's; install the release with its installer";
127
+ }
128
+
129
+ export async function codesignProblem(check: SignerCheck, staged: string): Promise<string | null> {
130
+ if (!check.mac) return null;
131
+ const verified = await check.tool(["/usr/bin/codesign", "--verify", "--deep", "--strict", staged]);
132
+ return verified.code === 0 ? null : `codesign failed: ${verified.output.trim()}`;
133
+ }
@@ -15,6 +15,8 @@
15
15
  "setAlwaysOnTop",
16
16
  "setDecorations",
17
17
  "setCursorVisible",
18
+ "setIgnoreCursorEvents",
19
+ "setVisibleOnAllWorkspaces",
18
20
  "setMinSize",
19
21
  "placeOnDisplay",
20
22
  "show",
@@ -30,7 +32,10 @@
30
32
  "events": ["resize", "move", "focus", "closeRequested", "created", "destroyed", "dragDrop"],
31
33
  "coalesce": ["resize", "move"],
32
34
  "web": "./src/web.ts",
33
- "desktop": "./src/desktop.ts",
35
+ "desktop": {
36
+ "module": "./src/desktop.ts",
37
+ "unsupported": { "windows": ["setVisibleOnAllWorkspaces"] }
38
+ },
34
39
  "ios": null,
35
40
  "android": null
36
41
  }
@@ -106,6 +106,18 @@ export function placement(display: Display, args: PlaceOnDisplayOptions | undefi
106
106
 
107
107
  const op = (name: string) => (args: unknown, ctx: DesktopContext) => shell(ctx, name, args) as Promise<WindowState>;
108
108
 
109
+ const CREATE_FLAGS = [
110
+ "frameless",
111
+ "transparent",
112
+ "shadow",
113
+ "alwaysOnTop",
114
+ "skipTaskbar",
115
+ "visible",
116
+ "focusable",
117
+ "visibleOnAllWorkspaces",
118
+ "auxiliary",
119
+ ] as const;
120
+
109
121
  function createOptions(args: unknown): Record<string, unknown> {
110
122
  const a = (args ?? {}) as Record<string, unknown>;
111
123
  const out: Record<string, unknown> = {};
@@ -119,17 +131,17 @@ function createOptions(args: unknown): Record<string, unknown> {
119
131
  if (typeof a.title !== "string") throw new AkanNativeError("INVALID_ARGS", "title must be a string");
120
132
  out.title = a.title;
121
133
  }
122
- if (a.frameless !== undefined) out.frameless = bool(a.frameless, "frameless");
134
+ for (const flag of CREATE_FLAGS) if (a[flag] !== undefined) out[flag] = bool(a[flag], flag);
123
135
  for (const [x, y] of [
124
136
  ["width", "height"],
137
+ ["minWidth", "minHeight"],
125
138
  ["x", "y"],
126
139
  ] as const) {
127
140
  if (a[x] === undefined && a[y] === undefined) continue;
128
141
  out[x] = finite(a[x], x);
129
142
  out[y] = finite(a[y], y);
130
- }
131
- if (out.width !== undefined && ((out.width as number) < 1 || (out.height as number) < 1)) {
132
- throw new AkanNativeError("INVALID_ARGS", "width and height must be positive");
143
+ if (x !== "x" && ((out[x] as number) < 1 || (out[y] as number) < 1))
144
+ throw new AkanNativeError("INVALID_ARGS", `${x} and ${y} must be positive`);
133
145
  }
134
146
  return out;
135
147
  }
@@ -166,6 +178,10 @@ export default defineDesktopPlugin<WindowApi, WindowEvents>({
166
178
  shell(ctx, "setDecorations", args, { value: bool(args?.value, "value") }) as Promise<WindowState>,
167
179
  setCursorVisible: (args, ctx) =>
168
180
  shell(ctx, "setCursorVisible", args, { value: bool(args?.value, "value") }) as Promise<WindowState>,
181
+ setIgnoreCursorEvents: (args, ctx) =>
182
+ shell(ctx, "setIgnoreCursorEvents", args, { value: bool(args?.value, "value") }) as Promise<WindowState>,
183
+ setVisibleOnAllWorkspaces: (args, ctx) =>
184
+ shell(ctx, "setVisibleOnAllWorkspaces", args, { value: bool(args?.value, "value") }) as Promise<WindowState>,
169
185
  setMinSize: (args, ctx) => {
170
186
  if (args?.width === undefined && args?.height === undefined)
171
187
  return shell(ctx, "setMinSize", args) as Promise<WindowState>;
@@ -30,9 +30,13 @@ export interface WindowState {
30
30
  /** A window and its id (SH-6: 1 is the window the app opened; others come from createWindow). */
31
31
  export interface WindowInfo extends WindowState {
32
32
  id: number;
33
+ auxiliary: boolean;
33
34
  }
34
35
 
35
- /** Where a new window opens. Sizes and positions are logical pixels; x and y are the frame's top-left corner. */
36
+ /**
37
+ * Where a new window opens. Sizes and positions are logical pixels; x and y are the frame's top-left corner. A Wayland
38
+ * session places every window itself: x, y and `setPosition` are not followed there.
39
+ */
36
40
  export interface CreateWindowOptions {
37
41
  /** App path the window loads, e.g. "/settings" (the SPA router sees it). Default "/". */
38
42
  path?: string;
@@ -45,6 +49,40 @@ export interface CreateWindowOptions {
45
49
  y?: number;
46
50
  /** No title bar or border, from the first frame: a kiosk drawn at an exact size. */
47
51
  frameless?: boolean;
52
+ /**
53
+ * The smallest inner size, from creation: both or neither. Default 320×240, and a `width` or `height` below the
54
+ * minimum is raised to it, so a smaller window names its minimum here.
55
+ */
56
+ minWidth?: number;
57
+ minHeight?: number;
58
+ /**
59
+ * Nothing is drawn behind the page, the theme colour included: with `html, body { background: transparent }` the
60
+ * desktop shows through. Linux needs a compositing window manager; without one the window is opaque.
61
+ */
62
+ transparent?: boolean;
63
+ /**
64
+ * The window's shadow. Default: the system's, and none for a transparent window. macOS, and a frameless window on
65
+ * Windows; on Linux the window manager decides.
66
+ */
67
+ shadow?: boolean;
68
+ alwaysOnTop?: boolean;
69
+ /** No taskbar button and no Alt+Tab entry (Windows, Linux). macOS has no taskbar. */
70
+ skipTaskbar?: boolean;
71
+ /** False: the window stays hidden after its page has loaded, until `show()`, so the page can place it first. */
72
+ visible?: boolean;
73
+ /**
74
+ * False: a click does not make it the window that takes the keyboard. On macOS a click may still bring the app
75
+ * forward, since the window is not a non-activating panel.
76
+ */
77
+ focusable?: boolean;
78
+ /** On every Space or virtual desktop (macOS, Linux). Windows has no such window, so there it is left out. */
79
+ visibleOnAllWorkspaces?: boolean;
80
+ /**
81
+ * 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.
84
+ */
85
+ auxiliary?: boolean;
48
86
  }
49
87
 
50
88
  /** A display of `screen.getDisplays()` and where on it the window goes. */
@@ -84,6 +122,14 @@ export interface WindowApi {
84
122
  * Windows; elsewhere on the desktop it still shows.
85
123
  */
86
124
  setCursorVisible(args: { value: boolean } & On): Promise<WindowState>;
125
+ /**
126
+ * True: clicks and the pointer pass through the whole window to what is under it, and the page gets no mouse event
127
+ * until it is false again, so the page turns it off from a `screen.getCursorPoint()` poll, which Wayland does not
128
+ * answer.
129
+ */
130
+ setIgnoreCursorEvents(args: { value: boolean } & On): Promise<WindowState>;
131
+ /** On every Space or virtual desktop. UNSUPPORTED on Windows. */
132
+ setVisibleOnAllWorkspaces(args: { value: boolean } & On): Promise<WindowState>;
87
133
  /**
88
134
  * The smallest inner size, logical pixels: both or neither (none); one alone is INVALID_ARGS. The default is
89
135
  * 320×240, which an LED board drawn at its device size (640×128 ÷ the display's `scale`) is below.
@@ -100,7 +146,7 @@ export interface WindowApi {
100
146
  /**
101
147
  * Closes the window without asking onCloseRequested handlers. While another window exists it
102
148
  * is destroyed; the last window makes the app quit (asking app.onBeforeQuit handlers), or only
103
- * hides if desktop.quitOnLastWindowClosed is false.
149
+ * hides if desktop.quitOnLastWindowClosed is false. An auxiliary window is not counted as another.
104
150
  */
105
151
  close(args?: On): Promise<void>;
106
152
  /** Moves the window with the mouse; call it from a mousedown on a custom title bar. */
@@ -161,6 +207,8 @@ export const appWindow = definePlugin<WindowApi, WindowEvents>("window", {
161
207
  "setAlwaysOnTop",
162
208
  "setDecorations",
163
209
  "setCursorVisible",
210
+ "setIgnoreCursorEvents",
211
+ "setVisibleOnAllWorkspaces",
164
212
  "setMinSize",
165
213
  "placeOnDisplay",
166
214
  "show",
@@ -196,6 +244,8 @@ export interface WindowHandle {
196
244
  setAlwaysOnTop(value: boolean): Promise<WindowState>;
197
245
  setDecorations(value: boolean): Promise<WindowState>;
198
246
  setCursorVisible(value: boolean): Promise<WindowState>;
247
+ setIgnoreCursorEvents(value: boolean): Promise<WindowState>;
248
+ setVisibleOnAllWorkspaces(value: boolean): Promise<WindowState>;
199
249
  /** Both left out: no minimum. One alone is INVALID_ARGS. */
200
250
  setMinSize(width?: number, height?: number): Promise<WindowState>;
201
251
  placeOnDisplay(options: PlaceOnDisplayOptions): Promise<WindowState>;
@@ -230,6 +280,8 @@ export function windowHandle(id: number): WindowHandle {
230
280
  setAlwaysOnTop: (value) => appWindow.setAlwaysOnTop({ value, ...on }),
231
281
  setDecorations: (value) => appWindow.setDecorations({ value, ...on }),
232
282
  setCursorVisible: (value) => appWindow.setCursorVisible({ value, ...on }),
283
+ setIgnoreCursorEvents: (value) => appWindow.setIgnoreCursorEvents({ value, ...on }),
284
+ setVisibleOnAllWorkspaces: (value) => appWindow.setVisibleOnAllWorkspaces({ value, ...on }),
233
285
  setMinSize: (width, height) =>
234
286
  appWindow.setMinSize({
235
287
  ...(width !== undefined ? { width } : {}),
@@ -259,7 +311,7 @@ export function getCurrentWindow(): WindowHandle {
259
311
 
260
312
  /**
261
313
  * Opens another window that loads `path` of this app (desktop). It stays hidden until its page
262
- * has loaded, like the first window. UNSUPPORTED on web, iOS and Android. Pages of different
314
+ * has loaded, like the first window, or until `show()` with `visible: false`. UNSUPPORTED on web, iOS and Android. Pages of different
263
315
  * windows share storage (localStorage, IndexedDB) and can talk through BroadcastChannel.
264
316
  */
265
317
  export async function createWindow(options: CreateWindowOptions = {}): Promise<WindowHandle> {