@ng-native/device 0.26.1 → 0.28.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 (48) hide show
  1. package/dist/accessibility.d.ts +5 -3
  2. package/dist/accessibility.js +5 -0
  3. package/dist/accessibility.js.map +1 -1
  4. package/dist/desktop-options.d.ts +5 -0
  5. package/dist/desktop-options.js +6 -1
  6. package/dist/desktop-options.js.map +1 -1
  7. package/dist/dialogs.js +4 -2
  8. package/dist/dialogs.js.map +1 -1
  9. package/dist/dock.d.ts +2 -0
  10. package/dist/dock.js +4 -1
  11. package/dist/dock.js.map +1 -1
  12. package/dist/menu-model.d.ts +11 -9
  13. package/dist/menu-model.js +72 -9
  14. package/dist/menu-model.js.map +1 -1
  15. package/dist/menus.d.ts +19 -0
  16. package/dist/menus.js +24 -3
  17. package/dist/menus.js.map +1 -1
  18. package/dist/os-support.d.ts +1 -1
  19. package/dist/os-support.js +188 -62
  20. package/dist/os-support.js.map +1 -1
  21. package/dist/os-version.d.ts +3 -1
  22. package/dist/os-version.js +3 -1
  23. package/dist/os-version.js.map +1 -1
  24. package/dist/os.d.ts +5 -3
  25. package/dist/os.js +5 -3
  26. package/dist/os.js.map +1 -1
  27. package/dist/processes.d.ts +2 -0
  28. package/dist/processes.js +4 -1
  29. package/dist/processes.js.map +1 -1
  30. package/dist/safe-area.d.ts +12 -3
  31. package/dist/safe-area.js +16 -4
  32. package/dist/safe-area.js.map +1 -1
  33. package/dist/sharing.js +4 -3
  34. package/dist/sharing.js.map +1 -1
  35. package/dist/shortcut.d.ts +2 -2
  36. package/dist/shortcut.js +37 -2
  37. package/dist/shortcut.js.map +1 -1
  38. package/dist/spawn-rules.js +8 -0
  39. package/dist/spawn-rules.js.map +1 -1
  40. package/dist/tray.d.ts +6 -3
  41. package/dist/tray.js +8 -4
  42. package/dist/tray.js.map +1 -1
  43. package/dist/vibration.d.ts +1 -1
  44. package/dist/vibration.js +3 -3
  45. package/dist/vibration.js.map +1 -1
  46. package/dist/window-restore.js +1 -1
  47. package/dist/window-restore.js.map +1 -1
  48. package/package.json +2 -2
package/dist/tray.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Icons in the macOS menu bar's status area, each with a menu or a press of its own. `<tray-icon>`
3
- * in `@ng-native/components` registers here. Absent on iOS and Android, where nothing is drawn.
2
+ * Icons in the macOS menu bar's status area, or a Linux panel's as StatusNotifierItems, each with
3
+ * a menu or a press of its own. `<tray-icon>` in `@ng-native/components` registers here. Absent on
4
+ * iOS and Android, and on a Linux desktop with no StatusNotifierWatcher, where nothing is drawn.
4
5
  *
5
6
  * The host contract, on the `NgNativeTray` module: `setIcons(icons)` takes every icon each time one
6
7
  * changes, as `{ id, title, sfSymbol, image, tooltip, menu }`, `menu` as `serializeMenu` makes it
@@ -9,6 +10,7 @@
9
10
  */
10
11
  import { InjectionToken, Service, computed, effect, inject, signal, } from '@angular/core';
11
12
  import { serializeMenu } from "./menus.js";
13
+ import { injectOs } from "./os.js";
12
14
  import { reactNative } from "./react-native.js";
13
15
  import * as i0 from "@angular/core";
14
16
  function traySource() {
@@ -30,14 +32,16 @@ export class Tray {
30
32
  factory: traySource,
31
33
  });
32
34
  native = inject(Tray.SOURCE);
35
+ /** The desktop OS whose shortcuts the menus show: Linux's own, else a Mac's. */
36
+ menuOs = injectOs() === 'linux' ? 'linux' : 'macos';
33
37
  icons = signal([], /* @ts-ignore */
34
38
  ...(ngDevMode ? [{ debugName: "icons" }] : /* istanbul ignore next */ []));
