@flighthq/tray 0.5.1-next.973.788d3d7 → 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/.tsbuildinfo.contract +1 -0
- package/dist/.tsbuildinfo.runtime +1 -0
- package/dist/contract.d.ts +2 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -2
- package/dist/contract.js.map +1 -1
- package/dist/contract.tray-types.d.ts +2 -0
- package/dist/contract.tray-types.d.ts.map +1 -0
- package/dist/contract.tray-types.js +4 -0
- package/dist/contract.tray-types.js.map +1 -0
- package/dist/enableTrayGuards.d.ts +2 -1
- package/dist/enableTrayGuards.d.ts.map +1 -1
- package/dist/enableTrayGuards.js +6 -7
- package/dist/enableTrayGuards.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +3 -0
- package/dist/runtime.js.map +1 -0
- package/dist/tray.d.ts +30 -22
- package/dist/tray.d.ts.map +1 -1
- package/dist/tray.js +58 -61
- package/dist/tray.js.map +1 -1
- package/dist/types.d.ts +307 -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 +10 -7
- package/src/enableTrayGuards.test.ts +23 -20
- package/src/tray.test.ts +127 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/tray",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,20 +32,23 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc -b",
|
|
34
34
|
"clean": "tsc -b --clean",
|
|
35
|
+
"generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-tray --package tray",
|
|
36
|
+
"generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-tray --package tray --check",
|
|
35
37
|
"test": "vitest run --config vitest.config.ts",
|
|
36
38
|
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
37
39
|
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
38
40
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.
|
|
42
|
-
"@flighthq/
|
|
43
|
-
"@flighthq/
|
|
44
|
-
"@flighthq/
|
|
43
|
+
"@flighthq/entity": "0.6.0",
|
|
44
|
+
"@flighthq/geometry": "0.6.0",
|
|
45
|
+
"@flighthq/log": "0.6.0",
|
|
46
|
+
"@flighthq/menu": "0.6.0",
|
|
47
|
+
"@flighthq/signals": "0.6.0"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
|
-
"typescript": "^
|
|
50
|
+
"typescript": "^7.0.2"
|
|
48
51
|
},
|
|
49
|
-
"description": "
|
|
52
|
+
"description": "Tray icon Entities over explicitly injected operation providers",
|
|
50
53
|
"sideEffects": false
|
|
51
54
|
}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { allocateEntity
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { allocateEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { LogEntry, LogState } from '@flighthq/log/contract';
|
|
3
|
+
import { createLogState, setLogSink } from '@flighthq/log/contract';
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
|
-
import { disableTrayGuards, enableTrayGuards } from './enableTrayGuards';
|
|
7
|
-
import { createTrayIcon, destroyTrayIcon, startTrayIconAnimation } from './tray';
|
|
6
|
+
import { disableTrayGuards, enableTrayGuards } from './enableTrayGuards.ts';
|
|
7
|
+
import { createTrayIcon, destroyTrayIcon, startTrayIconAnimation } from './tray.ts';
|
|
8
|
+
import type { TrayIcon } from './types.ts';
|
|
8
9
|
|
|
9
10
|
let entries: LogEntry[];
|
|
11
|
+
let logState: LogState;
|
|
10
12
|
|
|
11
13
|
beforeEach(() => {
|
|
12
|
-
clearLogOnceKeys();
|
|
13
14
|
vi.useFakeTimers();
|
|
14
15
|
entries = [];
|
|
15
|
-
|
|
16
|
+
logState = createLogState();
|
|
17
|
+
setLogSink(logState, (entry) => entries.push(entry));
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
afterEach(() => {
|
|
19
21
|
disableTrayGuards();
|
|
20
|
-
setLogSink(null);
|
|
22
|
+
setLogSink(logState, null);
|
|
21
23
|
vi.useRealTimers();
|
|
22
24
|
});
|
|
23
25
|
|
|
@@ -26,7 +28,7 @@ function host() {
|
|
|
26
28
|
return {
|
|
27
29
|
tray: {
|
|
28
30
|
lifecycle: (() => {
|
|
29
|
-
const out = allocateEntity<any>();
|
|
31
|
+
const out = allocateEntity<any>() as any;
|
|
30
32
|
out.create = async (tray: TrayIcon) => {
|
|
31
33
|
live.push(tray);
|
|
32
34
|
return { outcome: 'created' as const };
|
|
@@ -37,23 +39,24 @@ function host() {
|
|
|
37
39
|
};
|
|
38
40
|
out.isDestroyed = (tray: TrayIcon) => !live.includes(tray);
|
|
39
41
|
out.list = () => live.slice();
|
|
40
|
-
return
|
|
42
|
+
return out;
|
|
41
43
|
})(),
|
|
42
44
|
image: (() => {
|
|
43
|
-
const out = allocateEntity<any>();
|
|
45
|
+
const out = allocateEntity<any>() as any;
|
|
44
46
|
out.set = async () => {
|
|
45
47
|
return { outcome: 'updated' as const };
|
|
46
48
|
};
|
|
47
|
-
return
|
|
49
|
+
return out;
|
|
48
50
|
})(),
|
|
49
51
|
},
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
async function tray() {
|
|
54
|
-
const
|
|
56
|
+
const providers = host();
|
|
57
|
+
const result = await createTrayIcon(providers.tray.lifecycle);
|
|
55
58
|
if (result.outcome !== 'created') throw new Error(result.outcome);
|
|
56
|
-
return result.tray;
|
|
59
|
+
return { icon: result.tray, image: providers.tray.image };
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
function messages(): string {
|
|
@@ -62,10 +65,10 @@ function messages(): string {
|
|
|
62
65
|
|
|
63
66
|
describe('disableTrayGuards', () => {
|
|
64
67
|
it('stops inspecting later animations', async () => {
|
|
65
|
-
enableTrayGuards();
|
|
68
|
+
enableTrayGuards(logState, () => 0);
|
|
66
69
|
disableTrayGuards();
|
|
67
|
-
const icon = await tray();
|
|
68
|
-
const started = await startTrayIconAnimation(icon, ['a'], 0);
|
|
70
|
+
const { icon, image } = await tray();
|
|
71
|
+
const started = await startTrayIconAnimation(image, icon, ['a'], 0);
|
|
69
72
|
if (started.outcome === 'started') await started.release.release();
|
|
70
73
|
await destroyTrayIcon(icon);
|
|
71
74
|
expect(messages()).toBe('');
|
|
@@ -74,9 +77,9 @@ describe('disableTrayGuards', () => {
|
|
|
74
77
|
|
|
75
78
|
describe('enableTrayGuards', () => {
|
|
76
79
|
it('warns without refusing a non-positive interval', async () => {
|
|
77
|
-
enableTrayGuards();
|
|
78
|
-
const icon = await tray();
|
|
79
|
-
const started = await startTrayIconAnimation(icon, ['a'], 0);
|
|
80
|
+
enableTrayGuards(logState, () => 0);
|
|
81
|
+
const { icon, image } = await tray();
|
|
82
|
+
const started = await startTrayIconAnimation(image, icon, ['a'], 0);
|
|
80
83
|
expect(started.outcome).toBe('started');
|
|
81
84
|
expect(messages()).toContain('intervalMs is 0');
|
|
82
85
|
if (started.outcome === 'started') await started.release.release();
|
package/src/tray.test.ts
CHANGED
|
@@ -1,30 +1,7 @@
|
|
|
1
|
-
import { allocateEntity
|
|
1
|
+
import { allocateEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import type { RectangleLike } from '@flighthq/geometry/contract';
|
|
2
3
|
import { createSignal } from '@flighthq/signals/contract';
|
|
3
|
-
import type {
|
|
4
|
-
HasTrayBalloon,
|
|
5
|
-
HasTrayBalloonEvents,
|
|
6
|
-
HasTrayBounds,
|
|
7
|
-
HasTrayDoubleClickPolicy,
|
|
8
|
-
HasTrayDropEvents,
|
|
9
|
-
HasTrayImage,
|
|
10
|
-
HasTrayInteractionEvents,
|
|
11
|
-
HasTrayLifecycle,
|
|
12
|
-
HasTrayMenu,
|
|
13
|
-
HasTrayMenuSelectionEvents,
|
|
14
|
-
HasTrayPopupMenu,
|
|
15
|
-
HasTrayPressedImage,
|
|
16
|
-
HasTrayTemplateImage,
|
|
17
|
-
HasTrayTitle,
|
|
18
|
-
HasTrayTooltip,
|
|
19
|
-
RectangleLike,
|
|
20
|
-
Signal,
|
|
21
|
-
TrayBalloonEvent,
|
|
22
|
-
TrayDropEvent,
|
|
23
|
-
TrayIcon,
|
|
24
|
-
TrayIconForHost,
|
|
25
|
-
TrayInteractionEvent,
|
|
26
|
-
TrayMenuSelectionEvent,
|
|
27
|
-
} from '@flighthq/types/contract';
|
|
4
|
+
import type { Signal } from '@flighthq/signals/contract';
|
|
28
5
|
import { describe, expect, it, vi } from 'vitest';
|
|
29
6
|
|
|
30
7
|
import {
|
|
@@ -56,33 +33,59 @@ import {
|
|
|
56
33
|
setTrayPressedIcon,
|
|
57
34
|
startTrayIconAnimation,
|
|
58
35
|
stopTrayIconAnimation,
|
|
59
|
-
} from './tray';
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
} from './tray.ts';
|
|
37
|
+
import type {
|
|
38
|
+
HostTrayBalloonCapability,
|
|
39
|
+
HostTrayBalloonEventsCapability,
|
|
40
|
+
HostTrayBoundsCapability,
|
|
41
|
+
HostTrayDoubleClickPolicyCapability,
|
|
42
|
+
HostTrayDropEventsCapability,
|
|
43
|
+
HostTrayImageCapability,
|
|
44
|
+
HostTrayInteractionEventsCapability,
|
|
45
|
+
HostTrayLifecycleCapability,
|
|
46
|
+
HostTrayMenuCapability,
|
|
47
|
+
HostTrayMenuSelectionEventsCapability,
|
|
48
|
+
HostTrayPopupMenuCapability,
|
|
49
|
+
HostTrayPressedImageCapability,
|
|
50
|
+
HostTrayTemplateImageCapability,
|
|
51
|
+
HostTrayTitleCapability,
|
|
52
|
+
HostTrayTooltipCapability,
|
|
53
|
+
TrayBalloonEvent,
|
|
54
|
+
TrayDropEvent,
|
|
55
|
+
TrayIcon,
|
|
56
|
+
TrayInteractionEvent,
|
|
57
|
+
TrayMenuSelectionEvent,
|
|
58
|
+
} from './types.ts';
|
|
59
|
+
|
|
60
|
+
type TestHost = { readonly tray: { readonly lifecycle: HostTrayLifecycleCapability } } & {
|
|
61
|
+
readonly tray: { readonly image: HostTrayImageCapability };
|
|
62
|
+
} & { readonly tray: { readonly title: HostTrayTitleCapability } } & {
|
|
63
|
+
readonly tray: { readonly tooltip: HostTrayTooltipCapability };
|
|
64
|
+
} & { readonly tray: { readonly menu: HostTrayMenuCapability } } & {
|
|
65
|
+
readonly tray: { readonly templateImage: HostTrayTemplateImageCapability };
|
|
66
|
+
} & { readonly tray: { readonly bounds: HostTrayBoundsCapability } } & {
|
|
67
|
+
readonly tray: { readonly popupMenu: HostTrayPopupMenuCapability };
|
|
68
|
+
} & { readonly tray: { readonly doubleClickPolicy: HostTrayDoubleClickPolicyCapability } } & {
|
|
69
|
+
readonly tray: { readonly pressedImage: HostTrayPressedImageCapability };
|
|
70
|
+
} & { readonly tray: { readonly balloon: HostTrayBalloonCapability } } & {
|
|
71
|
+
readonly tray: { readonly interactionEvents: HostTrayInteractionEventsCapability };
|
|
72
|
+
} & {
|
|
73
|
+
readonly tray: {
|
|
74
|
+
readonly menuSelectionEvents: HostTrayMenuSelectionEventsCapability;
|
|
75
|
+
};
|
|
76
|
+
} & { readonly tray: { readonly balloonEvents: HostTrayBalloonEventsCapability } } & {
|
|
77
|
+
readonly tray: { readonly dropEvents: HostTrayDropEventsCapability };
|
|
78
|
+
};
|
|
76
79
|
|
|
77
80
|
interface TestState {
|
|
78
|
-
balloonEvents: WeakMap<TrayIcon, Signal<
|
|
81
|
+
balloonEvents: WeakMap<TrayIcon, Signal<Readonly<TrayBalloonEvent>>>;
|
|
79
82
|
destroyFailures: number;
|
|
80
83
|
destroyed: WeakSet<TrayIcon>;
|
|
81
|
-
dropEvents: WeakMap<TrayIcon, Signal<
|
|
84
|
+
dropEvents: WeakMap<TrayIcon, Signal<Readonly<TrayDropEvent>>>;
|
|
82
85
|
images: string[];
|
|
83
|
-
interactionEvents: WeakMap<TrayIcon, Signal<
|
|
86
|
+
interactionEvents: WeakMap<TrayIcon, Signal<Readonly<TrayInteractionEvent>>>;
|
|
84
87
|
live: TrayIcon[];
|
|
85
|
-
menuSelectionEvents: WeakMap<TrayIcon, Signal<
|
|
88
|
+
menuSelectionEvents: WeakMap<TrayIcon, Signal<Readonly<TrayMenuSelectionEvent>>>;
|
|
86
89
|
title: string;
|
|
87
90
|
tooltip: string;
|
|
88
91
|
}
|
|
@@ -101,9 +104,9 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
101
104
|
tooltip: '',
|
|
102
105
|
};
|
|
103
106
|
const signalFor = <Event extends object>(
|
|
104
|
-
map: WeakMap<TrayIcon, Signal<
|
|
107
|
+
map: WeakMap<TrayIcon, Signal<Readonly<Event>>>,
|
|
105
108
|
tray: TrayIcon,
|
|
106
|
-
): Signal<
|
|
109
|
+
): Signal<Readonly<Event>> | null => map.get(tray) ?? null;
|
|
107
110
|
const host = {
|
|
108
111
|
tray: {
|
|
109
112
|
lifecycle: (() => {
|
|
@@ -126,7 +129,7 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
126
129
|
};
|
|
127
130
|
out.isDestroyed = (tray: TrayIcon) => state.destroyed.has(tray);
|
|
128
131
|
out.list = () => state.live.slice();
|
|
129
|
-
return
|
|
132
|
+
return out;
|
|
130
133
|
})(),
|
|
131
134
|
image: (() => {
|
|
132
135
|
const out = allocateEntity<any>();
|
|
@@ -134,7 +137,7 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
134
137
|
state.images.push(icon);
|
|
135
138
|
return { outcome: 'updated' as const };
|
|
136
139
|
};
|
|
137
|
-
return
|
|
140
|
+
return out;
|
|
138
141
|
})(),
|
|
139
142
|
title: (() => {
|
|
140
143
|
const out = allocateEntity<any>();
|
|
@@ -145,7 +148,7 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
145
148
|
state.title = title;
|
|
146
149
|
return { outcome: 'updated' as const };
|
|
147
150
|
};
|
|
148
|
-
return
|
|
151
|
+
return out;
|
|
149
152
|
})(),
|
|
150
153
|
tooltip: (() => {
|
|
151
154
|
const out = allocateEntity<any>();
|
|
@@ -156,49 +159,49 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
156
159
|
state.tooltip = tooltip;
|
|
157
160
|
return { outcome: 'updated' as const };
|
|
158
161
|
};
|
|
159
|
-
return
|
|
162
|
+
return out;
|
|
160
163
|
})(),
|
|
161
164
|
menu: (() => {
|
|
162
165
|
const out = allocateEntity<any>();
|
|
163
166
|
out.set = async () => {
|
|
164
167
|
return { outcome: 'updated' as const };
|
|
165
168
|
};
|
|
166
|
-
return
|
|
169
|
+
return out;
|
|
167
170
|
})(),
|
|
168
171
|
templateImage: (() => {
|
|
169
172
|
const out = allocateEntity<any>();
|
|
170
173
|
out.set = async () => {
|
|
171
174
|
return { outcome: 'updated' as const };
|
|
172
175
|
};
|
|
173
|
-
return
|
|
176
|
+
return out;
|
|
174
177
|
})(),
|
|
175
178
|
bounds: (() => {
|
|
176
179
|
const out = allocateEntity<any>();
|
|
177
180
|
out.get = async () => {
|
|
178
181
|
return { bounds: { height: 2, width: 1, x: 3, y: 4 } satisfies RectangleLike, outcome: 'available' as const };
|
|
179
182
|
};
|
|
180
|
-
return
|
|
183
|
+
return out;
|
|
181
184
|
})(),
|
|
182
185
|
popupMenu: (() => {
|
|
183
186
|
const out = allocateEntity<any>();
|
|
184
187
|
out.popup = async () => {
|
|
185
188
|
return { outcome: 'shown' as const };
|
|
186
189
|
};
|
|
187
|
-
return
|
|
190
|
+
return out;
|
|
188
191
|
})(),
|
|
189
192
|
doubleClickPolicy: (() => {
|
|
190
193
|
const out = allocateEntity<any>();
|
|
191
194
|
out.setIgnore = async () => {
|
|
192
195
|
return { outcome: 'updated' as const };
|
|
193
196
|
};
|
|
194
|
-
return
|
|
197
|
+
return out;
|
|
195
198
|
})(),
|
|
196
199
|
pressedImage: (() => {
|
|
197
200
|
const out = allocateEntity<any>();
|
|
198
201
|
out.set = async () => {
|
|
199
202
|
return { outcome: 'updated' as const };
|
|
200
203
|
};
|
|
201
|
-
return
|
|
204
|
+
return out;
|
|
202
205
|
})(),
|
|
203
206
|
balloon: (() => {
|
|
204
207
|
const out = allocateEntity<any>();
|
|
@@ -208,35 +211,35 @@ function testHost(): { host: TestHost; state: TestState } {
|
|
|
208
211
|
out.remove = async () => {
|
|
209
212
|
return { outcome: 'removed' as const };
|
|
210
213
|
};
|
|
211
|
-
return
|
|
214
|
+
return out;
|
|
212
215
|
})(),
|
|
213
216
|
interactionEvents: (() => {
|
|
214
217
|
const out = allocateEntity<any>();
|
|
215
218
|
out.getSignal = (tray: TrayIcon) => signalFor(state.interactionEvents, tray);
|
|
216
|
-
return
|
|
219
|
+
return out;
|
|
217
220
|
})(),
|
|
218
221
|
menuSelectionEvents: (() => {
|
|
219
222
|
const out = allocateEntity<any>();
|
|
220
223
|
out.getSignal = (tray: TrayIcon) => signalFor(state.menuSelectionEvents, tray);
|
|
221
|
-
return
|
|
224
|
+
return out;
|
|
222
225
|
})(),
|
|
223
226
|
balloonEvents: (() => {
|
|
224
227
|
const out = allocateEntity<any>();
|
|
225
228
|
out.getSignal = (tray: TrayIcon) => signalFor(state.balloonEvents, tray);
|
|
226
|
-
return
|
|
229
|
+
return out;
|
|
227
230
|
})(),
|
|
228
231
|
dropEvents: (() => {
|
|
229
232
|
const out = allocateEntity<any>();
|
|
230
233
|
out.getSignal = (tray: TrayIcon) => signalFor(state.dropEvents, tray);
|
|
231
|
-
return
|
|
234
|
+
return out;
|
|
232
235
|
})(),
|
|
233
236
|
},
|
|
234
237
|
};
|
|
235
238
|
return { host: host as TestHost, state };
|
|
236
239
|
}
|
|
237
240
|
|
|
238
|
-
async function acquire(host: TestHost): Promise<
|
|
239
|
-
const result = await createTrayIcon(host);
|
|
241
|
+
async function acquire(host: TestHost): Promise<TrayIcon> {
|
|
242
|
+
const result = await createTrayIcon(host.tray.lifecycle);
|
|
240
243
|
if (result.outcome !== 'created') throw new Error(result.outcome);
|
|
241
244
|
return result.tray;
|
|
242
245
|
}
|
|
@@ -244,7 +247,7 @@ async function acquire(host: TestHost): Promise<TrayIconForHost<TestHost>> {
|
|
|
244
247
|
describe('createTrayIcon', () => {
|
|
245
248
|
it('publishes only after provider acquisition and exposes no public id', async () => {
|
|
246
249
|
const { host, state } = testHost();
|
|
247
|
-
const pending = createTrayIcon(host);
|
|
250
|
+
const pending = createTrayIcon(host.tray.lifecycle);
|
|
248
251
|
expect(state.live).toHaveLength(1);
|
|
249
252
|
const result = await pending;
|
|
250
253
|
expect(result.outcome).toBe('created');
|
|
@@ -267,14 +270,19 @@ describe('displayTrayBalloon', () => {
|
|
|
267
270
|
it('owns balloon display on the Tray entity', async () => {
|
|
268
271
|
const { host } = testHost();
|
|
269
272
|
const tray = await acquire(host);
|
|
270
|
-
expect((await displayTrayBalloon(tray, { text: 'Done', title: 'Flight' })).outcome).toBe(
|
|
273
|
+
expect((await displayTrayBalloon(host.tray.balloon, tray, { text: 'Done', title: 'Flight' })).outcome).toBe(
|
|
274
|
+
'displayed',
|
|
275
|
+
);
|
|
271
276
|
});
|
|
272
277
|
});
|
|
273
278
|
|
|
274
279
|
describe('getTrayIconBounds', () => {
|
|
275
280
|
it('returns provider bounds', async () => {
|
|
276
281
|
const { host } = testHost();
|
|
277
|
-
expect(await getTrayIconBounds(await acquire(host))).toMatchObject({
|
|
282
|
+
expect(await getTrayIconBounds(host.tray.bounds, await acquire(host))).toMatchObject({
|
|
283
|
+
outcome: 'available',
|
|
284
|
+
bounds: { width: 1 },
|
|
285
|
+
});
|
|
278
286
|
});
|
|
279
287
|
});
|
|
280
288
|
|
|
@@ -283,7 +291,7 @@ describe('getTrayIcons', () => {
|
|
|
283
291
|
const { host } = testHost();
|
|
284
292
|
const first = await acquire(host);
|
|
285
293
|
const second = await acquire(host);
|
|
286
|
-
expect(getTrayIcons(host)).toEqual([first, second]);
|
|
294
|
+
expect(getTrayIcons(host.tray.lifecycle)).toEqual([first, second]);
|
|
287
295
|
});
|
|
288
296
|
});
|
|
289
297
|
|
|
@@ -291,8 +299,8 @@ describe('getTrayIconTitle', () => {
|
|
|
291
299
|
it('reads the title', async () => {
|
|
292
300
|
const { host } = testHost();
|
|
293
301
|
const tray = await acquire(host);
|
|
294
|
-
await setTrayIconTitle(tray, 'Flight');
|
|
295
|
-
expect(await getTrayIconTitle(tray)).toEqual({ outcome: 'available', title: 'Flight' });
|
|
302
|
+
await setTrayIconTitle(host.tray.title, tray, 'Flight');
|
|
303
|
+
expect(await getTrayIconTitle(host.tray.title, tray)).toEqual({ outcome: 'available', title: 'Flight' });
|
|
296
304
|
});
|
|
297
305
|
});
|
|
298
306
|
|
|
@@ -300,8 +308,8 @@ describe('getTrayIconTooltip', () => {
|
|
|
300
308
|
it('reads the tooltip', async () => {
|
|
301
309
|
const { host } = testHost();
|
|
302
310
|
const tray = await acquire(host);
|
|
303
|
-
await setTrayIconTooltip(tray, 'Ready');
|
|
304
|
-
expect(await getTrayIconTooltip(tray)).toEqual({ outcome: 'available', tooltip: 'Ready' });
|
|
311
|
+
await setTrayIconTooltip(host.tray.tooltip, tray, 'Ready');
|
|
312
|
+
expect(await getTrayIconTooltip(host.tray.tooltip, tray)).toEqual({ outcome: 'available', tooltip: 'Ready' });
|
|
305
313
|
});
|
|
306
314
|
});
|
|
307
315
|
|
|
@@ -324,6 +332,11 @@ describe('initializeTrayCreateSuccessResult', () => {
|
|
|
324
332
|
});
|
|
325
333
|
|
|
326
334
|
describe('isTrayDestroyed', () => {
|
|
335
|
+
it('does not treat an unknown tray as destroyed', () => {
|
|
336
|
+
const tray = allocateEntity<TrayIcon>();
|
|
337
|
+
expect(isTrayDestroyed(tray)).toBe(false);
|
|
338
|
+
});
|
|
339
|
+
|
|
327
340
|
it('tracks the pinned lifecycle', async () => {
|
|
328
341
|
const { host } = testHost();
|
|
329
342
|
const tray = await acquire(host);
|
|
@@ -338,7 +351,7 @@ describe('isTrayIconAnimating', () => {
|
|
|
338
351
|
vi.useFakeTimers();
|
|
339
352
|
const { host } = testHost();
|
|
340
353
|
const tray = await acquire(host);
|
|
341
|
-
await startTrayIconAnimation(tray, ['a'], 10);
|
|
354
|
+
await startTrayIconAnimation(host.tray.image, tray, ['a'], 10);
|
|
342
355
|
expect(isTrayIconAnimating(tray)).toBe(true);
|
|
343
356
|
stopTrayIconAnimation(tray);
|
|
344
357
|
expect(isTrayIconAnimating(tray)).toBe(false);
|
|
@@ -351,7 +364,7 @@ describe('onTrayBalloonEvent', () => {
|
|
|
351
364
|
const { host, state } = testHost();
|
|
352
365
|
const tray = await acquire(host);
|
|
353
366
|
const listener = vi.fn();
|
|
354
|
-
expect(onTrayBalloonEvent(tray, listener).outcome).toBe('attached');
|
|
367
|
+
expect(onTrayBalloonEvent(host.tray.balloonEvents, tray, listener).outcome).toBe('attached');
|
|
355
368
|
state.balloonEvents.get(tray)!.emit({ type: 'show' });
|
|
356
369
|
expect(listener).toHaveBeenCalledWith({ type: 'show' });
|
|
357
370
|
});
|
|
@@ -362,18 +375,31 @@ describe('onTrayDrop', () => {
|
|
|
362
375
|
const { host, state } = testHost();
|
|
363
376
|
const tray = await acquire(host);
|
|
364
377
|
const listener = vi.fn();
|
|
365
|
-
expect(onTrayDrop(tray, listener).outcome).toBe('attached');
|
|
378
|
+
expect(onTrayDrop(host.tray.dropEvents, tray, listener).outcome).toBe('attached');
|
|
366
379
|
state.dropEvents.get(tray)!.emit({ files: ['a'], type: 'files' });
|
|
367
380
|
expect(listener).toHaveBeenCalledWith({ files: ['a'], type: 'files' });
|
|
368
381
|
});
|
|
369
382
|
});
|
|
370
383
|
|
|
371
384
|
describe('onTrayInteraction', () => {
|
|
385
|
+
it('stops delivering to a released listener because its slot is disconnected', async () => {
|
|
386
|
+
const { host, state } = testHost();
|
|
387
|
+
const tray = await acquire(host);
|
|
388
|
+
const listener = vi.fn();
|
|
389
|
+
const attached = onTrayMenuSelection(host.tray.menuSelectionEvents, tray, listener);
|
|
390
|
+
expectTypeOf(state.menuSelectionEvents.get(tray)!).toEqualTypeOf<Signal<Readonly<TrayMenuSelectionEvent>>>();
|
|
391
|
+
state.menuSelectionEvents.get(tray)!.emit({ id: 'first' });
|
|
392
|
+
if (attached.outcome === 'attached') await attached.release.release();
|
|
393
|
+
state.menuSelectionEvents.get(tray)!.emit({ id: 'second' });
|
|
394
|
+
expect(listener).toHaveBeenCalledOnce();
|
|
395
|
+
expect(listener).toHaveBeenCalledWith({ id: 'first' });
|
|
396
|
+
});
|
|
397
|
+
|
|
372
398
|
it('releases once and destroy releases a remaining subscription', async () => {
|
|
373
399
|
const { host, state } = testHost();
|
|
374
400
|
const tray = await acquire(host);
|
|
375
401
|
const listener = vi.fn();
|
|
376
|
-
const attached = onTrayInteraction(tray, listener);
|
|
402
|
+
const attached = onTrayInteraction(host.tray.interactionEvents, tray, listener);
|
|
377
403
|
expect(attached.outcome).toBe('attached');
|
|
378
404
|
state.interactionEvents.get(tray)!.emit({
|
|
379
405
|
altKey: false,
|
|
@@ -390,7 +416,7 @@ describe('onTrayInteraction', () => {
|
|
|
390
416
|
expect((await attached.release.release()).outcome).toBe('already-released');
|
|
391
417
|
}
|
|
392
418
|
const destroyReleased = vi.fn();
|
|
393
|
-
onTrayInteraction(tray, destroyReleased);
|
|
419
|
+
onTrayInteraction(host.tray.interactionEvents, tray, destroyReleased);
|
|
394
420
|
await destroyTrayIcon(tray);
|
|
395
421
|
state.interactionEvents.get(tray)!.emit({
|
|
396
422
|
altKey: false,
|
|
@@ -410,7 +436,7 @@ describe('onTrayMenuSelection', () => {
|
|
|
410
436
|
const { host, state } = testHost();
|
|
411
437
|
const tray = await acquire(host);
|
|
412
438
|
const listener = vi.fn();
|
|
413
|
-
expect(onTrayMenuSelection(tray, listener).outcome).toBe('attached');
|
|
439
|
+
expect(onTrayMenuSelection(host.tray.menuSelectionEvents, tray, listener).outcome).toBe('attached');
|
|
414
440
|
state.menuSelectionEvents.get(tray)!.emit({ id: 'open' });
|
|
415
441
|
expect(listener).toHaveBeenCalledWith({ id: 'open' });
|
|
416
442
|
});
|
|
@@ -419,7 +445,9 @@ describe('onTrayMenuSelection', () => {
|
|
|
419
445
|
describe('popupTrayContextMenu', () => {
|
|
420
446
|
it('shows the installed menu', async () => {
|
|
421
447
|
const { host } = testHost();
|
|
422
|
-
expect((await popupTrayContextMenu(await acquire(host), { x: 1, y: 2 })).outcome).toBe(
|
|
448
|
+
expect((await popupTrayContextMenu(host.tray.popupMenu, await acquire(host), { x: 1, y: 2 })).outcome).toBe(
|
|
449
|
+
'shown',
|
|
450
|
+
);
|
|
423
451
|
});
|
|
424
452
|
});
|
|
425
453
|
|
|
@@ -427,8 +455,8 @@ describe('removeTrayBalloon', () => {
|
|
|
427
455
|
it('owns balloon removal on the Tray entity', async () => {
|
|
428
456
|
const { host } = testHost();
|
|
429
457
|
const tray = await acquire(host);
|
|
430
|
-
await displayTrayBalloon(tray, { text: 'Done', title: 'Flight' });
|
|
431
|
-
expect((await removeTrayBalloon(tray)).outcome).toBe('removed');
|
|
458
|
+
await displayTrayBalloon(host.tray.balloon, tray, { text: 'Done', title: 'Flight' });
|
|
459
|
+
expect((await removeTrayBalloon(host.tray.balloon, tray)).outcome).toBe('removed');
|
|
432
460
|
});
|
|
433
461
|
});
|
|
434
462
|
|
|
@@ -439,7 +467,7 @@ describe('setTrayAnimationGuard', () => {
|
|
|
439
467
|
setTrayAnimationGuard(guard);
|
|
440
468
|
const { host } = testHost();
|
|
441
469
|
const tray = await acquire(host);
|
|
442
|
-
const started = await startTrayIconAnimation(tray, ['a'], 12);
|
|
470
|
+
const started = await startTrayIconAnimation(host.tray.image, tray, ['a'], 12);
|
|
443
471
|
expect(guard).toHaveBeenCalledWith(tray, 1, 12);
|
|
444
472
|
if (started.outcome === 'started') await started.release.release();
|
|
445
473
|
setTrayAnimationGuard(null);
|
|
@@ -448,9 +476,9 @@ describe('setTrayAnimationGuard', () => {
|
|
|
448
476
|
});
|
|
449
477
|
|
|
450
478
|
describe('setTrayIcon', () => {
|
|
451
|
-
it('uses the
|
|
479
|
+
it('uses the direct image provider', async () => {
|
|
452
480
|
const { host, state } = testHost();
|
|
453
|
-
expect((await setTrayIcon(await acquire(host), 'icon')).outcome).toBe('updated');
|
|
481
|
+
expect((await setTrayIcon(host.tray.image, await acquire(host), 'icon')).outcome).toBe('updated');
|
|
454
482
|
expect(state.images).toEqual(['icon']);
|
|
455
483
|
});
|
|
456
484
|
});
|
|
@@ -458,16 +486,16 @@ describe('setTrayIcon', () => {
|
|
|
458
486
|
describe('setTrayIconContextMenu', () => {
|
|
459
487
|
it('installs a plain descriptor', async () => {
|
|
460
488
|
const { host } = testHost();
|
|
461
|
-
expect(
|
|
462
|
-
'
|
|
463
|
-
);
|
|
489
|
+
expect(
|
|
490
|
+
(await setTrayIconContextMenu(host.tray.menu, await acquire(host), [{ id: 'quit', label: 'Quit' }])).outcome,
|
|
491
|
+
).toBe('updated');
|
|
464
492
|
});
|
|
465
493
|
});
|
|
466
494
|
|
|
467
495
|
describe('setTrayIconTemplate', () => {
|
|
468
496
|
it('updates template treatment', async () => {
|
|
469
497
|
const { host } = testHost();
|
|
470
|
-
expect((await setTrayIconTemplate(await acquire(host), true)).outcome).toBe('updated');
|
|
498
|
+
expect((await setTrayIconTemplate(host.tray.templateImage, await acquire(host), true)).outcome).toBe('updated');
|
|
471
499
|
});
|
|
472
500
|
});
|
|
473
501
|
|
|
@@ -475,7 +503,7 @@ describe('setTrayIconTitle', () => {
|
|
|
475
503
|
it('updates the title', async () => {
|
|
476
504
|
const { host } = testHost();
|
|
477
505
|
const tray = await acquire(host);
|
|
478
|
-
expect((await setTrayIconTitle(tray, 'Flight')).outcome).toBe('updated');
|
|
506
|
+
expect((await setTrayIconTitle(host.tray.title, tray, 'Flight')).outcome).toBe('updated');
|
|
479
507
|
});
|
|
480
508
|
});
|
|
481
509
|
|
|
@@ -483,29 +511,31 @@ describe('setTrayIconTooltip', () => {
|
|
|
483
511
|
it('updates the tooltip', async () => {
|
|
484
512
|
const { host } = testHost();
|
|
485
513
|
const tray = await acquire(host);
|
|
486
|
-
expect((await setTrayIconTooltip(tray, 'Ready')).outcome).toBe('updated');
|
|
514
|
+
expect((await setTrayIconTooltip(host.tray.tooltip, tray, 'Ready')).outcome).toBe('updated');
|
|
487
515
|
});
|
|
488
516
|
});
|
|
489
517
|
|
|
490
518
|
describe('setTrayIgnoreDoubleClickEvents', () => {
|
|
491
519
|
it('updates the policy', async () => {
|
|
492
520
|
const { host } = testHost();
|
|
493
|
-
expect((await setTrayIgnoreDoubleClickEvents(await acquire(host), true)).outcome).toBe(
|
|
521
|
+
expect((await setTrayIgnoreDoubleClickEvents(host.tray.doubleClickPolicy, await acquire(host), true)).outcome).toBe(
|
|
522
|
+
'updated',
|
|
523
|
+
);
|
|
494
524
|
});
|
|
495
525
|
});
|
|
496
526
|
describe('setTrayPressedIcon', () => {
|
|
497
527
|
it('updates the pressed icon', async () => {
|
|
498
528
|
const { host } = testHost();
|
|
499
|
-
expect((await setTrayPressedIcon(await acquire(host), 'pressed')).outcome).toBe('updated');
|
|
529
|
+
expect((await setTrayPressedIcon(host.tray.pressedImage, await acquire(host), 'pressed')).outcome).toBe('updated');
|
|
500
530
|
});
|
|
501
531
|
});
|
|
502
532
|
|
|
503
533
|
describe('startTrayIconAnimation', () => {
|
|
504
|
-
it('writes through the
|
|
534
|
+
it('writes through the direct image provider', async () => {
|
|
505
535
|
vi.useFakeTimers();
|
|
506
536
|
const { host, state } = testHost();
|
|
507
537
|
const tray = await acquire(host);
|
|
508
|
-
const result = await startTrayIconAnimation(tray, ['a', 'b'], 10);
|
|
538
|
+
const result = await startTrayIconAnimation(host.tray.image, tray, ['a', 'b'], 10);
|
|
509
539
|
expect(result.outcome).toBe('started');
|
|
510
540
|
await vi.advanceTimersByTimeAsync(10);
|
|
511
541
|
expect(state.images).toEqual(['a', 'b']);
|
|
@@ -519,7 +549,7 @@ describe('stopTrayIconAnimation', () => {
|
|
|
519
549
|
vi.useFakeTimers();
|
|
520
550
|
const { host } = testHost();
|
|
521
551
|
const tray = await acquire(host);
|
|
522
|
-
await startTrayIconAnimation(tray, ['a'], 10);
|
|
552
|
+
await startTrayIconAnimation(host.tray.image, tray, ['a'], 10);
|
|
523
553
|
expect(stopTrayIconAnimation(tray).outcome).toBe('stopped');
|
|
524
554
|
expect(stopTrayIconAnimation(tray).outcome).toBe('already-stopped');
|
|
525
555
|
vi.useRealTimers();
|