From ff8b6588d2f43104af76fba5f5dbc6808876c27e Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 26 Apr 2022 14:14:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=AA=E8=AF=BB=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Readme.md | 4 ++++ package.json | 2 +- src/images/tray_a.png | Bin 0 -> 3661 bytes src/main.js | 9 ++++++++- src/tools/inject.js | 4 ++++ src/tools/tray.js | 25 ++++++++++++++++++++++--- src/tools/windows.js | 16 +++++++++++++++- 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/images/tray_a.png 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 0000000000000000000000000000000000000000..2332a0f842110051f7dbc564322be7753a95d2a5 GIT binary patch literal 3661 zcmV-T4zlryP)Px@2T4RhRCr$PTMKYh)fxWIy}QY72zfwW1QU6QO*EtsqF6wyh;JPgJ9IiwupJ#c zqF}A9TCMF=O9whqrqv=9h57(Hidd(Lf{G{lE;mjoaxaZt^&iB8*|37DmD2gIbyxf>2;#T??k`o zM!OI2h6E5o=h#wG&X!SG z#}A%5D4lA{(pJT9mbhtsx^bb0GDdXqdJyzC9ySk1n>rJB?;OMz?VKW55d;Jx$iS#L-BJB7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SIiw419X@@Q%yT{A6GFBL*SXp%)=b>n3X z5fS7G7EL91vYZ7~-@PpYR_qld&5&yb(X~C)n~Z^;n}M#l?UyT3& zoJg>(Ya(`cXIT^mW6vt$)R;k$)xx_h+cYPz`U)0TO(giiP7X)T%JE-cf!3cii#&lR zO3BuS@3WYd9qIIjd`^%Om6e~1@N~pDsBCo>&@NmmtcE5w7iADUcO`=@wF0))i4vKS znlS@1)&bOK1EB8iM>(xnklq>9<`a$rdc^AcfO~fP(G|3*_gRGji)cxqy(*vJrb2>e zDg+FuMOlk6>Lt}QuS`FSWjRe@|6+Hz+xCEj`39T!*5QTD3o*#+8Jqr)U}TlXHhoiw z6;<^)c?5kyNV!2cX)@ctAxG2pD=*6>SejZ5H<5RKqj~*dX#kyPWn~4bed&0;^8%dV zWKA${md3IMy(JiGDoWjj?n0zG6(a=K6%ec{1zJt{zO4q>@qk#r z5jxrfJmV2@_^e@r%;?nBPrCV99vfB^NpgBIn6;TG({OrAW;+(9cOZq~ZGRwXD!k(mkOG8Ea5Q2fhcGo18f$rG@1`-Ph(pz)Mu8Y2BFoL-=cPbq$MAmT78eoH zPcs(6wf;1`+mny>Pzt<~_f{4YJGs+t8!fwx;rX*&BIZnB@L&m~O7d`j#+PsuuzDcn z@h^PVfJ$!$j`_!e{!U2pThY=46S1Rl-cW`&sSzz}e=ip(@E*m~#$yt+ z4=rL&FPVjY4yf%0YR&-FEq!PYy5SR8ge2Z3SFy%8fGigo00000NkvXXu0mjfd`r** literal 0 HcmV?d00001 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() }