@decaf-ts/for-os 0.0.0-stage → 0.2.7

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 (77) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +380 -2
  3. package/lib/cjs/errors.cjs +73 -0
  4. package/lib/cjs/errors.cjs.map +1 -0
  5. package/lib/cjs/index.cjs +46 -0
  6. package/lib/cjs/index.cjs.map +1 -0
  7. package/lib/cjs/native/icons.cjs +123 -0
  8. package/lib/cjs/native/icons.cjs.map +1 -0
  9. package/lib/cjs/native/loader.cjs +123 -0
  10. package/lib/cjs/native/loader.cjs.map +1 -0
  11. package/lib/cjs/native/types.cjs +4 -0
  12. package/lib/cjs/native/types.cjs.map +1 -0
  13. package/lib/cjs/notifications/NotificationCenter.cjs +328 -0
  14. package/lib/cjs/notifications/NotificationCenter.cjs.map +1 -0
  15. package/lib/cjs/tray/TrayIcon.cjs +367 -0
  16. package/lib/cjs/tray/TrayIcon.cjs.map +1 -0
  17. package/lib/cjs/tray/assets.cjs +31 -0
  18. package/lib/cjs/tray/assets.cjs.map +1 -0
  19. package/lib/esm/errors.js +65 -0
  20. package/lib/esm/errors.js.map +1 -0
  21. package/lib/esm/index.js +28 -0
  22. package/lib/esm/index.js.map +1 -0
  23. package/lib/esm/native/icons.js +117 -0
  24. package/lib/esm/native/icons.js.map +1 -0
  25. package/lib/esm/native/loader.js +116 -0
  26. package/lib/esm/native/loader.js.map +1 -0
  27. package/lib/esm/native/types.js +8 -0
  28. package/lib/esm/native/types.js.map +1 -0
  29. package/lib/esm/notifications/NotificationCenter.js +322 -0
  30. package/lib/esm/notifications/NotificationCenter.js.map +1 -0
  31. package/lib/esm/tray/TrayIcon.js +362 -0
  32. package/lib/esm/tray/TrayIcon.js.map +1 -0
  33. package/lib/esm/tray/assets.js +26 -0
  34. package/lib/esm/tray/assets.js.map +1 -0
  35. package/lib/types/errors.d.cts +56 -0
  36. package/lib/types/errors.d.mts +56 -0
  37. package/lib/types/index.d.cts +27 -0
  38. package/lib/types/index.d.mts +27 -0
  39. package/lib/types/native/icons.d.cts +71 -0
  40. package/lib/types/native/icons.d.mts +71 -0
  41. package/lib/types/native/loader.d.cts +37 -0
  42. package/lib/types/native/loader.d.mts +37 -0
  43. package/lib/types/native/types.d.cts +104 -0
  44. package/lib/types/native/types.d.mts +104 -0
  45. package/lib/types/notifications/NotificationCenter.d.cts +163 -0
  46. package/lib/types/notifications/NotificationCenter.d.mts +163 -0
  47. package/lib/types/tray/TrayIcon.d.cts +174 -0
  48. package/lib/types/tray/TrayIcon.d.mts +174 -0
  49. package/lib/types/tray/assets.d.cts +25 -0
  50. package/lib/types/tray/assets.d.mts +25 -0
  51. package/native/tray-icon-node/Cargo.lock +1511 -0
  52. package/native/tray-icon-node/Cargo.toml +45 -0
  53. package/native/tray-icon-node/Cross.toml +10 -0
  54. package/native/tray-icon-node/LICENSE +21 -0
  55. package/native/tray-icon-node/UPSTREAM-README.md +281 -0
  56. package/native/tray-icon-node/UPSTREAM.md +213 -0
  57. package/native/tray-icon-node/build-manifest.json +16 -0
  58. package/native/tray-icon-node/build.rs +5 -0
  59. package/native/tray-icon-node/index.d.ts +368 -0
  60. package/native/tray-icon-node/index.js +609 -0
  61. package/native/tray-icon-node/package.json +55 -0
  62. package/native/tray-icon-node/rustfmt.toml +31 -0
  63. package/native/tray-icon-node/source-manifest.json +30 -0
  64. package/native/tray-icon-node/src/common.rs +101 -0
  65. package/native/tray-icon-node/src/icon.rs +255 -0
  66. package/native/tray-icon-node/src/lib.rs +449 -0
  67. package/native/tray-icon-node/src/menu.rs +849 -0
  68. package/native/tray-icon-node/src/tray.rs +251 -0
  69. package/native/tray-icon-node/tray-icon-node.linux-x64-gnu.node +0 -0
  70. package/package.json +131 -4
  71. package/scripts/for-os-build.mjs +60 -0
  72. package/scripts/for-os-init.mjs +327 -0
  73. package/scripts/for-os-install.mjs +47 -0
  74. package/scripts/for-os-integration.mjs +137 -0
  75. package/scripts/for-os-integrity.mjs +51 -0
  76. package/scripts/for-os-package.mjs +49 -0
  77. package/scripts/lib/native.mjs +591 -0
