@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.
- package/README.md +3 -3
- package/dist/contract.d.ts +12 -15
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +12 -15
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/tauriApp.d.ts +10 -3
- package/dist/tauriApp.d.ts.map +1 -1
- package/dist/tauriApp.js +51 -34
- package/dist/tauriApp.js.map +1 -1
- package/dist/tauriClipboard.d.ts +4 -3
- package/dist/tauriClipboard.d.ts.map +1 -1
- package/dist/tauriClipboard.js +11 -11
- package/dist/tauriClipboard.js.map +1 -1
- package/dist/tauriDialog.d.ts +8 -9
- package/dist/tauriDialog.d.ts.map +1 -1
- package/dist/tauriDialog.js +32 -25
- package/dist/tauriDialog.js.map +1 -1
- package/dist/tauriHost.d.ts +4 -0
- package/dist/tauriHost.d.ts.map +1 -0
- package/dist/tauriHost.js +70 -0
- package/dist/tauriHost.js.map +1 -0
- package/dist/tauriHostGroups.d.ts +85 -0
- package/dist/tauriHostGroups.d.ts.map +1 -0
- package/dist/tauriHostGroups.js +2 -0
- package/dist/tauriHostGroups.js.map +1 -0
- package/dist/tauriMenu.d.ts +6 -3
- package/dist/tauriMenu.d.ts.map +1 -1
- package/dist/tauriMenu.js +42 -26
- package/dist/tauriMenu.js.map +1 -1
- package/dist/tauriNotification.d.ts +6 -3
- package/dist/tauriNotification.d.ts.map +1 -1
- package/dist/tauriNotification.js +35 -20
- package/dist/tauriNotification.js.map +1 -1
- package/dist/tauriPlatform.d.ts +4 -3
- package/dist/tauriPlatform.d.ts.map +1 -1
- package/dist/tauriPlatform.js +6 -10
- package/dist/tauriPlatform.js.map +1 -1
- package/dist/tauriShell.d.ts +6 -5
- package/dist/tauriShell.d.ts.map +1 -1
- package/dist/tauriShell.js +24 -24
- package/dist/tauriShell.js.map +1 -1
- package/dist/tauriShortcut.d.ts +5 -5
- package/dist/tauriShortcut.d.ts.map +1 -1
- package/dist/tauriShortcut.js +20 -19
- package/dist/tauriShortcut.js.map +1 -1
- package/dist/tauriTray.d.ts +11 -3
- package/dist/tauriTray.d.ts.map +1 -1
- package/dist/tauriTray.js +260 -227
- package/dist/tauriTray.js.map +1 -1
- package/dist/tauriUnsupportedHostGroups.d.ts +70 -0
- package/dist/tauriUnsupportedHostGroups.d.ts.map +1 -0
- package/dist/tauriUnsupportedHostGroups.js +127 -0
- package/dist/tauriUnsupportedHostGroups.js.map +1 -0
- package/dist/tauriWindow.d.ts +5 -3
- package/dist/tauriWindow.d.ts.map +1 -1
- package/dist/tauriWindow.js +209 -132
- package/dist/tauriWindow.js.map +1 -1
- package/dist/types.d.ts +251 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -16
- package/src/tauriApp.test.ts +55 -12
- package/src/tauriClipboard.test.ts +13 -14
- package/src/tauriDialog.test.ts +37 -57
- package/src/tauriHost.test.ts +312 -0
- package/src/tauriMenu.test.ts +41 -26
- package/src/tauriNotification.test.ts +31 -13
- package/src/tauriPackage.test.ts +295 -0
- package/src/tauriPlatform.test.ts +16 -11
- package/src/tauriShell.test.ts +31 -34
- package/src/tauriShortcut.test.ts +15 -29
- package/src/tauriTray.test.ts +108 -49
- package/src/tauriUnsupportedHostGroups.test.ts +125 -0
- package/src/tauriWindow.test.ts +98 -85
- package/dist/tauriRegister.d.ts +0 -4
- package/dist/tauriRegister.d.ts.map +0 -1
- package/dist/tauriRegister.js +0 -69
- package/dist/tauriRegister.js.map +0 -1
- package/src/tauriRegister.test.ts +0 -91
package/dist/tauriShortcut.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { allocateEntity
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
10
|
-
const provider =
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
const subscription =
|
|
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
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"tauriShortcut.js","sourceRoot":"","sources":["../src/tauriShortcut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAW3D,MAAM,UAAU,iBAAiB,CAC/B,KAAe;IAEf,OAAO;QACL,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC;QACpC,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC;KACzC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAe;IACpD,MAAM,QAAQ,GAAG,EAAiC,CAAC;IACnD,QAAQ,CAAC,YAAY,GAAG,KAAK,EAAE,WAAw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AAK,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"}
|
package/dist/tauriTray.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { DesktopOsProfile,
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
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
|
package/dist/tauriTray.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tauriTray.d.ts","sourceRoot":"","sources":["../src/tauriTray.ts"],"names":[],"mappings":"
|
|
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,+BA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
import { createSignal, emitSignal } from '@flighthq/signals/contract';
|
|
3
|
-
export function
|
|
2
|
+
export function tauriHostTray(tauri, profile) {
|
|
4
3
|
const records = new Map();
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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 (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
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
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
|
215
|
+
await oldMenu.close();
|
|
216
|
+
record.menus.splice(record.menus.indexOf(oldMenu), 1);
|
|
129
217
|
}
|
|
130
218
|
catch (error) {
|
|
131
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
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
|
-
|
|
236
|
-
out
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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);
|