From 741e9f7983748ff9aea7a04c8f31b3622b3f65bf Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 24 Jun 2023 14:34:46 +0800 Subject: [PATCH] fix: fix audio.play() error throw which will marked as Unhandled --- client/web/plugins/com.msgbyte.notify/src/notify.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/web/plugins/com.msgbyte.notify/src/notify.ts b/client/web/plugins/com.msgbyte.notify/src/notify.ts index 998875be..d7febabc 100644 --- a/client/web/plugins/com.msgbyte.notify/src/notify.ts +++ b/client/web/plugins/com.msgbyte.notify/src/notify.ts @@ -89,6 +89,7 @@ export function initNotify() { incBubble(); } + tryPlayNotificationSound(); // 不管当前是不是处于活跃状态,都发出提示音 }); } @@ -132,7 +133,7 @@ sharedEvent.on('userSettingsUpdate', (settings) => { /** * 尝试播放通知声音 */ -function tryPlayNotificationSound() { +async function tryPlayNotificationSound() { if (_get(userSettings, PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND) === true) { // 消息提示音被禁用 return; @@ -142,7 +143,7 @@ function tryPlayNotificationSound() { const audio = new Audio( '/plugins/com.msgbyte.notify/assets/sounds_bing.mp3' ); - audio.play(); + await audio.play(); } catch (err) { console.error(err); }