From 4c71366b7724e7ab5cac7f7dcdcbd3a05be986dc Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 9 Jul 2021 18:15:39 +0800 Subject: [PATCH] no message --- electron/main.js | 45 ++++++++++++-------- electron/package.json | 2 +- resources/assets/js/app.js | 2 + resources/assets/js/components/PageTitle.vue | 17 +------- resources/assets/js/pages/manage.vue | 27 +++++------- 5 files changed, 42 insertions(+), 51 deletions(-) diff --git a/electron/main.js b/electron/main.js index 52045ca6a..f86480fdb 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const {app, BrowserWindow} = require('electron') +const {app, BrowserWindow, ipcMain} = require('electron') let willQuitApp = false, devloadCachePath = path.resolve(__dirname, ".devload"), @@ -9,13 +9,25 @@ if (fs.existsSync(devloadCachePath)) { devloadUrl = fs.readFileSync(devloadCachePath, 'utf8') } -function getCounterValue(title) { - const itemCountRegex = /[([{]([\d.,]*)\+?[}\])]/; - const match = itemCountRegex.exec(title); - return match ? match[1] : undefined; +function runNum(str, fixed) { + let _s = Number(str); + if (_s + "" === "NaN") { + _s = 0; + } + if (/^[0-9]*[1-9][0-9]*$/.test(fixed)) { + _s = _s.toFixed(fixed); + let rs = _s.indexOf('.'); + if (rs < 0) { + _s += "."; + for (let i = 0; i < fixed; i++) { + _s += "0"; + } + } + } + return _s; } -function createWindow(setDockBadge) { +function createWindow() { const mainWindow = new BrowserWindow({ width: 1280, height: 800, @@ -36,15 +48,6 @@ function createWindow(setDockBadge) { }) } - mainWindow.on('page-title-updated', function (event, title) { - const counterValue = getCounterValue(title); - if (counterValue) { - setDockBadge(counterValue); - } else { - setDockBadge(''); - } - }) - mainWindow.on('close', function (e) { if (!willQuitApp) { e.preventDefault(); @@ -54,10 +57,10 @@ function createWindow(setDockBadge) { } app.whenReady().then(() => { - createWindow(app.dock.setBadge) + createWindow() app.on('activate', function () { - if (BrowserWindow.getAllWindows().length === 0) createWindow(app.dock.setBadge) + if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) @@ -68,3 +71,11 @@ app.on('window-all-closed', function () { app.on('before-quit', () => { willQuitApp = true }); + +ipcMain.on('setDockBadge', (event, arg) => { + if (runNum(arg) > 0) { + app.dock.setBadge(String(arg)) + } else { + app.dock.setBadge("") + } +}); diff --git a/electron/package.json b/electron/package.json index ab39691bd..b64d9eef9 100644 --- a/electron/package.json +++ b/electron/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "start": "electron-forge start", - "start-quiet": "electron-forge start &> /dev/null", + "start-quiet": "sleep 3 && electron-forge start &> /dev/null", "build": "electron-builder", "build-mac-intel": "electron-builder --mac", "build-mac-m1": "electron-builder --mac --arm64", diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index d87c042ce..0caa3ae57 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -46,7 +46,9 @@ Vue.component('EDropdown', Dropdown); Vue.component('EDropdownMenu', DropdownMenu); Vue.component('EDropdownItem', DropdownItem); +Vue.prototype.isElectron = false; if (!!__IS_ELECTRON) { + Vue.prototype.isElectron = true; Vue.prototype.$electron = require('electron') } diff --git a/resources/assets/js/components/PageTitle.vue b/resources/assets/js/components/PageTitle.vue index c7cccf92c..378b2b5aa 100755 --- a/resources/assets/js/components/PageTitle.vue +++ b/resources/assets/js/components/PageTitle.vue @@ -26,19 +26,7 @@ export default { computed: { - ...mapState([ - 'userId', - 'dialogs', - ]), - - - msgAllUnread() { - let num = 0; - this.dialogs.map(({unread}) => { - num += unread; - }) - return num; - }, + ...mapState(['userId']), }, watch: { @@ -68,9 +56,6 @@ export default { }, setPageTile(title) { - if (this.userId && this.msgAllUnread > 0) { - title+= " (" + this.msgAllUnread + ")" - } document.title = title; } } diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index 7dd01f26a..77af10e7e 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -187,8 +187,6 @@ export default { allProjectShow: false, archivedProjectShow: false, - titleInterval: null, - natificationHidden: false, natificationReady: false, notificationClass: null, @@ -199,14 +197,16 @@ export default { this.$store.dispatch("getUserInfo"); this.$store.dispatch("getTaskPriority"); // - this.startCountTitle(); this.notificationInit(); this.onVisibilityChange(); + // + if (this.isElectron) { + this.$electron.ipcRenderer.send('setDockBadge', 0); + } }, deactivated() { this.addShow = false; - clearInterval(this.titleInterval); }, computed: { @@ -280,6 +280,12 @@ export default { id > 0 && this.$Modal.resetIndex(); }, + msgAllUnread(val) { + if (this.isElectron) { + this.$electron.ipcRenderer.send('setDockBadge', val); + } + }, + dialogMsgPush(data) { if (this.natificationHidden && this.natificationReady) { const {id, dialog_id, type, msg} = data; @@ -444,19 +450,6 @@ export default { } }, - startCountTitle() { - this.titleInterval = setInterval(() => { - let {title} = document; - let newTitle = title.replace(/^(.*?)\((\d+)\)$/g, "$1") - if (this.userId && this.msgAllUnread > 0) { - newTitle+= " (" + this.msgAllUnread + ")" - } - if (title != newTitle) { - document.title = newTitle; - } - }, 1000) - }, - notificationInit() { this.notificationClass = new notificationKoro(this.$L("打开通知成功")); if (this.notificationClass.support) {