Skip to content

Commit 9fede7e

Browse files
Use ms-winsoundevent:Notification.IM on Windows
1 parent 1d4290d commit 9fede7e

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

app/renderWindowsToast.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const Text = (props: { id: string; children: React.ReactNode }) =>
3333
React.createElement('text', props);
3434
const Image = (props: { id: string; src: string; 'hint-crop': string }) =>
3535
React.createElement('image', props);
36+
const Audio = (props: { src: string }) => React.createElement('audio', props);
3637

3738
export function renderWindowsToast({
3839
avatarPath,
@@ -51,13 +52,16 @@ export function renderWindowsToast({
5152
const template = avatarPath ? 'ToastImageAndText02' : 'ToastText02';
5253
let launch: URL;
5354

55+
let audio: React.ReactNode | undefined;
56+
5457
// Note:
5558
// 1) this maps to the notify() function in services/notifications.ts
5659
// 2) this also maps to the url-handling in main.ts
5760
if (type === NotificationType.Message || type === NotificationType.Reaction) {
5861
launch = showConversationRoute.toAppUrl({
5962
token,
6063
});
64+
audio = <Audio src="ms-winsoundevent:Notification.IM" />;
6165
} else if (type === NotificationType.IncomingGroupCall) {
6266
launch = startCallLobbyRoute.toAppUrl({
6367
token,
@@ -79,6 +83,7 @@ export function renderWindowsToast({
7983
<Text id="2">{body}</Text>
8084
</Binding>
8185
</Visual>
86+
{audio}
8287
</Toast>
8388
);
8489
}

ts/test-node/app/renderWindowsToast_test.tsx

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ describe('renderWindowsToast', () => {
1616
type: NotificationType.Message,
1717
});
1818

19-
const expected =
20-
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol"><visual><binding template="ToastImageAndText02"><image id="1" src="file:///C:/temp/ab/abcd" hint-crop="circle"></image><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
19+
const expected = [
20+
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol">',
21+
'<visual>',
22+
'<binding template="ToastImageAndText02">',
23+
'<image id="1" src="file:///C:/temp/ab/abcd" hint-crop="circle"></image>',
24+
'<text id="1">Alice</text>',
25+
'<text id="2">Hi there!</text>',
26+
'</binding>',
27+
'</visual>',
28+
'<audio src="ms-winsoundevent:Notification.IM"></audio>',
29+
'</toast>',
30+
].join('');
2131

2232
assert.strictEqual(xml, expected);
2333
});
@@ -30,8 +40,17 @@ describe('renderWindowsToast', () => {
3040
type: NotificationType.Message,
3141
});
3242

33-
const expected =
34-
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol"><visual><binding template="ToastText02"><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
43+
const expected = [
44+
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol">',
45+
'<visual>',
46+
'<binding template="ToastText02">',
47+
'<text id="1">Alice</text>',
48+
'<text id="2">Hi there!</text>',
49+
'</binding>',
50+
'</visual>',
51+
'<audio src="ms-winsoundevent:Notification.IM"></audio>',
52+
'</toast>',
53+
].join('');
3554

3655
assert.strictEqual(xml, expected);
3756
});
@@ -44,8 +63,17 @@ describe('renderWindowsToast', () => {
4463
type: NotificationType.Message,
4564
});
4665

47-
const expected =
48-
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol"><visual><binding template="ToastText02"><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
66+
const expected = [
67+
'<toast launch="sgnl://show-conversation?token=token" activationType="protocol">',
68+
'<visual>',
69+
'<binding template="ToastText02">',
70+
'<text id="1">Alice</text>',
71+
'<text id="2">Hi there!</text>',
72+
'</binding>',
73+
'</visual>',
74+
'<audio src="ms-winsoundevent:Notification.IM"></audio>',
75+
'</toast>',
76+
].join('');
4977

5078
assert.strictEqual(xml, expected);
5179
});
@@ -58,8 +86,16 @@ describe('renderWindowsToast', () => {
5886
type: NotificationType.IncomingCall,
5987
});
6088

61-
const expected =
62-
'<toast launch="sgnl://show-window" activationType="protocol"><visual><binding template="ToastText02"><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
89+
const expected = [
90+
'<toast launch="sgnl://show-window" activationType="protocol">',
91+
'<visual>',
92+
'<binding template="ToastText02">',
93+
'<text id="1">Alice</text>',
94+
'<text id="2">Hi there!</text>',
95+
'</binding>',
96+
'</visual>',
97+
'</toast>',
98+
].join('');
6399

64100
assert.strictEqual(xml, expected);
65101
});
@@ -72,8 +108,16 @@ describe('renderWindowsToast', () => {
72108
type: NotificationType.IncomingGroupCall,
73109
});
74110

75-
const expected =
76-
'<toast launch="sgnl://start-call-lobby?token=token" activationType="protocol"><visual><binding template="ToastText02"><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
111+
const expected = [
112+
'<toast launch="sgnl://start-call-lobby?token=token" activationType="protocol">',
113+
'<visual>',
114+
'<binding template="ToastText02">',
115+
'<text id="1">Alice</text>',
116+
'<text id="2">Hi there!</text>',
117+
'</binding>',
118+
'</visual>',
119+
'</toast>',
120+
].join('');
77121

78122
assert.strictEqual(xml, expected);
79123
});
@@ -86,8 +130,16 @@ describe('renderWindowsToast', () => {
86130
type: NotificationType.IsPresenting,
87131
});
88132

89-
const expected =
90-
'<toast launch="sgnl://cancel-presenting" activationType="protocol"><visual><binding template="ToastText02"><text id="1">Alice</text><text id="2">Hi there!</text></binding></visual></toast>';
133+
const expected = [
134+
'<toast launch="sgnl://cancel-presenting" activationType="protocol">',
135+
'<visual>',
136+
'<binding template="ToastText02">',
137+
'<text id="1">Alice</text>',
138+
'<text id="2">Hi there!</text>',
139+
'</binding>',
140+
'</visual>',
141+
'</toast>',
142+
].join('');
91143

92144
assert.strictEqual(xml, expected);
93145
});

0 commit comments

Comments
 (0)