This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
appcat
/
dtalk-app
Archived
1
0
Fork 0

增加未读消息检测

master
yutent 2022-04-26 14:14:13 +08:00
parent 50e150199e
commit ff8b6588d2
7 changed files with 54 additions and 6 deletions

View File

@ -16,6 +16,10 @@
## 更新日志 ## 更新日志
- 2022.04.26
1. 版本号改为`年.月.日`格式
2. 检测未读消息, 如有, 托盘图标显示红点。
- 2022.04.24 - 2022.04.24
1. electron升级为18.0 1. electron升级为18.0
2. 修复自动登录功能 2. 修复自动登录功能

View File

@ -1,6 +1,6 @@
{ {
"name": "dtalk", "name": "dtalk",
"version": "3.8.12", "version": "22.4.26",
"description": "钉钉-Linux版", "description": "钉钉-Linux版",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

BIN
src/images/tray_a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -29,7 +29,7 @@ app.once('ready', () => {
let win = createMainWindow(join(ROOT, './images/app.png')) let win = createMainWindow(join(ROOT, './images/app.png'))
createTray(win) app.toggleTray = createTray(win)
}) })
ipcMain.on('app', (ev, conn) => { ipcMain.on('app', (ev, conn) => {
@ -73,5 +73,12 @@ ipcMain.on('app', (ev, conn) => {
ev.returnValue = true ev.returnValue = true
} }
break break
case 'toggleTray':
{
app.toggleTray(conn.data)
ev.returnValue = true
}
break
} }
}) })

View File

@ -24,5 +24,9 @@ contextBridge.exposeInMainWorld('electron', {
saveCookie() { saveCookie() {
return ipcRenderer.sendSync('app', { type: 'saveCookie' }) return ipcRenderer.sendSync('app', { type: 'saveCookie' })
},
toggleTray(unread) {
return ipcRenderer.sendSync('app', { type: 'toggleTray', data: unread })
} }
}) })

View File

@ -8,8 +8,11 @@ const { app, Tray, Menu } = require('electron')
const path = require('path') const path = require('path')
const ROOT = __dirname const ROOT = __dirname
const TRAY_ICO = path.join(ROOT, '../images/tray.png')
const TRAY_ICO_A = path.join(ROOT, '../images/tray_a.png')
module.exports = function (win) { module.exports = function (win) {
app.__TRAY__ = new Tray(path.join(ROOT, '../images/tray.png')) let dTray = new Tray(TRAY_ICO)
let menuList = Menu.buildFromTemplate([ let menuList = Menu.buildFromTemplate([
{ {
label: '显示主窗口', label: '显示主窗口',
@ -25,9 +28,25 @@ module.exports = function (win) {
} }
} }
]) ])
app.__TRAY__.on('click', _ => { let unreadCache = false
dTray.on('click', _ => {
win.show() win.show()
}) })
app.__TRAY__.setContextMenu(menuList) dTray.setContextMenu(menuList)
return function (unread) {
// 缓存状态, 避免频繁修改tray图标
if (unreadCache === unread) {
return
}
unreadCache = unread
if (unread) {
dTray.setImage(TRAY_ICO_A)
} else {
dTray.setImage(TRAY_ICO)
}
}
} }

View File

@ -33,7 +33,7 @@ exports.createMainWindow = function (icon) {
win.on('ready-to-show', _ => { win.on('ready-to-show', _ => {
win.show() win.show()
// win.openDevTools() win.openDevTools()
}) })
win.webContents.on('dom-ready', ev => { win.webContents.on('dom-ready', ev => {
@ -70,6 +70,20 @@ exports.createMainWindow = function (icon) {
location.reload() location.reload()
}, 2000) }, 2000)
} }
function checkUnReadMsg() {
window.__timer = setTimeout(function() {
var $box = document.body.querySelector('.conv-lists-box')
var $unread = $box.querySelectorAll('.unread-num')
electro($unread.length > 0)
clearTimeout(window.__timer)
checkUnReadMsg()
}, 1500)
}
checkUnReadMsg()
} }