@flighthq/host-tauri 0.5.1-next.920.da8f530 → 0.6.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 (84) hide show
  1. package/README.md +3 -3
  2. package/dist/contract.d.ts +12 -15
  3. package/dist/contract.d.ts.map +1 -1
  4. package/dist/contract.js +12 -15
  5. package/dist/contract.js.map +1 -1
  6. package/dist/index.d.ts +12 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +12 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/tauriApp.d.ts +10 -3
  11. package/dist/tauriApp.d.ts.map +1 -1
  12. package/dist/tauriApp.js +51 -34
  13. package/dist/tauriApp.js.map +1 -1
  14. package/dist/tauriClipboard.d.ts +4 -3
  15. package/dist/tauriClipboard.d.ts.map +1 -1
  16. package/dist/tauriClipboard.js +11 -11
  17. package/dist/tauriClipboard.js.map +1 -1
  18. package/dist/tauriDialog.d.ts +8 -9
  19. package/dist/tauriDialog.d.ts.map +1 -1
  20. package/dist/tauriDialog.js +32 -25
  21. package/dist/tauriDialog.js.map +1 -1
  22. package/dist/tauriHost.d.ts +4 -0
  23. package/dist/tauriHost.d.ts.map +1 -0
  24. package/dist/tauriHost.js +70 -0
  25. package/dist/tauriHost.js.map +1 -0
  26. package/dist/tauriHostGroups.d.ts +85 -0
  27. package/dist/tauriHostGroups.d.ts.map +1 -0
  28. package/dist/tauriHostGroups.js +2 -0
  29. package/dist/tauriHostGroups.js.map +1 -0
  30. package/dist/tauriMenu.d.ts +6 -3
  31. package/dist/tauriMenu.d.ts.map +1 -1
  32. package/dist/tauriMenu.js +42 -26
  33. package/dist/tauriMenu.js.map +1 -1
  34. package/dist/tauriNotification.d.ts +6 -3
  35. package/dist/tauriNotification.d.ts.map +1 -1
  36. package/dist/tauriNotification.js +35 -20
  37. package/dist/tauriNotification.js.map +1 -1
  38. package/dist/tauriPlatform.d.ts +4 -3
  39. package/dist/tauriPlatform.d.ts.map +1 -1
  40. package/dist/tauriPlatform.js +6 -10
  41. package/dist/tauriPlatform.js.map +1 -1
  42. package/dist/tauriShell.d.ts +6 -5
  43. package/dist/tauriShell.d.ts.map +1 -1
  44. package/dist/tauriShell.js +24 -24
  45. package/dist/tauriShell.js.map +1 -1
  46. package/dist/tauriShortcut.d.ts +5 -5
  47. package/dist/tauriShortcut.d.ts.map +1 -1
  48. package/dist/tauriShortcut.js +20 -19
  49. package/dist/tauriShortcut.js.map +1 -1
  50. package/dist/tauriTray.d.ts +11 -3
  51. package/dist/tauriTray.d.ts.map +1 -1
  52. package/dist/tauriTray.js +260 -227
  53. package/dist/tauriTray.js.map +1 -1
  54. package/dist/tauriUnsupportedHostGroups.d.ts +70 -0
  55. package/dist/tauriUnsupportedHostGroups.d.ts.map +1 -0
  56. package/dist/tauriUnsupportedHostGroups.js +127 -0
  57. package/dist/tauriUnsupportedHostGroups.js.map +1 -0
  58. package/dist/tauriWindow.d.ts +5 -3
  59. package/dist/tauriWindow.d.ts.map +1 -1
  60. package/dist/tauriWindow.js +209 -132
  61. package/dist/tauriWindow.js.map +1 -1
  62. package/dist/types.d.ts +251 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +2 -0
  65. package/dist/types.js.map +1 -0
  66. package/package.json +40 -16
  67. package/src/tauriApp.test.ts +55 -12
  68. package/src/tauriClipboard.test.ts +13 -14
  69. package/src/tauriDialog.test.ts +37 -57
  70. package/src/tauriHost.test.ts +312 -0
  71. package/src/tauriMenu.test.ts +41 -26
  72. package/src/tauriNotification.test.ts +31 -13
  73. package/src/tauriPackage.test.ts +295 -0
  74. package/src/tauriPlatform.test.ts +16 -11
  75. package/src/tauriShell.test.ts +31 -34
  76. package/src/tauriShortcut.test.ts +15 -29
  77. package/src/tauriTray.test.ts +108 -49
  78. package/src/tauriUnsupportedHostGroups.test.ts +125 -0
  79. package/src/tauriWindow.test.ts +98 -85
  80. package/dist/tauriRegister.d.ts +0 -4
  81. package/dist/tauriRegister.d.ts.map +0 -1
  82. package/dist/tauriRegister.js +0 -69
  83. package/dist/tauriRegister.js.map +0 -1
  84. package/src/tauriRegister.test.ts +0 -91
