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

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

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

@ -4,6 +4,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"lodash": "^4.17.21",
"tinycon": "^0.6.8"
},
"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 {
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) ? <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,
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'

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

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

@ -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

Loading…
Cancel
Save