From c02dbed7e0a77300108e69f1f059b4a7aaf63fb9 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 14 Jan 2023 17:20:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=85=B3=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E7=A6=81=E7=94=A8=E5=86=85=E7=BD=AE=E7=9A=84=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/web/plugins/README.md | 1 - .../plugins/com.msgbyte.notify/package.json | 1 + .../plugins/com.msgbyte.notify/src/const.ts | 3 +++ .../plugins/com.msgbyte.notify/src/index.tsx | 11 +++++++-- .../plugins/com.msgbyte.notify/src/notify.ts | 23 ++++++++++++++++++- .../com.msgbyte.notify/src/translate.ts | 4 ++++ .../plugins/com.msgbyte.notify/tsconfig.json | 1 + pnpm-lock.yaml | 2 ++ 8 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 client/web/plugins/com.msgbyte.notify/src/const.ts diff --git a/client/web/plugins/README.md b/client/web/plugins/README.md index 0b89d53a..6488a797 100644 --- a/client/web/plugins/README.md +++ b/client/web/plugins/README.md @@ -16,7 +16,6 @@ pnpm ministar createPlugin ```json { "compilerOptions": { - "rootDir": "./src", "baseUrl": "./src", "esModuleInterop": true, "jsx": "react", diff --git a/client/web/plugins/com.msgbyte.notify/package.json b/client/web/plugins/com.msgbyte.notify/package.json index 895d7086..27daacd6 100644 --- a/client/web/plugins/com.msgbyte.notify/package.json +++ b/client/web/plugins/com.msgbyte.notify/package.json @@ -4,6 +4,7 @@ "version": "0.0.0", "private": true, "dependencies": { + "lodash": "^4.17.21", "tinycon": "^0.6.8" }, "devDependencies": { diff --git a/client/web/plugins/com.msgbyte.notify/src/const.ts b/client/web/plugins/com.msgbyte.notify/src/const.ts new file mode 100644 index 00000000..b42bd357 --- /dev/null +++ b/client/web/plugins/com.msgbyte.notify/src/const.ts @@ -0,0 +1,3 @@ +export const PLUGIN_NAME = 'com.msgbyte.notify'; + +export const PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND = `${PLUGIN_NAME}.disabledSound`; diff --git a/client/web/plugins/com.msgbyte.notify/src/index.tsx b/client/web/plugins/com.msgbyte.notify/src/index.tsx index f0fac147..a80cba44 100644 --- a/client/web/plugins/com.msgbyte.notify/src/index.tsx +++ b/client/web/plugins/com.msgbyte.notify/src/index.tsx @@ -1,6 +1,7 @@ import { regGroupPanelBadge, regPluginGroupTextPanelExtraMenu, + regPluginSettings, sharedEvent, showToasts, } from '@capital/common'; @@ -9,8 +10,7 @@ import React from 'react'; import { appendSilent, hasSilent, removeSilent } from './silent'; import { initNotify } from './notify'; import { Translate } from './translate'; - -const PLUGIN_NAME = 'com.msgbyte.notify'; +import { PLUGIN_NAME, PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND } from './const'; if ('Notification' in window) { initNotify(); @@ -40,3 +40,10 @@ regGroupPanelBadge({ return hasSilent(panelId) ? : null; }, }); + +regPluginSettings({ + name: PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND, + label: Translate.disabledSound, + position: 'system', + type: 'boolean', +}); diff --git a/client/web/plugins/com.msgbyte.notify/src/notify.ts b/client/web/plugins/com.msgbyte.notify/src/notify.ts index 7b852de8..f0541333 100644 --- a/client/web/plugins/com.msgbyte.notify/src/notify.ts +++ b/client/web/plugins/com.msgbyte.notify/src/notify.ts @@ -2,14 +2,17 @@ import { regSocketEventListener, getGlobalState, getCachedUserInfo, - getCachedConverseInfo, getCachedBaseGroupInfo, getServiceWorkerRegistration, navigate, + sharedEvent, + getCachedUserSettings, } from '@capital/common'; import { Translate } from './translate'; import { hasSilent } from './silent'; import { incBubble, setBubble } from './bubble'; +import _get from 'lodash/get'; +import { PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND } from './const'; const TAG = 'tailchat-message'; @@ -123,10 +126,28 @@ function handleMessageNotifyClick(tag, data) { } } +let userSettings = null; +sharedEvent.on('loginSuccess', () => { + getCachedUserSettings().then((settings) => { + if (userSettings === null) { + userSettings = settings; + } + }); +}); + +sharedEvent.on('userSettingsUpdate', (settings) => { + userSettings = settings; +}); + /** * 尝试播放通知声音 */ function tryPlayNotificationSound() { + if (_get(userSettings, PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND) === true) { + // 消息提示音被禁用 + return; + } + try { const audio = new Audio( '/plugins/com.msgbyte.notify/assets/sounds_bing.mp3' diff --git a/client/web/plugins/com.msgbyte.notify/src/translate.ts b/client/web/plugins/com.msgbyte.notify/src/translate.ts index befd0f3c..3ed20be1 100644 --- a/client/web/plugins/com.msgbyte.notify/src/translate.ts +++ b/client/web/plugins/com.msgbyte.notify/src/translate.ts @@ -14,4 +14,8 @@ export const Translate = { 'zh-CN': '私信', 'en-US': 'DM', }), + disabledSound: localTrans({ + 'zh-CN': '禁用消息通知提示音', + 'en-US': 'Disable message notification sound', + }), }; diff --git a/client/web/plugins/com.msgbyte.notify/tsconfig.json b/client/web/plugins/com.msgbyte.notify/tsconfig.json index 6dfff4f0..465a28b5 100644 --- a/client/web/plugins/com.msgbyte.notify/tsconfig.json +++ b/client/web/plugins/com.msgbyte.notify/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "baseUrl": "./src", "esModuleInterop": true, "jsx": "react", "paths": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c105454..3e24eb7b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -646,8 +646,10 @@ importers: client/web/plugins/com.msgbyte.notify: specifiers: '@types/tinycon': ^0.6.3 + lodash: ^4.17.21 tinycon: ^0.6.8 dependencies: + lodash: 4.17.21 tinycon: 0.6.8 devDependencies: '@types/tinycon': 0.6.3