@@ -1,22 +1,22 @@
1
- import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
- export function createTauriShortcutQueryBackend(tauri) {
3
- const provider = allocateEntity();
4
- initializeTauriShortcutQueryBackend(provider, tauri.globalShortcut);
1
+ import { allocateEntity } from '@flighthq/entity/contract';
2
+ export function tauriHostShortcut(tauri) {
3
+ return {
4
+ query: tauriHostShortcutQuery(tauri),
5
+ trigger: tauriHostShortcutTrigger(tauri),
6
+ };
7
+ }
8
+ export function tauriHostShortcutQuery(tauri) {
9
+ const provider = {};
10
+ provider.isRegistered = async (accelerator) => {
11
+ return await tauri.globalShortcut.isRegistered(accelerator);
12
+ };
5
13
  return provider;
6
14
  }
7
15
  // Tauri's plugin is async at every boundary. Registrations enter the owned ledger only after native
8
16
  // acquisition settles; failed unregisters remain there so destroy or an exact-token retry can release them.
9
- export function createTauriShortcutTriggerBackend(tauri) {
10
- const provider = allocateEntity();
11
- initializeTauriShortcutTriggerBackend(provider, tauri.globalShortcut);
12
- return finishEntity(provider);
13
- }
14
- export function initializeTauriShortcutQueryBackend(out, globalShortcut) {
15
- out.isRegistered = async (accelerator) => {
16
- return await globalShortcut.isRegistered(accelerator);
17
- };
18
- }
19
- export function initializeTauriShortcutTriggerBackend(out, globalShortcut) {
17
+ export function tauriHostShortcutTrigger(tauri) {
18
+ const provider = {};
19
+ const globalShortcut = tauri.globalShortcut;
20
20
  const registrations = new Map();
21
21
  const pending = new Set();
22
22
  async function releaseAccelerator(accelerator) {
@@ -26,7 +26,7 @@ export function initializeTauriShortcutTriggerBackend(out, globalShortcut) {
26
26
  registrations.delete(subscription);
27
27
  }
28
28
  }
29
- out.destroy = async () => {
29
+ provider.destroy = async () => {
30
30
  await Promise.allSettled([...pending]);
31
31
  let firstError;
32
32
  const accelerators = new Set(registrations.values());
@@ -42,8 +42,8 @@ export function initializeTauriShortcutTriggerBackend(out, globalShortcut) {
42
42
  if (firstError !== undefined)
43
43
  throw firstError;
44
44
  };
45
- out.subscribe = async (accelerator, trigger) => {
46
- const subscription = finishEntity(allocateEntity());
45
+ provider.subscribe = async (accelerator, trigger) => {
46
+ const subscription = allocateEntity();
47
47
  const registration = globalShortcut.register(accelerator, (event) => {
48
48
  if (event.state === 'Pressed' && registrations.has(subscription))
49
49
  trigger();
@@ -58,12 +58,13 @@ export function initializeTauriShortcutTriggerBackend(out, globalShortcut) {
58
58
  pending.delete(registration);
59
59
  }
60
60
  };
61
- out.unsubscribe = async (subscription) => {
61
+ provider.unsubscribe = async (subscription) => {
62
62
  const accelerator = registrations.get(subscription);
63
63
  if (accelerator === undefined)
64
64
  return { reason: 'unknown-subscription' };
65
65
  await releaseAccelerator(accelerator);
66
66
  return { reason: 'unsubscribed' };
67
67
  };
68
+ return provider;
68
69
  }
69
70
  //# sourceMappingURL=tauriShortcut.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tauriShortcut.js","sourceRoot":"","sources":["../src/tauriShortcut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAWzE,MAAM,UAAU,+BAA+B,CAAC,KAAe;IAC7D,MAAM,QAAQ,GAAG,cAAc,EAAwB,CAAC;IACxD,mCAAmC,CAAC,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACpE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,oGAAoG;AACpG,4GAA4G;AAC5G,MAAM,UAAU,iCAAiC,CAAC,KAAe;IAC/D,MAAM,QAAQ,GAAG,cAAc,EAA0B,CAAC;IAC1D,qCAAqC,CAAC,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;IACtE,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,mCAAmC,CACjD,GAA6C,EAC7C,cAA0C;IAE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AU,CAAC;IACjD,CAAC,CAAC;IACF,QAAQ,CAAC,SAAS,GAAG,KAAK,EAAE,WAAwB,EAAE,OAAmB,EAAE,EAAE;QAC3E,MAAM,YAAY,GAAG,cAAc,EAA+B,CAAC;QACnE,MAAM,YAAY,GAAG,cAAc,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YAClE,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,IAAI,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC;gBAAE,OAAO,EAAE,CAAC;QAC9E,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,YAAY,CAAC;YACnB,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;YAC7C,OAAO,EAAE,MAAM,EAAE,YAAqB,EAAE,YAAY,EAAE,CAAC;QACzD,CAAC;gBAAS,CAAC;YACT,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC,CAAC;IACF,QAAQ,CAAC,WAAW,GAAG,KAAK,EAAE,YAAyC,EAAE,EAAE;QACzE,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,WAAW,KAAK,SAAS;YAAE,OAAO,EAAE,MAAM,EAAE,sBAA+B,EAAE,CAAC;QAClF,MAAM,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACtC,OAAO,EAAE,MAAM,EAAE,cAAuB,EAAE,CAAC;IAC7C,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,4 +1,12 @@
1
- import type { DesktopOsProfile, Entity, EntityConstruction, TauriApi, TauriTrayCapabilitiesFor, TrayImageBackend, TrayInteractionEventsBackend, TrayLifecycleBackend, TrayMenuBackend, TrayMenuSelectionEventsBackend, TrayTemplateImageBackend, TrayTitleBackend, TrayTooltipBackend } from '@flighthq/types/contract';
2
- export declare function createTauriTrayCapabilities<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): TauriTrayCapabilitiesFor<Profile>;
3
- export declare function initializeTauriTrayCapabilities(out: EntityConstruction<Entity>, image: TrayImageBackend, interactionEvents: TrayInteractionEventsBackend | null, lifecycle: TrayLifecycleBackend, menu: TrayMenuBackend, menuSelectionEvents: TrayMenuSelectionEventsBackend, templateImage: TrayTemplateImageBackend | null, title: TrayTitleBackend | null, tooltip: TrayTooltipBackend | null): void;
1
+ import type { DesktopOsProfile, HostTrayImageCapability, HostTrayInteractionEventsCapability, HostTrayLifecycleCapability, HostTrayMenuCapability, HostTrayMenuSelectionEventsCapability, HostTrayTemplateImageCapability, HostTrayTitleCapability, HostTrayTooltipCapability } from '@flighthq/tray/contract';
2
+ import type { TauriApi, TauriTrayCapabilitiesFor } from './types.ts';
3
+ export declare function tauriHostTray<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): TauriTrayCapabilitiesFor<Profile>;
4
+ export declare function tauriHostTrayImage<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): HostTrayImageCapability;
5
+ export declare function tauriHostTrayInteractionEvents(tauri: TauriApi, profile: 'macos' | 'windows'): HostTrayInteractionEventsCapability;
6
+ export declare function tauriHostTrayLifecycle<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): HostTrayLifecycleCapability;
7
+ export declare function tauriHostTrayMenu<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): HostTrayMenuCapability;
8
+ export declare function tauriHostTrayMenuSelectionEvents<Profile extends DesktopOsProfile>(tauri: TauriApi, profile: Profile): HostTrayMenuSelectionEventsCapability;
9
+ export declare function tauriHostTrayTemplateImage(tauri: TauriApi): HostTrayTemplateImageCapability;
10
+ export declare function tauriHostTrayTitle(tauri: TauriApi, profile: 'linux' | 'macos'): HostTrayTitleCapability;
11
+ export declare function tauriHostTrayTooltip(tauri: TauriApi, profile: 'macos' | 'windows'): HostTrayTooltipCapability;
4
12
  //# sourceMappingURL=tauriTray.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tauriTray.d.ts","sourceRoot":"","sources":["../src/tauriTray.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,MAAM,EACN,kBAAkB,EAGlB,QAAQ,EAMR,wBAAwB,EAGxB,gBAAgB,EAEhB,4BAA4B,EAC5B,oBAAoB,EACpB,eAAe,EAEf,8BAA8B,EAC9B,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAelC,wBAAgB,2BAA2B,CAAC,OAAO,SAAS,gBAAgB,EAC1E,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,wBAAwB,CAAC,OAAO,CAAC,CAiQnC;AAED,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,kBAAkB,CAAC,MAAM,CAAC,EAC/B,KAAK,EAAE,gBAAgB,EACvB,iBAAiB,EAAE,4BAA4B,GAAG,IAAI,EACtD,SAAS,EAAE,oBAAoB,EAC/B,IAAI,EAAE,eAAe,EACrB,mBAAmB,EAAE,8BAA8B,EACnD,aAAa,EAAE,wBAAwB,GAAG,IAAI,EAC9C,KAAK,EAAE,gBAAgB,GAAG,IAAI,EAC9B,OAAO,EAAE,kBAAkB,GAAG,IAAI,GACjC,IAAI,CASN"}
1
+ {"version":3,"file":"tauriTray.d.ts","sourceRoot":"","sources":["../src/tauriTray.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,mCAAmC,EACnC,2BAA2B,EAC3B,sBAAsB,EACtB,qCAAqC,EACrC,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EAK1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EACV,QAAQ,EAGR,wBAAwB,EAIzB,MAAM,YAAY,CAAC;AAepB,wBAAgB,aAAa,CAAC,OAAO,SAAS,gBAAgB,EAC5D,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,wBAAwB,CAAC,OAAO,CAAC,CAoCnC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,gBAAgB,EACjE,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,uBAAuB,CAIzB;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GAAG,SAAS,GAC3B,mCAAmC,CAIrC;AAED,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,gBAAgB,EACrE,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,2BAA2B,CAE7B;AAED,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,gBAAgB,EAChE,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,sBAAsB,CAGxB;AAED,wBAAgB,gCAAgC,CAAC,OAAO,SAAS,gBAAgB,EAC/E,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,OAAO,GACf,qCAAqC,CAIvC;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,QAAQ,GAAG,+BAA+B,CAG3F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,uBAAuB,CAIvG;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,GAAG,yBAAyB,CAI7G"}
package/dist/tauriTray.js CHANGED
@@ -1,250 +1,283 @@
1
- import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
1
  import { createSignal, emitSignal } from '@flighthq/signals/contract';
3
- export function createTauriTrayCapabilities(tauri, profile) {
2
+ export function tauriHostTray(tauri, profile) {
4
3
  const records = new Map();
5
- const lifecycle = (() => {
6
- const out = allocateEntity();
7
- out.create = async (tray, options) => {
8
- if (options.signal?.aborted)
9
- return { outcome: 'cancelled' };
10
- const interactionEvents = createSignal();
11
- const menuSelectionEvents = createSignal();
12
- const nativeOptions = {
13
- action: (event) => emitInteraction(interactionEvents, event),
14
- icon: options.icon,
15
- };
16
- if (profile === 'linux' || profile === 'macos')
17
- nativeOptions.title = options.title;
18
- if (profile === 'windows' || profile === 'macos')
19
- nativeOptions.tooltip = options.tooltip;
20
- if (profile === 'macos')
21
- nativeOptions.iconAsTemplate = options.iconTemplate;
22
- let icon;
4
+ const common = {
5
+ image: createTrayImage(records),
6
+ lifecycle: createTrayLifecycle(tauri, profile, records),
7
+ menu: createTrayMenu(tauri, records),
8
+ menuSelectionEvents: createTrayMenuSelectionEvents(records),
9
+ };
10
+ if (profile === 'linux') {
11
+ // Double cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that cannot be narrowed statically.
12
+ return Object.freeze({
13
+ ...common,
14
+ title: createTrayTitle(records),
15
+ });
16
+ }
17
+ const interactionEvents = createTrayInteractionEvents(records);
18
+ const tooltip = createTrayTooltip(records);
19
+ if (profile === 'windows') {
20
+ // Double cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that cannot be narrowed statically.
21
+ return Object.freeze({
22
+ ...common,
23
+ interactionEvents,
24
+ tooltip,
25
+ });
26
+ }
27
+ // Double cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that cannot be narrowed statically.
28
+ return Object.freeze({
29
+ ...common,
30
+ interactionEvents,
31
+ templateImage: createTrayTemplateImage(records),
32
+ title: createTrayTitle(records),
33
+ tooltip,
34
+ });
35
+ }
36
+ export function tauriHostTrayImage(tauri, profile) {
37
+ void tauri;
38
+ void profile;
39
+ return createTrayImage(new Map());
40
+ }
41
+ export function tauriHostTrayInteractionEvents(tauri, profile) {
42
+ void tauri;
43
+ void profile;
44
+ return createTrayInteractionEvents(new Map());
45
+ }
46
+ export function tauriHostTrayLifecycle(tauri, profile) {
47
+ return createTrayLifecycle(tauri, profile, new Map());
48
+ }
49
+ export function tauriHostTrayMenu(tauri, profile) {
50
+ void profile;
51
+ return createTrayMenu(tauri, new Map());
52
+ }
53
+ export function tauriHostTrayMenuSelectionEvents(tauri, profile) {
54
+ void tauri;
55
+ void profile;
56
+ return createTrayMenuSelectionEvents(new Map());
57
+ }
58
+ export function tauriHostTrayTemplateImage(tauri) {
59
+ void tauri;
60
+ return createTrayTemplateImage(new Map());
61
+ }
62
+ export function tauriHostTrayTitle(tauri, profile) {
63
+ void tauri;
64
+ void profile;
65
+ return createTrayTitle(new Map());
66
+ }
67
+ export function tauriHostTrayTooltip(tauri, profile) {
68
+ void tauri;
69
+ void profile;
70
+ return createTrayTooltip(new Map());
71
+ }
72
+ function createTrayLifecycle(tauri, profile, records) {
73
+ const out = {};
74
+ out.create = async (tray, options) => {
75
+ if (options.signal?.aborted)
76
+ return { outcome: 'cancelled' };
77
+ const interactionEvents = createSignal();
78
+ const menuSelectionEvents = createSignal();
79
+ const nativeOptions = {
80
+ action: (event) => emitInteraction(interactionEvents, event),
81
+ icon: options.icon,
82
+ };
83
+ if (profile === 'linux' || profile === 'macos')
84
+ nativeOptions.title = options.title;
85
+ if (profile === 'windows' || profile === 'macos')
86
+ nativeOptions.tooltip = options.tooltip;
87
+ if (profile === 'macos')
88
+ nativeOptions.iconAsTemplate = options.iconTemplate;
89
+ let icon;
90
+ try {
91
+ icon = await tauri.tray.TrayIcon.new(nativeOptions);
92
+ }
93
+ catch (error) {
94
+ return { error, outcome: 'tray-create-failed' };
95
+ }
96
+ if (options.signal?.aborted) {
23
97
  try {
24
- icon = await tauri.tray.TrayIcon.new(nativeOptions);
98
+ await icon.close();
99
+ return { outcome: 'cancelled' };
25
100
  }
26
101
  catch (error) {
27
102
  return { error, outcome: 'tray-create-failed' };
28
103
  }
29
- if (options.signal?.aborted) {
30
- try {
31
- await icon.close();
32
- return { outcome: 'cancelled' };
33
- }
34
- catch (error) {
35
- return { error, outcome: 'tray-create-failed' };
36
- }
104
+ }
105
+ records.set(tray, {
106
+ destroying: false,
107
+ icon,
108
+ interactionEvents,
109
+ menuGeneration: 0,
110
+ menus: [],
111
+ menuSelectionEvents,
112
+ nativePending: true,
113
+ pendingMenuOperations: new Set(),
114
+ title: options.title ?? '',
115
+ tooltip: options.tooltip ?? '',
116
+ });
117
+ return { outcome: 'created' };
118
+ };
119
+ out.destroy = async (tray) => {
120
+ const record = records.get(tray);
121
+ if (record === undefined)
122
+ return { outcome: 'destroyed' };
123
+ record.destroying = true;
124
+ record.menuGeneration++;
125
+ await Promise.all([...record.pendingMenuOperations]);
126
+ const failures = [];
127
+ for (let index = record.menus.length - 1; index >= 0; index--) {
128
+ let closed = false;
129
+ try {
130
+ await record.menus[index].close();
131
+ closed = true;
37
132
  }
38
- records.set(tray, {
39
- destroying: false,
40
- icon,
41
- interactionEvents,
42
- menuGeneration: 0,
43
- menus: [],
44
- menuSelectionEvents,
45
- nativePending: true,
46
- pendingMenuOperations: new Set(),
47
- title: options.title ?? '',
48
- tooltip: options.tooltip ?? '',
49
- });
50
- return { outcome: 'created' };
51
- };
52
- out.destroy = async (tray) => {
53
- const record = records.get(tray);
54
- if (record === undefined)
55
- return { outcome: 'destroyed' };
56
- record.destroying = true;
57
- record.menuGeneration++;
58
- await Promise.all([...record.pendingMenuOperations]);
59
- const failures = [];
60
- for (let index = record.menus.length - 1; index >= 0; index--) {
61
- let closed = false;
62
- try {
63
- await record.menus[index].close();
64
- closed = true;
65
- }
66
- catch (error) {
67
- failures.push({ error, step: 'native-resource' });
68
- }
69
- if (closed)
70
- record.menus.splice(index, 1);
133
+ catch (error) {
134
+ failures.push({ error, step: 'native-resource' });
71
135
  }
72
- if (record.nativePending) {
73
- try {
74
- await record.icon.close();
75
- record.nativePending = false;
76
- }
77
- catch (error) {
78
- failures.push({ error, step: 'native-resource' });
79
- }
136
+ if (closed)
137
+ record.menus.splice(index, 1);
138
+ }
139
+ if (record.nativePending) {
140
+ try {
141
+ await record.icon.close();
142
+ record.nativePending = false;
80
143
  }
81
- if (failures.length > 0)
82
- return { failures, outcome: 'tray-destroy-failed' };
83
- records.delete(tray);
84
- return { outcome: 'destroyed' };
85
- };
86
- out.isDestroyed = (tray) => records.get(tray)?.destroying ?? true;
87
- out.list = () => [...records.entries()].filter(([, record]) => !record.destroying).map(([tray]) => tray);
88
- return finishEntity(out);
89
- })();
90
- const image = (() => {
91
- const out = allocateEntity();
92
- out.set = async (tray, icon) => {
93
- return update(records, tray, 'image-update-failed', async (record) => record.icon.setIcon(icon));
94
- };
95
- return finishEntity(out);
96
- })();
97
- const menu = (() => {
98
- const out = allocateEntity();
99
- out.set = async (tray, items) => {
100
- const record = activeRecord(records, tray);
101
- if (record === null)
102
- return { outcome: 'tray-destroyed' };
103
- let finishOperation;
104
- const pendingOperation = new Promise((resolve) => {
105
- finishOperation = resolve;
106
- });
107
- record.pendingMenuOperations.add(pendingOperation);
144
+ catch (error) {
145
+ failures.push({ error, step: 'native-resource' });
146
+ }
147
+ }
148
+ if (failures.length > 0)
149
+ return { failures, outcome: 'tray-destroy-failed' };
150
+ records.delete(tray);
151
+ return { outcome: 'destroyed' };
152
+ };
153
+ out.isDestroyed = (tray) => records.get(tray)?.destroying ?? true;
154
+ out.list = () => [...records.entries()].filter(([, record]) => !record.destroying).map(([tray]) => tray);
155
+ return out;
156
+ }
157
+ function createTrayImage(records) {
158
+ const out = {};
159
+ out.set = async (tray, icon) => {
160
+ return update(records, tray, 'image-update-failed', async (record) => record.icon.setIcon(icon));
161
+ };
162
+ return out;
163
+ }
164
+ function createTrayMenu(tauri, records) {
165
+ const out = {};
166
+ out.set = async (tray, items) => {
167
+ const record = activeRecord(records, tray);
168
+ if (record === null)
169
+ return { outcome: 'tray-destroyed' };
170
+ let finishOperation;
171
+ const pendingOperation = new Promise((resolve) => {
172
+ finishOperation = resolve;
173
+ });
174
+ record.pendingMenuOperations.add(pendingOperation);
175
+ try {
176
+ const generation = ++record.menuGeneration;
177
+ let built;
108
178
  try {
109
- const generation = ++record.menuGeneration;
110
- let built;
111
- try {
112
- const handles = await buildTrayItems(tauri.menu, items, (id) => emitSignal(record.menuSelectionEvents, { id }));
113
- built = await tauri.menu.Menu.new({ items: handles });
114
- }
115
- catch (error) {
116
- return { error, outcome: 'menu-build-failed' };
117
- }
118
- if (record.destroying || generation !== record.menuGeneration) {
119
- await closeStaleMenu(record, built);
120
- return record.destroying
121
- ? { outcome: 'tray-destroyed' }
122
- : {
123
- error: new Error('A newer Tray menu superseded this build'),
124
- outcome: 'menu-install-failed',
125
- };
126
- }
179
+ const handles = await buildTrayItems(tauri.menu, items, (id) => emitSignal(record.menuSelectionEvents, { id }));
180
+ built = await tauri.menu.Menu.new({ items: handles });
181
+ }
182
+ catch (error) {
183
+ return { error, outcome: 'menu-build-failed' };
184
+ }
185
+ if (record.destroying || generation !== record.menuGeneration) {
186
+ await closeStaleMenu(record, built);
187
+ return record.destroying
188
+ ? { outcome: 'tray-destroyed' }
189
+ : {
190
+ error: new Error('A newer Tray menu superseded this build'),
191
+ outcome: 'menu-install-failed',
192
+ };
193
+ }
194
+ try {
195
+ await record.icon.setMenu(built);
196
+ }
197
+ catch (error) {
198
+ await closeStaleMenu(record, built);
199
+ return { error, outcome: 'menu-install-failed' };
200
+ }
201
+ if (record.destroying || generation !== record.menuGeneration) {
202
+ await closeStaleMenu(record, built);
203
+ return record.destroying
204
+ ? { outcome: 'tray-destroyed' }
205
+ : {
206
+ error: new Error('A newer Tray menu superseded this install'),
207
+ outcome: 'menu-install-failed',
208
+ };
209
+ }
210
+ const previous = record.menus.slice();
211
+ record.menus.push(built);
212
+ const failures = [];
213
+ for (const oldMenu of previous) {
127
214
  try {
128
- await record.icon.setMenu(built);
215
+ await oldMenu.close();
216
+ record.menus.splice(record.menus.indexOf(oldMenu), 1);
129
217
  }
130
218
  catch (error) {
131
- await closeStaleMenu(record, built);
132
- return { error, outcome: 'menu-install-failed' };
133
- }
134
- if (record.destroying || generation !== record.menuGeneration) {
135
- await closeStaleMenu(record, built);
136
- return record.destroying
137
- ? { outcome: 'tray-destroyed' }
138
- : {
139
- error: new Error('A newer Tray menu superseded this install'),
140
- outcome: 'menu-install-failed',
141
- };
219
+ failures.push(error);
142
220
  }
143
- const previous = record.menus.slice();
144
- record.menus.push(built);
145
- const failures = [];
146
- for (const oldMenu of previous) {
147
- try {
148
- await oldMenu.close();
149
- record.menus.splice(record.menus.indexOf(oldMenu), 1);
150
- }
151
- catch (error) {
152
- failures.push(error);
153
- }
154
- }
155
- return failures.length === 0
156
- ? { outcome: 'updated' }
157
- : { error: failures, outcome: 'menu-install-failed' };
158
- }
159
- finally {
160
- record.pendingMenuOperations.delete(pendingOperation);
161
- finishOperation();
162
221
  }
163
- };
164
- return finishEntity(out);
165
- })();
166
- const common = {
167
- image,
168
- lifecycle,
169
- menu,
170
- menuSelectionEvents: (() => {
171
- const out = allocateEntity();
172
- out.getSignal = (tray) => activeRecord(records, tray)?.menuSelectionEvents ?? null;
173
- return finishEntity(out);
174
- })(),
222
+ return failures.length === 0
223
+ ? { outcome: 'updated' }
224
+ : { error: failures, outcome: 'menu-install-failed' };
225
+ }
226
+ finally {
227
+ record.pendingMenuOperations.delete(pendingOperation);
228
+ finishOperation();
229
+ }
175
230
  };
176
- const title = (() => {
177
- const out = allocateEntity();
178
- out.get = async (tray) => {
179
- const record = activeRecord(records, tray);
180
- return record === null
181
- ? { outcome: 'tray-destroyed' }
182
- : { outcome: 'available', title: record.title };
183
- };
184
- out.set = async (tray, value) => {
185
- const result = await update(records, tray, 'title-update-failed', async (record) => record.icon.setTitle(value));
186
- if (result.outcome === 'updated')
187
- records.get(tray).title = value;
188
- return result;
189
- };
190
- return finishEntity(out);
191
- })();
192
- if (profile === 'linux') {
193
- // Entity + cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that allocateEntity cannot see through.
194
- const out = allocateEntity();
195
- initializeTauriTrayCapabilities(out, common.image, null, common.lifecycle, common.menu, common.menuSelectionEvents, null, title, null);
196
- return finishEntity(out);
197
- }
198
- const interactionEvents = (() => {
199
- const out = allocateEntity();
200
- out.getSignal = (tray) => activeRecord(records, tray)?.interactionEvents ?? null;
201
- return finishEntity(out);
202
- })();
203
- const tooltip = (() => {
204
- const out = allocateEntity();
205
- out.get = async (tray) => {
206
- const record = activeRecord(records, tray);
207
- return record === null
208
- ? { outcome: 'tray-destroyed' }
209
- : { outcome: 'available', tooltip: record.tooltip };
210
- };
211
- out.set = async (tray, value) => {
212
- const result = await update(records, tray, 'tooltip-update-failed', async (record) => record.icon.setTooltip(value));
213
- if (result.outcome === 'updated')
214
- records.get(tray).tooltip = value;
215
- return result;
216
- };
217
- return finishEntity(out);
218
- })();
219
- if (profile === 'windows') {
220
- // Entity + cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that allocateEntity cannot see through.
221
- const out = allocateEntity();
222
- initializeTauriTrayCapabilities(out, common.image, interactionEvents, common.lifecycle, common.menu, common.menuSelectionEvents, null, null, tooltip);
223
- return finishEntity(out);
224
- }
225
- const templateImageEntity = allocateEntity();
226
- templateImageEntity.set = async (tray, isTemplate) => {
231
+ return out;
232
+ }
233
+ function createTrayMenuSelectionEvents(records) {
234
+ const out = {};
235
+ out.getSignal = (tray) => activeRecord(records, tray)?.menuSelectionEvents ?? null;
236
+ return out;
237
+ }
238
+ function createTrayInteractionEvents(records) {
239
+ const out = {};
240
+ out.getSignal = (tray) => activeRecord(records, tray)?.interactionEvents ?? null;
241
+ return out;
242
+ }
243
+ function createTrayTemplateImage(records) {
244
+ const out = {};
245
+ out.set = async (tray, isTemplate) => {
227
246
  return update(records, tray, 'template-image-update-failed', async (record) => record.icon.setIconAsTemplate(isTemplate));
228
247
  };
229
- const templateImage = finishEntity(templateImageEntity);
230
- // Entity + cast: TauriTrayCapabilitiesFor<Profile> is a conditional type that allocateEntity cannot see through.
231
- const out = allocateEntity();
232
- initializeTauriTrayCapabilities(out, common.image, interactionEvents, common.lifecycle, common.menu, common.menuSelectionEvents, templateImage, title, tooltip);
233
- return finishEntity(out);
248
+ return out;
234
249
  }
235
- export function initializeTauriTrayCapabilities(out, image, interactionEvents, lifecycle, menu, menuSelectionEvents, templateImage, title, tooltip) {
236
- out.image = image;
237
- if (interactionEvents !== null)
238
- out.interactionEvents = interactionEvents;
239
- out.lifecycle = lifecycle;
240
- out.menu = menu;
241
- out.menuSelectionEvents = menuSelectionEvents;
242
- if (templateImage !== null)
243
- out.templateImage = templateImage;
244
- if (title !== null)
245
- out.title = title;
246
- if (tooltip !== null)
247
- out.tooltip = tooltip;
250
+ function createTrayTitle(records) {
251
+ const out = {};
252
+ out.get = async (tray) => {
253
+ const record = activeRecord(records, tray);
254
+ return record === null
255
+ ? { outcome: 'tray-destroyed' }
256
+ : { outcome: 'available', title: record.title };
257
+ };
258
+ out.set = async (tray, value) => {
259
+ const result = await update(records, tray, 'title-update-failed', async (record) => record.icon.setTitle(value));
260
+ if (result.outcome === 'updated')
261
+ records.get(tray).title = value;
262
+ return result;
263
+ };
264
+ return out;
265
+ }
266
+ function createTrayTooltip(records) {
267
+ const out = {};
268
+ out.get = async (tray) => {
269
+ const record = activeRecord(records, tray);
270
+ return record === null
271
+ ? { outcome: 'tray-destroyed' }
272
+ : { outcome: 'available', tooltip: record.tooltip };
273
+ };
274
+ out.set = async (tray, value) => {
275
+ const result = await update(records, tray, 'tooltip-update-failed', async (record) => record.icon.setTooltip(value));
276
+ if (result.outcome === 'updated')
277
+ records.get(tray).tooltip = value;
278
+ return result;
279
+ };
280
+ return out;
248
281
  }
249
282
  function activeRecord(records, tray) {
250
283
  const record = records.get(tray);