接入群消息系统通知和本机开关
This commit is contained in:
1 parent
fef421bd4b
commit
5c882ac855
7 files changed
+179
-6
No files matched your search
+31
-1
@@ -1,4 +1,4 @@
|
||||
import { app, BrowserWindow, ipcMain, protocol, safeStorage, session } from 'electron'
|
||||
import { app, BrowserWindow, ipcMain, Notification, protocol, safeStorage, session } from 'electron'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { signChallenge, signMls } from './identity'
|
||||
@@ -6,6 +6,7 @@ import { openBrowser, registerBrowserHandlers, website } from './browser'
|
||||
|
||||
const appURL = 'xhchat://app/'
|
||||
app.enableSandbox()
|
||||
if (process.platform === 'win32' && !app.isPackaged) app.setAppUserModelId(process.execPath)
|
||||
protocol.registerSchemesAsPrivileged([{
|
||||
scheme: 'xhchat', privileges: { standard: true, secure: true, supportFetchAPI: true, corsEnabled: true },
|
||||
}])
|
||||
@@ -76,6 +77,35 @@ 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
|
||||
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 }
|
||||
notification.once('close', release)
|
||||
notification.once('failed', release)
|
||||
notification.once('click', () => {
|
||||
release()
|
||||
if (win.isDestroyed()) return
|
||||
if (win.isMinimized()) win.restore()
|
||||
win.show()
|
||||
win.focus()
|
||||
})
|
||||
notification.show()
|
||||
})
|
||||
ipcMain.handle('notification:group-close', (event) => {
|
||||
if (!trustedSender(event)) return
|
||||
groupNotification?.close()
|
||||
groupNotification = undefined
|
||||
})
|
||||
win.on('closed', () => groupNotification?.close())
|
||||
let microphoneUntil = 0
|
||||
let microphonePage = ''
|
||||
function recordingPage(url: string) {
|
||||
|
||||
Reference in new issue
Block a user