Skip to content

Commit c5320f0

Browse files
committed
small ts refactors
1 parent 0a01b87 commit c5320f0

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

frontend/assets/app.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ let persistedClientStats: Record<string, ClientStats> | null = null;
5656
// Error Handling
5757
// ==========================
5858

59-
const showJSError = (message: string) => {
59+
const showJSErrorDiv = (doShow = true) => {
6060
const errorDiv = document.getElementById('js-error') as HTMLDivElement;
61+
errorDiv.hidden = !doShow;
62+
}
63+
64+
const showJSError = (message: string) => {
6165
const messageEl = document.getElementById('js-error-message') as HTMLParagraphElement;
62-
if (errorDiv && messageEl) {
66+
if (messageEl) {
6367
messageEl.textContent = message;
64-
errorDiv.hidden = false;
68+
showJSErrorDiv(true);
6569
}
6670
};
6771

@@ -118,6 +122,7 @@ const connectWebSocket = () => {
118122
// `ev` is typically an Event without much detail; still log to help
119123
// spot timing or repeated failures.
120124
console.error('WebSocket error', ev);
125+
showJSError(`A WebSocket error occurred, please check the console for details.`);
121126
};
122127
socket.onclose = (ev) => {
123128
console.warn('WebSocket closed', { code: ev.code, reason: ev.reason, wasClean: ev.wasClean });

frontend/assets/sw.tmpl.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,19 @@ self.addEventListener('notificationclick', (event) => {
7777
event.notification.close();
7878

7979
// Focus existing window or open new one
80-
event.waitUntil(
81-
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList: readonly WindowClient[]) => {
82-
const url = self.location.origin;
83-
84-
for (const client of clientList) {
85-
if (client.url === url && 'focus' in client) {
86-
return client.focus();
87-
}
88-
}
89-
90-
if (self.clients.openWindow) {
91-
return self.clients.openWindow(url);
80+
event.waitUntil((async () => {
81+
const clientList = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
82+
const url = self.location.origin;
83+
84+
for (const client of clientList) {
85+
if (client.url === url && 'focus' in client) {
86+
return client.focus();
9287
}
93-
return Promise.resolve(null);
94-
})
95-
);
88+
}
89+
90+
if (self.clients.openWindow) {
91+
return self.clients.openWindow(url);
92+
}
93+
return null;
94+
})());
9695
});

0 commit comments

Comments
 (0)