接入私聊消息通知和联系人免打扰

This commit is contained in:
xhgit committed 2026-11-15 22:27:58 +08:00
1 parent 5c882ac855
commit 7e165ba9b4
23 files changed
+286 -97

No files matched your search

+17 -15
View File
@@ -77,18 +77,20 @@ async function start() {
return !win.isDestroyed() && event.sender === win.webContents && frame && frame === win.webContents.mainFrame &&
frame.url.split('#')[0] === appURL
}
let groupNotification: Notification | undefined
let lastGroupNotification = 0
ipcMain.handle('notification:group-supported', (event) => trustedSender(event) && Notification.isSupported())
ipcMain.handle('notification:group-show', (event) => {
if (!trustedSender(event) || !Notification.isSupported() || (win.isFocused() && !win.isMinimized())) return
let messageNotification: Notification | undefined
let lastMessageNotification = 0
ipcMain.handle('notification:message-supported', (event) => trustedSender(event) && Notification.isSupported())
ipcMain.handle('notification:message-show', (event, kind: unknown) => {
if (!trustedSender(event) || (kind !== 'group' && kind !== 'private') || !Notification.isSupported() ||
(win.isFocused() && !win.isMinimized())) return
const now = Date.now()
if (now - lastGroupNotification < 2500) return
lastGroupNotification = now
groupNotification?.close()
const notification = new Notification({ title: 'XHChat', body: '有新的群消息', icon: join(renderer, 'brand/xhchat.png') })
groupNotification = notification
const release = () => { if (groupNotification === notification) groupNotification = undefined }
if (now - lastMessageNotification < 2500) return
lastMessageNotification = now
messageNotification?.close()
const body = kind === 'group' ? '有新的群消息' : '有新的私聊消息'
const notification = new Notification({ title: 'XHChat', body, icon: join(renderer, 'brand/xhchat.png') })
messageNotification = notification
const release = () => { if (messageNotification === notification) messageNotification = undefined }
notification.once('close', release)
notification.once('failed', release)
notification.once('click', () => {
@@ -100,12 +102,12 @@ async function start() {
})
notification.show()
})
ipcMain.handle('notification:group-close', (event) => {
ipcMain.handle('notification:message-close', (event) => {
if (!trustedSender(event)) return
groupNotification?.close()
groupNotification = undefined
messageNotification?.close()
messageNotification = undefined
})
win.on('closed', () => groupNotification?.close())
win.on('closed', () => messageNotification?.close())
let microphoneUntil = 0
let microphonePage = ''
function recordingPage(url: string) {
+3 -3
View File
@@ -6,9 +6,9 @@ contextBridge.exposeInMainWorld('xhchat', {
apiBase: apiArgument?.slice('--xhchat-api='.length),
signChallenge: (username: string, challenge: string) => ipcRenderer.invoke('device:sign', username, challenge),
openBrowser: (url?: string) => ipcRenderer.invoke('browser:open', url),
groupNotificationsSupported: () => ipcRenderer.invoke('notification:group-supported'),
showGroupNotification: () => ipcRenderer.invoke('notification:group-show'),
closeGroupNotification: () => ipcRenderer.invoke('notification:group-close'),
messageNotificationsSupported: () => ipcRenderer.invoke('notification:message-supported'),
showMessageNotification: (kind: 'group' | 'private') => ipcRenderer.invoke('notification:message-show', kind),
closeMessageNotification: () => ipcRenderer.invoke('notification:message-close'),
allowVoiceRecording: () => ipcRenderer.invoke('voice:allow'),
endVoiceRecording: () => ipcRenderer.invoke('voice:end'),
signMls: (username: string, kind: string, user: string, device: string, value: Uint8Array) =>