35
39
  next = 0;
36
- /** Whether the OS has a status area for the app: macOS. */
40
+ /** Whether the OS has a status area for the app: macOS, and Linux with a StatusNotifierWatcher. */
37
41
  available = signal(this.native !== null).asReadonly();
38
42
  sent = computed(() => this.icons().map(({ id, model }) => {
39
43
  const { menu, press, ...icon } = model();
40
- const serialized = serializeMenu(menu, 'macos');
44
+ const serialized = serializeMenu(menu, this.menuOs);
41
45
  return {
42
46
  icon: { id, ...icon, menu: serialized.entries.length ? serialized.entries : null },
43
47
  actions: serialized.actions,
package/dist/tray.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tray.js","sourceRoot":"","sources":["../src/tray.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAwB,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAqChD,SAAS,UAAU;IACjB,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,cAAc,CAC5B,CAAC;IACrC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC;QAC7C,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,MAAM,YAAY,GAAG,MAAM,EAAE,kBAAkB,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,EAAE,CACrF,QAAQ,CAAC,KAAwB,CAAC,CACnC,CAAC;YACF,OAAO,GAAG,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,MAAM,OAAO,IAAI;IACf,6CAA6C;IAC7C,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAoB,2BAA2B,EAAE;QAC1F,OAAO,EAAE,UAAU;KACpB,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC7B,KAAK,GAAG,MAAM,CAA0D,EAAE;8EAAC,CAAC;IACrF,IAAI,GAAG,CAAC,CAAC;IAE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CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC1C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEO,QAAQ,CAAC,KAAsB;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC;QACnE,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,IAAI,EAAE,KAAK,EAAE,CAAC;;YACrC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACvC,CAAC;IAED,WAAW;QACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACvB,CAAC;uGA/CU,IAAI;wGAAJ,IAAI;;2FAAJ,IAAI;kBADhB,OAAO","sourcesContent":["/**\n * Icons in the macOS menu bar's status area, each with a menu or a press of its own. `<tray-icon>`\n * in `@ng-native/components` registers here. Absent on iOS and Android, where nothing is drawn.\n *\n * The host contract, on the `NgNativeTray` module: `setIcons(icons)` takes every icon each time one\n * changes, as `{ id, title, sfSymbol, image, tooltip, menu }`, `menu` as `serializeMenu` makes it\n * (null for an icon with a press instead). It sends `{ type: 'press', icon }` and\n * `{ type: 'menuSelect', icon, id }` on `ngNativeTray`.\n */\nimport {\n InjectionToken,\n Service,\n computed,\n effect,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport type { MenuEntry } from './menu-model.ts';\nimport { serializeMenu, type NativeMenuEntry } from './menus.ts';\nimport { reactNative } from './react-native.ts';\n\n/** One icon as an app describes it. */\nexport interface TrayIconModel {\n readonly title?: string;\n /** An SF Symbol, drawn as a template image that follows the menu bar's appearance. */\n readonly sfSymbol?: string;\n /** An image asset's name, for an icon of the app's own. */\n readonly image?: string;\n readonly tooltip?: string;\n /** The menu a click opens; with none, a click is a press. */\n readonly menu: readonly MenuEntry[];\n readonly press: () => void;\n}\n\nexport interface NativeTrayIcon {\n readonly id: string;\n readonly title?: string;\n readonly sfSymbol?: string;\n readonly image?: string;\n readonly tooltip?: string;\n readonly menu: readonly NativeMenuEntry[] | null;\n}\n\nexport type NativeTrayEvent =\n | { readonly type: 'press'; readonly icon: string }\n | { readonly type: 'menuSelect'; readonly icon: string; readonly id: string };\n\nexport interface NativeTray {\n setIcons(icons: readonly NativeTrayIcon[]): void;\n subscribe(listener: (event: NativeTrayEvent) => void): () => void;\n}\n\ninterface TrayTurboModule {\n setIcons?(icons: readonly NativeTrayIcon[]): void;\n}\n\nfunction traySource(): NativeTray | null {\n const native = reactNative();\n const module = native?.TurboModuleRegistry?.get?.('NgNativeTray') as\n TrayTurboModule | null | undefined;\n if (!module) return null;\n return {\n setIcons: (icons) => module.setIcons?.(icons),\n subscribe: (listener) => {\n const subscription = native?.DeviceEventEmitter?.addListener('ngNativeTray', (event) =>\n listener(event as NativeTrayEvent),\n );\n return () => subscription?.remove();\n },\n };\n}\n\n@Service()\nexport class Tray {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeTray | null>('angular-native.traySource', {\n factory: traySource,\n });\n\n private readonly native = inject(Tray.SOURCE);\n private readonly icons = signal<readonly { id: string; model: Signal<TrayIconModel> }[]>([]);\n private next = 0;\n\n /** Whether the OS has a status area for the app: macOS. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n private readonly sent = computed(() =>\n this.icons().map(({ id, model }) => {\n const { menu, press, ...icon } = model();\n const serialized = serializeMenu(menu, 'macos');\n return {\n icon: { id, ...icon, menu: serialized.entries.length ? serialized.entries : null },\n actions: serialized.actions,\n press,\n };\n }),\n );\n\n private readonly unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;\n\n constructor() {\n const native = this.native;\n if (native) effect(() => native.setIcons(this.sent().map((one) => one.icon)));\n }\n\n /** Show an icon for as long as the function answered is not called. */\n add(model: Signal<TrayIconModel>): () => void {\n const one = { id: `tray-${this.next++}`, model };\n this.icons.update((all) => [...all, one]);\n return () => this.icons.update((all) => all.filter((each) => each !== one));\n }\n\n private hostSaid(event: NativeTrayEvent): void {\n const icon = this.sent().find((one) => one.icon.id === event.icon);\n if (event.type === 'press') icon?.press();\n else icon?.actions.get(event.id)?.();\n }\n\n ngOnDestroy(): void {\n this.unsubscribe?.();\n }\n}\n"]}
1
+ {"version":3,"file":"tray.js","sourceRoot":"","sources":["../src/tray.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAwB,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAqChD,SAAS,UAAU;IACjB,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,cAAc,CAC5B,CAAC;IACrC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC;QAC7C,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,MAAM,YAAY,GAAG,MAAM,EAAE,kBAAkB,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,KAAK,EA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WAAW;QACT,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACvB,CAAC;uGAjDU,IAAI;wGAAJ,IAAI;;2FAAJ,IAAI;kBADhB,OAAO","sourcesContent":["/**\n * Icons in the macOS menu bar's status area, or a Linux panel's as StatusNotifierItems, each with\n * a menu or a press of its own. `<tray-icon>` in `@ng-native/components` registers here. Absent on\n * iOS and Android, and on a Linux desktop with no StatusNotifierWatcher, where nothing is drawn.\n *\n * The host contract, on the `NgNativeTray` module: `setIcons(icons)` takes every icon each time one\n * changes, as `{ id, title, sfSymbol, image, tooltip, menu }`, `menu` as `serializeMenu` makes it\n * (null for an icon with a press instead). It sends `{ type: 'press', icon }` and\n * `{ type: 'menuSelect', icon, id }` on `ngNativeTray`.\n */\nimport {\n InjectionToken,\n Service,\n computed,\n effect,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport type { MenuEntry } from './menu-model.ts';\nimport { serializeMenu, type NativeMenuEntry } from './menus.ts';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\n\n/** One icon as an app describes it. */\nexport interface TrayIconModel {\n readonly title?: string;\n /** An SF Symbol, drawn as a template image that follows the menu bar's appearance. */\n readonly sfSymbol?: string;\n /** An image asset's name, for an icon of the app's own. */\n readonly image?: string;\n readonly tooltip?: string;\n /** The menu a click opens; with none, a click is a press. */\n readonly menu: readonly MenuEntry[];\n readonly press: () => void;\n}\n\nexport interface NativeTrayIcon {\n readonly id: string;\n readonly title?: string;\n readonly sfSymbol?: string;\n readonly image?: string;\n readonly tooltip?: string;\n readonly menu: readonly NativeMenuEntry[] | null;\n}\n\nexport type NativeTrayEvent =\n | { readonly type: 'press'; readonly icon: string }\n | { readonly type: 'menuSelect'; readonly icon: string; readonly id: string };\n\nexport interface NativeTray {\n setIcons(icons: readonly NativeTrayIcon[]): void;\n subscribe(listener: (event: NativeTrayEvent) => void): () => void;\n}\n\ninterface TrayTurboModule {\n setIcons?(icons: readonly NativeTrayIcon[]): void;\n}\n\nfunction traySource(): NativeTray | null {\n const native = reactNative();\n const module = native?.TurboModuleRegistry?.get?.('NgNativeTray') as\n TrayTurboModule | null | undefined;\n if (!module) return null;\n return {\n setIcons: (icons) => module.setIcons?.(icons),\n subscribe: (listener) => {\n const subscription = native?.DeviceEventEmitter?.addListener('ngNativeTray', (event) =>\n listener(event as NativeTrayEvent),\n );\n return () => subscription?.remove();\n },\n };\n}\n\n@Service()\nexport class Tray {\n /** Overridden in a test with a fake host. */\n static readonly SOURCE = new InjectionToken<NativeTray | null>('angular-native.traySource', {\n factory: traySource,\n });\n\n private readonly native = inject(Tray.SOURCE);\n /** The desktop OS whose shortcuts the menus show: Linux's own, else a Mac's. */\n private readonly menuOs = injectOs() === 'linux' ? 'linux' : 'macos';\n private readonly icons = signal<readonly { id: string; model: Signal<TrayIconModel> }[]>([]);\n private next = 0;\n\n /** Whether the OS has a status area for the app: macOS, and Linux with a StatusNotifierWatcher. */\n readonly available: Signal<boolean> = signal(this.native !== null).asReadonly();\n\n private readonly sent = computed(() =>\n this.icons().map(({ id, model }) => {\n const { menu, press, ...icon } = model();\n const serialized = serializeMenu(menu, this.menuOs);\n return {\n icon: { id, ...icon, menu: serialized.entries.length ? serialized.entries : null },\n actions: serialized.actions,\n press,\n };\n }),\n );\n\n private readonly unsubscribe = this.native?.subscribe((event) => this.hostSaid(event)) ?? null;\n\n constructor() {\n const native = this.native;\n if (native) effect(() => native.setIcons(this.sent().map((one) => one.icon)));\n }\n\n /** Show an icon for as long as the function answered is not called. */\n add(model: Signal<TrayIconModel>): () => void {\n const one = { id: `tray-${this.next++}`, model };\n this.icons.update((all) => [...all, one]);\n return () => this.icons.update((all) => all.filter((each) => each !== one));\n }\n\n private hostSaid(event: NativeTrayEvent): void {\n const icon = this.sent().find((one) => one.icon.id === event.icon);\n if (event.type === 'press') icon?.press();\n else icon?.actions.get(event.id)?.();\n }\n\n ngOnDestroy(): void {\n this.unsubscribe?.();\n }\n}\n"]}
@@ -8,7 +8,7 @@ export declare class Vibration {
8
8
  /** Overridden in a test to record a buzz without one happening. */
9
9
  static readonly SOURCE: InjectionToken<NativeVibration | null>;
10
10
  private readonly native;
11
- /** Whether the device can vibrate: absent on a Mac, which has no motor to drive. */
11
+ /** Whether the device can vibrate: absent on a desktop OS, which has no motor to drive. */
12
12
  readonly available: Signal<boolean>;
13
13
  /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */
14
14
  buzz(durationMs?: number): void;
package/dist/vibration.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * over, because a pattern designed on Android does not feel the same on iOS and nothing here can
12
12
  * make it.
13
13
  */
14
- import { injectOs } from "./os.js";
14
+ import { injectOs, isDesktopOs } from "./os.js";
15
15
  import { InjectionToken, Service, inject, signal } from '@angular/core';
16
16
  import { reactNative } from "./react-native.js";
17
17
  import * as i0 from "@angular/core";
@@ -19,8 +19,8 @@ export class Vibration {
19
19
  /** Overridden in a test to record a buzz without one happening. */
20
20
  static SOURCE = new InjectionToken('angular-native.vibrationSource', { factory: () => reactNative()?.Vibration ?? null });
21
21
  native = inject(Vibration.SOURCE);
22
- /** Whether the device can vibrate: absent on a Mac, which has no motor to drive. */
23
- available = signal(this.native !== null && injectOs() !== 'macos').asReadonly();
22
+ /** Whether the device can vibrate: absent on a desktop OS, which has no motor to drive. */
23
+ available = signal(this.native !== null && !isDesktopOs(injectOs())).asReadonly();
24
24
  /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */
25
25
  buzz(durationMs = 400) {
26
26
  this.native?.vibrate(durationMs);
@@ -1 +1 @@
1
- {"version":3,"file":"vibration.js","sourceRoot":"","sources":["../src/vibration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAQhD,MAAM,OAAO,SAAS;IACpB,mEAAmE;IACnE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,gCAAgC,EAChC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,IAAI,IAAI,EAAE,CACpD,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAEnD,oFAAoF;IAC3E,SAAS,GAAoB,MAAM,CAC1C,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,QAAQ,EAAE,KAAK,OAAO,CAC/C,CAAC,UAAU,EAAE,CAAC;IAEf,uFAAuF;IACvF,IAAI,CAAC,UAAU,GAAG,GAAG;QACnB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,MAAyB,EAAE,UAAgC,EAAE;QACnE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IACxB,CAAC;uGA/BU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Vibration, which is not haptics.\n *\n * `Haptics` is the Taptic Engine: a tap, a nudge, a success chime you feel rather than hear, tied\n * to something the user just did. This is the motor - a buzz of a stated length, or a pattern -\n * and it is what an alarm, a timer or an incoming call uses. An app that wants feedback for a\n * button press wants the other one.\n *\n * iOS has one duration and ignores the number, so a pattern there is on and off at a fixed\n * strength; Android takes the milliseconds as written. Both are said plainly rather than papered\n * over, because a pattern designed on Android does not feel the same on iOS and nothing here can\n * make it.\n */\n\nimport { injectOs } from './os.ts';\nimport { InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeVibration {\n vibrate(pattern?: number | number[], repeat?: boolean): void;\n cancel(): void;\n}\n\n@Service()\nexport class Vibration {\n /** Overridden in a test to record a buzz without one happening. */\n static readonly SOURCE = new InjectionToken<NativeVibration | null>(\n 'angular-native.vibrationSource',\n { factory: () => reactNative()?.Vibration ?? null },\n );\n\n private readonly native = inject(Vibration.SOURCE);\n\n /** Whether the device can vibrate: absent on a Mac, which has no motor to drive. */\n readonly available: Signal<boolean> = signal(\n this.native !== null && injectOs() !== 'macos',\n ).asReadonly();\n\n /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */\n buzz(durationMs = 400): void {\n this.native?.vibrate(durationMs);\n }\n\n /**\n * A pattern of waits and buzzes, in milliseconds, starting with a wait.\n *\n * `repeat` runs it until `stop()`, which is for something that must be answered - an alarm, a\n * call - and is a promise to call `stop` rather than a decoration.\n */\n pattern(millis: readonly number[], options: { repeat?: boolean } = {}): void {\n this.native?.vibrate([...millis], options.repeat ?? false);\n }\n\n stop(): void {\n this.native?.cancel();\n }\n}\n"]}
1
+ {"version":3,"file":"vibration.js","sourceRoot":"","sources":["../src/vibration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAQhD,MAAM,OAAO,SAAS;IACpB,mEAAmE;IACnE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,gCAAgC,EAChC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,SAAS,IAAI,IAAI,EAAE,CACpD,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAEnD,2FAA2F;IAClF,SAAS,GAAoB,MAAM,CAC1C,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CACjD,CAAC,UAAU,EAAE,CAAC;IAEf,uFAAuF;IACvF,IAAI,CAAC,UAAU,GAAG,GAAG;QACnB,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,MAAyB,EAAE,UAAgC,EAAE;QACnE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IACxB,CAAC;uGA/BU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Vibration, which is not haptics.\n *\n * `Haptics` is the Taptic Engine: a tap, a nudge, a success chime you feel rather than hear, tied\n * to something the user just did. This is the motor - a buzz of a stated length, or a pattern -\n * and it is what an alarm, a timer or an incoming call uses. An app that wants feedback for a\n * button press wants the other one.\n *\n * iOS has one duration and ignores the number, so a pattern there is on and off at a fixed\n * strength; Android takes the milliseconds as written. Both are said plainly rather than papered\n * over, because a pattern designed on Android does not feel the same on iOS and nothing here can\n * make it.\n */\n\nimport { injectOs, isDesktopOs } from './os.ts';\nimport { InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeVibration {\n vibrate(pattern?: number | number[], repeat?: boolean): void;\n cancel(): void;\n}\n\n@Service()\nexport class Vibration {\n /** Overridden in a test to record a buzz without one happening. */\n static readonly SOURCE = new InjectionToken<NativeVibration | null>(\n 'angular-native.vibrationSource',\n { factory: () => reactNative()?.Vibration ?? null },\n );\n\n private readonly native = inject(Vibration.SOURCE);\n\n /** Whether the device can vibrate: absent on a desktop OS, which has no motor to drive. */\n readonly available: Signal<boolean> = signal(\n this.native !== null && !isDesktopOs(injectOs()),\n ).asReadonly();\n\n /** A single buzz. The duration is Android's; iOS vibrates for its own fixed length. */\n buzz(durationMs = 400): void {\n this.native?.vibrate(durationMs);\n }\n\n /**\n * A pattern of waits and buzzes, in milliseconds, starting with a wait.\n *\n * `repeat` runs it until `stop()`, which is for something that must be answered - an alarm, a\n * call - and is a promise to call `stop` rather than a decoration.\n */\n pattern(millis: readonly number[], options: { repeat?: boolean } = {}): void {\n this.native?.vibrate([...millis], options.repeat ?? false);\n }\n\n stop(): void {\n this.native?.cancel();\n }\n}\n"]}
@@ -21,7 +21,7 @@ const SETTINGS_KEY = 'ngNative.windows';
21
21
  */
22
22
  function settingsStore() {
23
23
  const os = injectOs();
24
- if (os !== 'macos' && os !== 'ios')
24
+ if (os !== 'macos' && os !== 'linux' && os !== 'ios')
25
25
  return null;
26
26
  const settings = reactNative()?.Settings;
27
27
  if (!settings)
@@ -1 +1 @@
1
- {"version":3,"file":"window-restore.js","sourceRoot":"","sources":["../src/window-restore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,cAAc,EACd,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA2BhD,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,IAAI,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAChD,MAAM,QAAQ,GAAG,WAAW,EAAE,EAAE,QAAQ,CAAC;IACzC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YACzC,IAAI,OAAO,GAAY,KAAK,CAAC;YAC7B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,IAAI,CAAC;oBACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC9B,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC;YACD,0FAA0F;YAC1F,2DAA2D;YAC3D,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;gBAC3B,CAAC,CAAC,OAAO,CAAC,MAAM,CACZ,CAAC,MAAM,EAA4B,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,CACpF;gBACH,CAAC,CAAC,EAAE,CAAC;QACT,CAAC;QACD,8FAA8F;QAC9F,0CAA0C;QAC1C,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;KAC9E,CAAC;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,cAAc,CACpD,mCAAmC,EACnC,EAAE,OAAO,EAAE,aAAa,EAAE,CAC3B,CAAC;AAEF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,cAAc,CAClD,kCAAkC,CACnC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAAmD;IAEnD,OAAO,wBAAwB,CAAC;QAC9B,EAAE,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE;KACnE,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Which windows open again after a reload or a relaunch, and what they rendered.\n *\n * The host, on macOS and on iPadOS, keeps a window that has a key across a reload, and closes it\n * unless the reloaded app opens that key again within a few seconds. So `AppWindows` writes down each window\n * with a key as it opens and forgets it as it closes, and a starting app opens every one it finds:\n * the main window, a route window at the path it was last opened at, and a `restoreKey` component\n * window with its inputs. A relaunch takes the same path, with the frames the host autosaved.\n *\n * A component is written down by the name `provideRestorableWindows` gives it, since a class name\n * does not survive minifying.\n */\nimport {\n InjectionToken,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\nimport type { WindowOptions } from './app-windows.ts';\n\n/** One window to open again. */\nexport type RestoredWindow =\n | { readonly kind: 'main' }\n | {\n readonly kind: 'route';\n readonly outlet: string;\n readonly path: string;\n readonly options: WindowOptions;\n }\n | {\n readonly kind: 'component';\n readonly key: string;\n /** The name `provideRestorableWindows` gave the component. */\n readonly component: string;\n readonly inputs?: Readonly<Record<string, unknown>>;\n readonly options: WindowOptions;\n };\n\n/** Where the windows to open again are kept between one run of the app and the next. */\nexport interface WindowRestoreStore {\n read(): readonly RestoredWindow[];\n write(windows: readonly RestoredWindow[]): void;\n}\n\nconst SETTINGS_KEY = 'ngNative.windows';\n\n/**\n * React Native's `Settings`, the app's user defaults, on macOS and iOS; null elsewhere. On iPadOS\n * the host keeps a window's scene across a reload, as the desktop host keeps the window, until the\n * reloaded app opens its key again.\n */\nfunction settingsStore(): WindowRestoreStore | null {\n const os = injectOs();\n if (os !== 'macos' && os !== 'ios') return null;\n const settings = reactNative()?.Settings;\n if (!settings) return null;\n return {\n read: () => {\n const saved = settings.get(SETTINGS_KEY);\n let records: unknown = saved;\n if (typeof saved === 'string') {\n try {\n records = JSON.parse(saved);\n } catch {\n return [];\n }\n }\n // A list as a property list too: what an earlier version saved still opens. Only records,\n // since a value written outside the app can hold anything.\n return Array.isArray(records)\n ? records.filter(\n (window): window is RestoredWindow => typeof window === 'object' && window !== null,\n )\n : [];\n },\n // As JSON: a property list drops null, from an object and from an array, so a window's inputs\n // would not come back as they were given.\n write: (windows) => settings.set({ [SETTINGS_KEY]: JSON.stringify(windows) }),\n };\n}\n\n/** The store `AppWindows` keeps its windows in. Overridden in a test with one in memory. */\nexport const WINDOW_RESTORE_STORE = new InjectionToken<WindowRestoreStore | null>(\n 'angular-native.windowRestoreStore',\n { factory: settingsStore },\n);\n\n/** The components a `restoreKey` window may render, named by `provideRestorableWindows`. */\nexport const RESTORABLE_WINDOWS = new InjectionToken<Readonly<Record<string, Type<unknown>>>[]>(\n 'angular-native.restorableWindows',\n);\n\n/**\n * Name the components that `AppWindows.open(component, { restoreKey })` may open, so the window\n * opens again after a reload or a relaunch: `provideRestorableWindows({ note: NoteWindow })`. Its\n * inputs are written down too, so they have to survive `JSON.stringify`.\n */\nexport function provideRestorableWindows(\n components: Readonly<Record<string, Type<unknown>>>,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: RESTORABLE_WINDOWS, useValue: components, multi: true },\n ]);\n}\n"]}
1
+ {"version":3,"file":"window-restore.js","sourceRoot":"","sources":["../src/window-restore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,cAAc,EACd,wBAAwB,GAGzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA2BhD,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACtB,IAAI,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAClE,MAAM,QAAQ,GAAG,WAAW,EAAE,EAAE,QAAQ,CAAC;IACzC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO;QACL,IAAI,EAAE,GAAG,EAAE;YACT,MAAM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\n * The host, on macOS and on iPadOS, keeps a window that has a key across a reload, and closes it\n * unless the reloaded app opens that key again within a few seconds. So `AppWindows` writes down each window\n * with a key as it opens and forgets it as it closes, and a starting app opens every one it finds:\n * the main window, a route window at the path it was last opened at, and a `restoreKey` component\n * window with its inputs. A relaunch takes the same path, with the frames the host autosaved.\n *\n * A component is written down by the name `provideRestorableWindows` gives it, since a class name\n * does not survive minifying.\n */\nimport {\n InjectionToken,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { injectOs } from './os.ts';\nimport { reactNative } from './react-native.ts';\nimport type { WindowOptions } from './app-windows.ts';\n\n/** One window to open again. */\nexport type RestoredWindow =\n | { readonly kind: 'main' }\n | {\n readonly kind: 'route';\n readonly outlet: string;\n readonly path: string;\n readonly options: WindowOptions;\n }\n | {\n readonly kind: 'component';\n readonly key: string;\n /** The name `provideRestorableWindows` gave the component. */\n readonly component: string;\n readonly inputs?: Readonly<Record<string, unknown>>;\n readonly options: WindowOptions;\n };\n\n/** Where the windows to open again are kept between one run of the app and the next. */\nexport interface WindowRestoreStore {\n read(): readonly RestoredWindow[];\n write(windows: readonly RestoredWindow[]): void;\n}\n\nconst SETTINGS_KEY = 'ngNative.windows';\n\n/**\n * React Native's `Settings`, the app's user defaults, on macOS and iOS; null elsewhere. On iPadOS\n * the host keeps a window's scene across a reload, as the desktop host keeps the window, until the\n * reloaded app opens its key again.\n */\nfunction settingsStore(): WindowRestoreStore | null {\n const os = injectOs();\n if (os !== 'macos' && os !== 'linux' && os !== 'ios') return null;\n const settings = reactNative()?.Settings;\n if (!settings) return null;\n return {\n read: () => {\n const saved = settings.get(SETTINGS_KEY);\n let records: unknown = saved;\n if (typeof saved === 'string') {\n try {\n records = JSON.parse(saved);\n } catch {\n return [];\n }\n }\n // A list as a property list too: what an earlier version saved still opens. Only records,\n // since a value written outside the app can hold anything.\n return Array.isArray(records)\n ? records.filter(\n (window): window is RestoredWindow => typeof window === 'object' && window !== null,\n )\n : [];\n },\n // As JSON: a property list drops null, from an object and from an array, so a window's inputs\n // would not come back as they were given.\n write: (windows) => settings.set({ [SETTINGS_KEY]: JSON.stringify(windows) }),\n };\n}\n\n/** The store `AppWindows` keeps its windows in. Overridden in a test with one in memory. */\nexport const WINDOW_RESTORE_STORE = new InjectionToken<WindowRestoreStore | null>(\n 'angular-native.windowRestoreStore',\n { factory: settingsStore },\n);\n\n/** The components a `restoreKey` window may render, named by `provideRestorableWindows`. */\nexport const RESTORABLE_WINDOWS = new InjectionToken<Readonly<Record<string, Type<unknown>>>[]>(\n 'angular-native.restorableWindows',\n);\n\n/**\n * Name the components that `AppWindows.open(component, { restoreKey })` may open, so the window\n * opens again after a reload or a relaunch: `provideRestorableWindows({ note: NoteWindow })`. Its\n * inputs are written down too, so they have to survive `JSON.stringify`.\n */\nexport function provideRestorableWindows(\n components: Readonly<Record<string, Type<unknown>>>,\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n { provide: RESTORABLE_WINDOWS, useValue: components, multi: true },\n ]);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/device",
3
- "version": "0.26.1",
3
+ "version": "0.28.0",
4
4
  "description": "Angular Native device services: keyboard, screen, color scheme, app state, accessibility, hardware back and deep links.",
5
5
  "keywords": [
6
6
  "angular",
@@ -17,7 +17,7 @@
17
17
  "type": "module",
18
18
  "main": "dist/index.js",
19
19
  "dependencies": {
20
- "@ng-native/fabric": "0.26.1"
20
+ "@ng-native/fabric": "0.28.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@angular/core": "^22.0.0",