@@ -0,0 +1,367 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrayIcon = void 0;
4
+ /**
5
+ * @module for-os.tray
6
+ * @description Runtime-switchable system-tray icon and menu bridge.
7
+ * @summary `TrayIcon` owns one native tray host, a menu with JavaScript
8
+ * callbacks, and the cooperative native event pump. Icons can be replaced at
9
+ * runtime with {@link TrayIcon.setIcon} (path, bytes, base64, or RGBA), menu
10
+ * entries can be relabelled/enabled/checked, and unknown native failures
11
+ * degrade the tray without throwing into the host application.
12
+ */
13
+ const errors_js_1 = require("./../errors.cjs");
14
+ const icons_js_1 = require("./../native/icons.cjs");
15
+ const loader_js_1 = require("./../native/loader.cjs");
16
+ /** Interval of the cooperative native event pump while a tray exists. */
17
+ const DEFAULT_POLL_INTERVAL_MS = 100;
18
+ function defaultLog(message) {
19
+ console.warn(message);
20
+ }
21
+ /**
22
+ * @description A live system-tray icon with a JavaScript-driven menu.
23
+ * @summary Create one with {@link TrayIcon.create}. Call {@link close} when the
24
+ * host application shuts the tray down. `active` turns false after a native
25
+ * failure; every mutating method is a no-op after that.
26
+ * @class TrayIcon
27
+ * @example
28
+ * import { TrayIcon, TRAY_ICON_BASE64 } from "@decaf-ts/for-os";
29
+ * const tray = TrayIcon.create({
30
+ * icon: { base64: TRAY_ICON_BASE64.idle },
31
+ * tooltip: "Decaf",
32
+ * menu: [{ id: "quit", label: "Quit" }],
33
+ * });
34
+ * tray.on("quit", () => tray.close());
35
+ */
36
+ class TrayIcon {
37
+ constructor(api, host, options, menu, resolver, handles) {
38
+ this.api = api;
39
+ this.host = host;
40
+ this.handlers = new Map();
41
+ this.itemHandlers = new Map();
42
+ this.menuHandles = new Map();
43
+ this.closed = false;
44
+ this.isActive = true;
45
+ this.menu = menu;
46
+ this.log = options.log ?? defaultLog;
47
+ this.pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
48
+ this.onEvent = options.onEvent;
49
+ this.resolver = resolver;
50
+ for (const { id, entry, handle } of handles) {
51
+ this.menuHandles.set(id, handle);
52
+ if (entry.onClick)
53
+ this.itemHandlers.set(id, entry.onClick);
54
+ }
55
+ this.startPump();
56
+ }
57
+ /**
58
+ * Creates a tray icon and its menu.
59
+ * @param {TrayIconOptions} options icon, tooltip, title, and menu entries
60
+ * @param {NativeModule} [api] native module override (tests/embedding)
61
+ * @return {TrayIcon} the live tray
62
+ * @throws {NativeModuleUnavailableError} when the native addon is unavailable
63
+ * @throws {TrayError} when the native tray host or menu cannot be created
64
+ */
65
+ static create(options, api = (0, loader_js_1.requireNativeModule)()) {
66
+ if (!options?.icon)
67
+ throw new errors_js_1.TrayError("TrayIcon requires an icon source.");
68
+ const resolver = new icons_js_1.IconResolver(api.Icon);
69
+ let menu;
70
+ const handles = [];
71
+ try {
72
+ api.initialize();
73
+ const icon = resolver.resolve(options.icon);
74
+ if (options.menu?.length) {
75
+ menu = new api.Menu();
76
+ for (const entry of options.menu) {
77
+ if (entry.separator) {
78
+ const separator = api.PredefinedMenuItem?.separator();
79
+ if (separator)
80
+ menu.appendPredefinedMenuItem(separator);
81
+ continue;
82
+ }
83
+ if (entry.checkable && api.CheckMenuItemBuilder) {
84
+ const builder = new api.CheckMenuItemBuilder();
85
+ builder.withId(entry.id);
86
+ builder.withText(entry.label);
87
+ builder.withEnabled(entry.enabled ?? true);
88
+ builder.withChecked(entry.checked ?? false);
89
+ const handle = builder.build();
90
+ menu.appendCheckMenuItem(handle, entry.id);
91
+ handles.push({ id: entry.id, entry, handle });
92
+ continue;
93
+ }
94
+ const builder = new api.MenuItemBuilder();
95
+ builder.withId(entry.id);
96
+ builder.withText(entry.label);
97
+ builder.withEnabled(entry.enabled ?? true);
98
+ const handle = builder.build();
99
+ menu.appendMenuItem(handle, entry.id);
100
+ handles.push({ id: entry.id, entry, handle });
101
+ }
102
+ }
103
+ const builder = new api.TrayIconBuilder();
104
+ builder.withIcon(icon);
105
+ if (options.tooltip)
106
+ builder.withTooltip(options.tooltip);
107
+ if (options.title)
108
+ builder.withTitle(options.title);
109
+ if (menu)
110
+ builder.withMenu(menu);
111
+ const host = builder.build();
112
+ return new TrayIcon(api, host, options, menu, resolver, handles);
113
+ }
114
+ catch (error) {
115
+ resolver.dispose();
116
+ if (error instanceof errors_js_1.TrayError)
117
+ throw error;
118
+ throw new errors_js_1.TrayError(error);
119
+ }
120
+ }
121
+ /**
122
+ * Creates a tray icon, returning `undefined` instead of throwing.
123
+ * @param {TrayIconOptions} options tray construction options
124
+ * @param {NativeModule} [api] native module override
125
+ * @return {TrayIcon|undefined} the tray, or `undefined` when it cannot be created
126
+ */
127
+ static tryCreate(options, api) {
128
+ try {
129
+ return TrayIcon.create(options, api);
130
+ }
131
+ catch (error) {
132
+ (options.log ?? defaultLog)(`for-os: tray unavailable (${error instanceof Error ? error.message : String(error)}).`);
133
+ return undefined;
134
+ }
135
+ }
136
+ /** Whether the tray still exists and has not degraded. */
137
+ get active() {
138
+ return this.isActive && !this.closed;
139
+ }
140
+ /**
141
+ * Switches the tray icon at runtime.
142
+ * @param {IconSource} source the new icon
143
+ * @return {boolean} `true` when applied
144
+ */
145
+ setIcon(source) {
146
+ if (!this.active)
147
+ return false;
148
+ try {
149
+ this.host.setIcon(this.resolver.resolve(source));
150
+ this.pumpOnce();
151
+ return true;
152
+ }
153
+ catch (error) {
154
+ this.degrade(error);
155
+ return false;
156
+ }
157
+ }
158
+ /**
159
+ * Updates the hover tooltip.
160
+ * @param {string} tooltip new tooltip text
161
+ * @return {boolean} `true` when applied
162
+ */
163
+ setTooltip(tooltip) {
164
+ if (!this.active)
165
+ return false;
166
+ try {
167
+ this.host.setTooltip(tooltip);
168
+ return true;
169
+ }
170
+ catch (error) {
171
+ this.degrade(error);
172
+ return false;
173
+ }
174
+ }
175
+ /**
176
+ * Updates the macOS title text.
177
+ * @param {string} title new title
178
+ * @return {boolean} `true` when applied
179
+ */
180
+ setTitle(title) {
181
+ if (!this.active)
182
+ return false;
183
+ try {
184
+ this.host.setTitle(title);
185
+ return true;
186
+ }
187
+ catch (error) {
188
+ this.degrade(error);
189
+ return false;
190
+ }
191
+ }
192
+ /**
193
+ * Shows or hides the tray icon.
194
+ * @param {boolean} visible desired visibility
195
+ * @return {boolean} `true` when applied
196
+ */
197
+ setVisible(visible) {
198
+ if (!this.active)
199
+ return false;
200
+ try {
201
+ this.host.setVisible(visible);
202
+ return true;
203
+ }
204
+ catch (error) {
205
+ this.degrade(error);
206
+ return false;
207
+ }
208
+ }
209
+ /**
210
+ * Registers a global menu-action handler.
211
+ * @param {string} id menu action id
212
+ * @param {TrayActionHandler} handler callback
213
+ * @return {TrayIcon} this instance
214
+ */
215
+ on(id, handler) {
216
+ const handlers = this.handlers.get(id) ?? new Set();
217
+ handlers.add(handler);
218
+ this.handlers.set(id, handlers);
219
+ return this;
220
+ }
221
+ /**
222
+ * Removes a previously registered global handler.
223
+ * @param {string} id menu action id
224
+ * @param {TrayActionHandler} handler callback to remove
225
+ * @return {TrayIcon} this instance
226
+ */
227
+ off(id, handler) {
228
+ this.handlers.get(id)?.delete(handler);
229
+ return this;
230
+ }
231
+ /**
232
+ * Relabels, enables/disables, or checks a menu entry.
233
+ * @param {string} id menu entry id
234
+ * @param {TrayMenuItemPatch} patch fields to update
235
+ * @return {boolean} `true` when the entry exists and the change was applied
236
+ */
237
+ updateMenuItem(id, patch) {
238
+ if (!this.active)
239
+ return false;
240
+ const handle = this.menuHandles.get(id);
241
+ if (!handle)
242
+ return false;
243
+ try {
244
+ if (typeof patch.label === "string")
245
+ handle.setText(patch.label);
246
+ if (typeof patch.enabled === "boolean")
247
+ handle.setEnabled(patch.enabled);
248
+ if (typeof patch.checked === "boolean" && "setChecked" in handle) {
249
+ handle.setChecked(patch.checked);
250
+ }
251
+ return true;
252
+ }
253
+ catch (error) {
254
+ this.degrade(error);
255
+ return false;
256
+ }
257
+ }
258
+ /**
259
+ * Reads the checked state of a checkable menu entry.
260
+ * @param {string} id menu entry id
261
+ * @return {boolean} whether the entry is checked
262
+ */
263
+ isMenuItemChecked(id) {
264
+ if (!this.active || !this.menu)
265
+ return false;
266
+ try {
267
+ return this.menu.isChecked(id);
268
+ }
269
+ catch (error) {
270
+ this.degrade(error);
271
+ return false;
272
+ }
273
+ }
274
+ /**
275
+ * Toggles a checkable menu entry.
276
+ * @param {string} id menu entry id
277
+ * @return {boolean} the resulting checked state
278
+ */
279
+ toggleMenuItem(id) {
280
+ if (!this.active || !this.menu)
281
+ return false;
282
+ try {
283
+ this.menu.toggleCheck(id);
284
+ return this.menu.isChecked(id);
285
+ }
286
+ catch (error) {
287
+ this.degrade(error);
288
+ return false;
289
+ }
290
+ }
291
+ /**
292
+ * Processes pending native events immediately.
293
+ * @return {string[]} menu action ids dispatched in this drain
294
+ */
295
+ poll() {
296
+ return this.pumpOnce();
297
+ }
298
+ /** Releases the native tray, event pump, and materialized icon files; idempotent. */
299
+ close() {
300
+ if (this.closed)
301
+ return;
302
+ this.closed = true;
303
+ if (this.pump)
304
+ clearInterval(this.pump);
305
+ this.pump = undefined;
306
+ try {
307
+ this.host.setVisible(false);
308
+ }
309
+ catch {
310
+ // The desktop host may already have removed the tray; nothing to release.
311
+ }
312
+ this.resolver.dispose();
313
+ this.isActive = false;
314
+ }
315
+ startPump() {
316
+ this.pump = setInterval(() => this.pumpOnce(), this.pollIntervalMs);
317
+ this.pump.unref?.();
318
+ this.pumpOnce();
319
+ }
320
+ pumpOnce() {
321
+ if (!this.active)
322
+ return [];
323
+ const dispatched = [];
324
+ try {
325
+ this.api.update();
326
+ for (let event = this.api.pollMenuEvents(); event; event = this.api.pollMenuEvents()) {
327
+ this.dispatchMenuAction(event.id);
328
+ dispatched.push(event.id);
329
+ }
330
+ if (this.api.pollTrayEvents && this.onEvent) {
331
+ for (let event = this.api.pollTrayEvents(); event; event = this.api.pollTrayEvents()) {
332
+ this.onEvent(event);
333
+ }
334
+ }
335
+ return dispatched;
336
+ }
337
+ catch (error) {
338
+ this.degrade(error);
339
+ return dispatched;
340
+ }
341
+ }
342
+ dispatchMenuAction(id) {
343
+ const handlers = this.handlers.get(id);
344
+ if (handlers) {
345
+ for (const handler of handlers)
346
+ this.invoke(id, handler);
347
+ }
348
+ const item = this.itemHandlers.get(id);
349
+ if (item)
350
+ this.invoke(id, item);
351
+ }
352
+ invoke(id, handler) {
353
+ try {
354
+ handler(id);
355
+ }
356
+ catch (error) {
357
+ this.log(`for-os: tray action "${id}" handler failed (${error instanceof Error ? error.message : String(error)}).`);
358
+ }
359
+ }
360
+ degrade(error) {
361
+ this.log(`for-os: tray disabled after native failure (${error instanceof Error ? error.message : String(error)}).`);
362
+ this.close();
363
+ }
364
+ }
365
+ exports.TrayIcon = TrayIcon;
366
+ //# sourceMappingURL=TrayIcon.js.map
367
+ //# sourceMappingURL=TrayIcon.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tray/TrayIcon.cjs","sourceRoot":"","sources":["tray/TrayIcon.js"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,8CAA2C;AAC3C,mDAAoD;AACpD,qDAA4D;AAC5D,yEAAyE;AACzE,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,SAAS,UAAU,CAAC,OAAO;IACvB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AACD;;;;;;;;;;;;;;GAcG;AACH,MAAa,QAAQ;IACjB,YAAY,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO;QACnD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,IA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H,CAAC;IACL,CAAC;IACD,OAAO,CAAC,KAAK;QACT,IAAI,CAAC,GAAG,CAAC,+CAA+C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpH,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ;AAxUD,4BAwUC;AACD,oCAAoC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TRAY_ICON_BASE64 = void 0;
4
+ exports.trayIconPng = trayIconPng;
5
+ /**
6
+ * @module for-os.tray.assets
7
+ * @description Embedded 16x16 tray icons for runtime icon-switching examples.
8
+ * @summary Icons are base64 PNG strings so no binary asset has to be resolved
9
+ * at runtime. Pass them directly to {@link TrayIcon.setIcon} or decode them
10
+ * with {@link trayIconPng}.
11
+ */
12
+ /**
13
+ * Embedded base64 PNG icons keyed by tray state.
14
+ * @summary Values are 16x16 PNGs encoded as base64 strings. Decode them with
15
+ * {@link trayIconPng}, or pass `{ base64 }` directly to
16
+ * {@link TrayIcon.setIcon}.
17
+ * @constant
18
+ * @readonly
19
+ */
20
+ exports.TRAY_ICON_BASE64 = {
21
+ /** Base64 PNG shown while the tray is idle. */
22
+ idle: "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAaUlEQVR42q2TwQ3AIAhFvbof2zDC28IZvbdpIkljitHC4V0k/0UBC1AieIUKCKADGWdbgifQgWuij9pS0D6CM80T6EbY0FlQnWt7dOuJCeQgbMhboD8EmioIPyHcxPAYUxYpZZVTPtMRNxn8JW/L/TDsAAAAAElFTkSuQmCC",
23
+ /** Base64 PNG shown while the tray is active. */
24
+ active: "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAbUlEQVR42mN46uHLQAnGJcH51MM35KmHbzUUh0DFiDIApOHLUw/f/2j4C1QOrwGLsGhEx4twGVBNhGYYrkY3gBOHs3HhL7AwgRkQQoJmGA5BNqCaDAOqqWoAxV6gOBApjkaqJCSqJGWqZCaSMABh2/5gh+Rb1AAAAABJRU5ErkJggg==",
25
+ };
26
+ /** Decodes an embedded tray icon back into PNG bytes. */
27
+ function trayIconPng(name) {
28
+ return Buffer.from(exports.TRAY_ICON_BASE64[name], "base64");
29
+ }
30
+ //# sourceMappingURL=assets.js.map
31
+ //# sourceMappingURL=assets.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tray/assets.cjs","sourceRoot":"","sources":["tray/assets.js"],"names":[],"mappings":";;;AAsBA,kCAEC;AAxBD;;;;;;GAMG;AACH;;;;;;;GAOG;AACU,QAAA,gBAAgB,GAAG;IAC5B,+CAA+C;IAC/C,IAAI,EAAE,0NAA0N;IAChO,iDAAiD;IACjD,MAAM,EAAE,kOAAkO;CAC7O,CAAC;AACF,yDAAyD;AACzD,SAAgB,WAAW,CAAC,IAAI;IAC5B,OAAO,MAAM,CAAC,IAAI,CAAC,wBAAgB,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAC;AACzD,CAAC;AACD,kCAAkC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @module for-os.errors
3
+ * @description Error hierarchy for the native operating-system bridges.
4
+ * @summary Every failure raised by `@decaf-ts/for-os` extends the Decaf
5
+ * `InternalError` hierarchy so callers get a stable `code` and `name`.
6
+ */
7
+ import { InternalError } from "@decaf-ts/db-decorators";
8
+ /**
9
+ * @description Raised when the native tray/notification addon cannot be located or loaded.
10
+ * @summary Use this when the vendored `tray-icon-node` addon has not been built
11
+ * or the host platform is unsupported.
12
+ * @param {string|Error|unknown} msg error message or originating error
13
+ * @class NativeModuleUnavailableError
14
+ * @extends InternalError
15
+ * @category Errors
16
+ */
17
+ export class NativeModuleUnavailableError extends InternalError {
18
+ constructor(msg) {
19
+ super(msg, NativeModuleUnavailableError.name, 500);
20
+ }
21
+ }
22
+ /**
23
+ * @description Raised when a system-tray host or menu operation fails.
24
+ * @summary Wraps native addon failures raised while creating or mutating a
25
+ * {@link TrayIcon} so callers can distinguish tray failures from other errors.
26
+ * @param {string|Error|unknown} msg error message or originating error
27
+ * @class TrayError
28
+ * @extends InternalError
29
+ * @category Errors
30
+ */
31
+ export class TrayError extends InternalError {
32
+ constructor(msg) {
33
+ super(msg, TrayError.name, 500);
34
+ }
35
+ }
36
+ /**
37
+ * @description Raised when a desktop notification cannot be dispatched.
38
+ * @summary Reserved for notification-specific failures; validation and missing
39
+ * native backends report {@link ValidationError} and
40
+ * {@link NativeModuleUnavailableError} respectively.
41
+ * @param {string|Error|unknown} msg error message or originating error
42
+ * @class NotificationError
43
+ * @extends InternalError
44
+ * @category Errors
45
+ */
46
+ export class NotificationError extends InternalError {
47
+ constructor(msg) {
48
+ super(msg, NotificationError.name, 500);
49
+ }
50
+ }
51
+ /**
52
+ * @description Raised when an icon source cannot be materialized or decoded.
53
+ * @summary Covers empty paths, missing files, malformed base64, and RGBA buffers
54
+ * whose length does not match `width x height x 4`.
55
+ * @param {string|Error|unknown} msg error message or originating error
56
+ * @class IconError
57
+ * @extends InternalError
58
+ * @category Errors
59
+ */
60
+ export class IconError extends InternalError {
61
+ constructor(msg) {
62
+ super(msg, IconError.name, 500);
63
+ }
64
+ }
65
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,OAAO,4BAA6B,SAAQ,aAAa;IAC7D,YAAY,GAA6B;QACvC,KAAK,CAAC,GAAG,EAAE,4BAA4B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,GAA6B;QACvC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAClD,YAAY,GAA6B;QACvC,KAAK,CAAC,GAAG,EAAE,iBAAiB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,GAA6B;QACvC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module for-os
3
+ * @description Native operating-system bridges for Decaf.ts: system tray and
4
+ * desktop notifications, built from Rust and exposed to TypeScript/JavaScript.
5
+ * @summary The package ships a vendored NAPI-RS crate
6
+ * (`native/tray-icon-node`) that is compiled at install time. The TypeScript
7
+ * layer adds runtime icon switching, menu callbacks, auto-dismiss notification
8
+ * timers, and JavaScript button mapping on top of the raw native API. The main
9
+ * entry points are {@link TrayIcon}, {@link NotificationCenter}, and the native
10
+ * loader helpers exposed by {@link loadNativeModule}.
11
+ */
12
+ export * from "./errors.js";
13
+ export * from "./native/types.js";
14
+ export * from "./native/icons.js";
15
+ export * from "./native/loader.js";
16
+ export * from "./tray/assets.js";
17
+ export * from "./tray/TrayIcon.js";
18
+ export * from "./notifications/NotificationCenter.js";
19
+ /**
20
+ * @description The package version, replaced by the build pipeline.
21
+ * @summary Reports the released semantic version of `@decaf-ts/for-os`; the
22
+ * placeholder literal is substituted during the release build.
23
+ * @type {string}
24
+ * @constant
25
+ * @memberOf module:for-os
26
+ */
27
+ export const VERSION = "0.2.7";
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4BAAyB;AACzB,kCAA+B;AAC/B,kCAA+B;AAC/B,mCAAgC;AAChC,iCAA8B;AAC9B,mCAAgC;AAChC,sDAAmD;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAAC"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @module for-os.native.icons
3
+ * @description Converts TypeScript icon sources into native tray icon handles.
4
+ * @summary The native addon loads icons from file paths (or raw RGBA), so
5
+ * base64 and byte-buffer sources are materialized into a private temporary
6
+ * directory that is removed when the owning tray closes.
7
+ */
8
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { extname, join, sep } from "node:path";
11
+ import { IconError } from "./../errors.js";
12
+ const MAX_ICON_EXTENSION_LENGTH = 16;
13
+ function sanitizeExtension(extension) {
14
+ const cleaned = extension
15
+ .replace(/[^A-Za-z0-9.]/g, "")
16
+ .replace(/\.{2,}/g, ".")
17
+ .slice(0, MAX_ICON_EXTENSION_LENGTH)
18
+ .replace(/^\.+/, "");
19
+ return cleaned ? `.${cleaned}` : ".png";
20
+ }
21
+ function hasRgba(value) {
22
+ if (!value || typeof value !== "object")
23
+ return false;
24
+ const candidate = value;
25
+ return ((Buffer.isBuffer(candidate.rgba) || candidate.rgba instanceof Uint8Array) &&
26
+ typeof candidate.width === "number" &&
27
+ typeof candidate.height === "number");
28
+ }
29
+ /**
30
+ * @description Owns the temporary directory used to materialize file-backed icons.
31
+ * @summary One resolver is normally owned by a tray or notification host and
32
+ * disposed with it. Resolving an already-native handle is intentionally not
33
+ * supported; callers pass a source and the resolver keeps the native object.
34
+ * @param {NativeIconFactory} api native icon factory used to build handles
35
+ * @param {function(string): string} [createDirectory] creates the private
36
+ * temporary directory; defaults to `fs.mkdtempSync` under the OS temp dir
37
+ * @param {function(string): void} [removeDirectory] removes the private
38
+ * directory on {@link IconResolver.dispose}; defaults to a recursive `fs.rmSync`
39
+ * @class IconResolver
40
+ */
41
+ export class IconResolver {
42
+ constructor(api, createDirectory = (prefix) => mkdtempSync(join(tmpdir(), prefix)), removeDirectory = (directory) => rmSync(directory, { recursive: true, force: true })) {
43
+ this.api = api;
44
+ this.createDirectory = createDirectory;
45
+ this.removeDirectory = removeDirectory;
46
+ }
47
+ ensureDirectory() {
48
+ if (!this.directory)
49
+ this.directory = this.createDirectory("for-os-icons-");
50
+ return this.directory;
51
+ }
52
+ /**
53
+ * Materializes `source` into a native icon handle.
54
+ * @param {IconSource} source the icon path, bytes, base64, or RGBA data
55
+ * @return {unknown} the native icon handle expected by the addon
56
+ * @throws {IconError} when the source is invalid or points to a missing file
57
+ */
58
+ resolve(source) {
59
+ if (typeof source === "string")
60
+ return this.fromPath(source);
61
+ if (!source || typeof source !== "object") {
62
+ throw new IconError("Icon source must be a path, bytes, base64 string, or RGBA data.");
63
+ }
64
+ if (hasRgba(source)) {
65
+ const expected = source.width * source.height * 4;
66
+ if (source.rgba.length !== expected) {
67
+ throw new IconError(`RGBA icon length ${source.rgba.length} does not match ${source.width}x${source.height}x4 (${expected}).`);
68
+ }
69
+ return this.api.fromRgba(Buffer.from(source.rgba), source.width, source.height);
70
+ }
71
+ if ("path" in source)
72
+ return this.fromPath(source.path);
73
+ if ("base64" in source) {
74
+ const bytes = Buffer.from(source.base64, "base64");
75
+ if (!bytes.length)
76
+ throw new IconError("Icon base64 payload is empty or invalid.");
77
+ return this.fromBytes(bytes, source.extension ?? ".png");
78
+ }
79
+ if ("png" in source)
80
+ return this.fromBytes(source.png, ".png");
81
+ if ("bytes" in source)
82
+ return this.fromBytes(source.bytes, source.extension ?? ".png");
83
+ throw new IconError("Unsupported icon source shape.");
84
+ }
85
+ fromPath(path) {
86
+ if (!path)
87
+ throw new IconError("Icon path is empty.");
88
+ if (!existsSync(path))
89
+ throw new IconError(`Icon file does not exist: ${path}`);
90
+ return this.api.fromPath(path);
91
+ }
92
+ fromBytes(bytes, extension) {
93
+ const directory = this.ensureDirectory();
94
+ const file = join(directory, `icon-${Date.now()}-${Math.random().toString(16).slice(2)}${sanitizeExtension(extension)}`);
95
+ if (!file.startsWith(directory + sep)) {
96
+ throw new IconError("Icon extension resolved outside the icon directory.");
97
+ }
98
+ writeFileSync(file, Buffer.from(bytes));
99
+ return this.api.fromPath(file);
100
+ }
101
+ /** Removes every materialized icon file; idempotent. */
102
+ dispose() {
103
+ if (!this.directory)
104
+ return;
105
+ this.removeDirectory(this.directory);
106
+ this.directory = undefined;
107
+ }
108
+ /** Directory holding materialized icons, when one has been created. */
109
+ get iconDirectory() {
110
+ return this.directory;
111
+ }
112
+ }
113
+ /** Returns a stable file extension for a path, defaulting to `.png`. */
114
+ export function iconExtension(path) {
115
+ return extname(path) || ".png";
116
+ }
117
+ //# sourceMappingURL=icons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icons.js","sourceRoot":"","sources":["../../../src/native/icons.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,uBAAkB;AAGtC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,MAAM,OAAO,GAAG,SAAS;SACtB,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,yBAAyB,CAAC;SACnC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1C,CAAC;AA4BD,SA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