feat: 消息通知插件增加开关允许禁用内置的提示音

pull/64/head
moonrailgun 2 years ago
parent e9b96a15a2
commit c02dbed7e0

@ -16,7 +16,6 @@ pnpm ministar createPlugin
```json ```json
{ {
"compilerOptions": { "compilerOptions": {
"rootDir": "./src",
"baseUrl": "./src", "baseUrl": "./src",
"esModuleInterop": true, "esModuleInterop": true,
"jsx": "react", "jsx": "react",

@ -4,6 +4,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"lodash": "^4.17.21",
"tinycon": "^0.6.8" "tinycon": "^0.6.8"
}, },
"devDependencies": { "devDependencies": {

@ -0,0 +1,3 @@
export const PLUGIN_NAME = 'com.msgbyte.notify';
export const PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND = `${PLUGIN_NAME}.disabledSound`;

@ -1,6 +1,7 @@
import { import {
regGroupPanelBadge, regGroupPanelBadge,
regPluginGroupTextPanelExtraMenu, regPluginGroupTextPanelExtraMenu,
regPluginSettings,
sharedEvent, sharedEvent,
showToasts, showToasts,
} from '@capital/common'; } from '@capital/common';
@ -9,8 +10,7 @@ import React from 'react';
import { appendSilent, hasSilent, removeSilent } from './silent'; import { appendSilent, hasSilent, removeSilent } from './silent';
import { initNotify } from './notify'; import { initNotify } from './notify';
import { Translate } from './translate'; import { Translate } from './translate';
import { PLUGIN_NAME, PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND } from './const';
const PLUGIN_NAME = 'com.msgbyte.notify';
if ('Notification' in window) { if ('Notification' in window) {
initNotify(); initNotify();
@ -40,3 +40,10 @@ regGroupPanelBadge({
return hasSilent(panelId) ? <Icon icon="mdi:bell-off-outline" /> : null; return hasSilent(panelId) ? <Icon icon="mdi:bell-off-outline" /> : null;
}, },
}); });
regPluginSettings({
name: PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND,
label: Translate.disabledSound,
position: 'system',
type: 'boolean',
});

@ -2,14 +2,17 @@ import {
regSocketEventListener, regSocketEventListener,
getGlobalState, getGlobalState,
getCachedUserInfo, getCachedUserInfo,
getCachedConverseInfo,
getCachedBaseGroupInfo, getCachedBaseGroupInfo,
getServiceWorkerRegistration, getServiceWorkerRegistration,
navigate, navigate,
sharedEvent,
getCachedUserSettings,
} from '@capital/common'; } from '@capital/common';
import { Translate } from './translate'; import { Translate } from './translate';
import { hasSilent } from './silent'; import { hasSilent } from './silent';
import { incBubble, setBubble } from './bubble'; import { incBubble, setBubble } from './bubble';
import _get from 'lodash/get';
import { PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND } from './const';
const TAG = 'tailchat-message'; 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() { function tryPlayNotificationSound() {
if (_get(userSettings, PLUGIN_SYSTEM_SETTINGS_DISABLED_SOUND) === true) {
// 消息提示音被禁用
return;
}
try { try {
const audio = new Audio( const audio = new Audio(
'/plugins/com.msgbyte.notify/assets/sounds_bing.mp3' '/plugins/com.msgbyte.notify/assets/sounds_bing.mp3'

@ -14,4 +14,8 @@ export const Translate = {
'zh-CN': '私信', 'zh-CN': '私信',
'en-US': 'DM', 'en-US': 'DM',
}), }),
disabledSound: localTrans({
'zh-CN': '禁用消息通知提示音',
'en-US': 'Disable message notification sound',
}),
}; };

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": "./src",
"esModuleInterop": true, "esModuleInterop": true,
"jsx": "react", "jsx": "react",
"paths": { "paths": {

@ -646,8 +646,10 @@ importers:
client/web/plugins/com.msgbyte.notify: client/web/plugins/com.msgbyte.notify:
specifiers: specifiers:
'@types/tinycon': ^0.6.3 '@types/tinycon': ^0.6.3
lodash: ^4.17.21
tinycon: ^0.6.8 tinycon: ^0.6.8
dependencies: dependencies:
lodash: 4.17.21
tinycon: 0.6.8 tinycon: 0.6.8
devDependencies: devDependencies:
'@types/tinycon': 0.6.3 '@types/tinycon': 0.6.3

Loading…
Cancel
Save