diff --git a/Readme.md b/Readme.md index 3d2aa05..55b8526 100644 --- a/Readme.md +++ b/Readme.md @@ -16,6 +16,10 @@ ## 更新日志 +- 2022.04.26 + 1. 版本号改为`年.月.日`格式 + 2. 检测未读消息, 如有, 托盘图标显示红点。 + - 2022.04.24 1. electron升级为18.0 2. 修复自动登录功能 diff --git a/package.json b/package.json index b191cd4..c711570 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dtalk", - "version": "3.8.12", + "version": "22.4.26", "description": "钉钉-Linux版", "main": "src/main.js", "scripts": { diff --git a/src/images/tray_a.png b/src/images/tray_a.png new file mode 100644 index 0000000..2332a0f Binary files /dev/null and b/src/images/tray_a.png differ diff --git a/src/main.js b/src/main.js index 641cf5e..4fa2573 100644 --- a/src/main.js +++ b/src/main.js @@ -29,7 +29,7 @@ app.once('ready', () => { let win = createMainWindow(join(ROOT, './images/app.png')) - createTray(win) + app.toggleTray = createTray(win) }) ipcMain.on('app', (ev, conn) => { @@ -73,5 +73,12 @@ ipcMain.on('app', (ev, conn) => { ev.returnValue = true } break + + case 'toggleTray': + { + app.toggleTray(conn.data) + ev.returnValue = true + } + break } }) diff --git a/src/tools/inject.js b/src/tools/inject.js index acfa642..09e9c81 100644 --- a/src/tools/inject.js +++ b/src/tools/inject.js @@ -24,5 +24,9 @@ contextBridge.exposeInMainWorld('electron', { saveCookie() { return ipcRenderer.sendSync('app', { type: 'saveCookie' }) + }, + + toggleTray(unread) { + return ipcRenderer.sendSync('app', { type: 'toggleTray', data: unread }) } }) diff --git a/src/tools/tray.js b/src/tools/tray.js index ba4e206..e10c8ea 100644 --- a/src/tools/tray.js +++ b/src/tools/tray.js @@ -8,8 +8,11 @@ const { app, Tray, Menu } = require('electron') const path = require('path') 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) { - app.__TRAY__ = new Tray(path.join(ROOT, '../images/tray.png')) + let dTray = new Tray(TRAY_ICO) let menuList = Menu.buildFromTemplate([ { label: '显示主窗口', @@ -25,9 +28,25 @@ module.exports = function (win) { } } ]) - app.__TRAY__.on('click', _ => { + let unreadCache = false + + dTray.on('click', _ => { 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) + } + } } diff --git a/src/tools/windows.js b/src/tools/windows.js index ce3a203..f64c054 100644 --- a/src/tools/windows.js +++ b/src/tools/windows.js @@ -33,7 +33,7 @@ exports.createMainWindow = function (icon) { win.on('ready-to-show', _ => { win.show() - // win.openDevTools() + win.openDevTools() }) win.webContents.on('dom-ready', ev => { @@ -70,6 +70,20 @@ exports.createMainWindow = function (icon) { location.reload() }, 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() }