no message

This commit is contained in:
kuaifan 2021-07-09 18:15:39 +08:00
parent 276654a7e3
commit 4c71366b77
5 changed files with 42 additions and 51 deletions

45
electron/main.js vendored
View File

@ -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("")
}
});

View File

@ -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",

View File

@ -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')
}

View File

@ -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;
}
}

View File

@ -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) {