mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
perf: 优化客户端通知,Mac支持快速回复
This commit is contained in:
parent
4b90086e5a
commit
36bfaf3b94
22
electron/electron.js
vendored
22
electron/electron.js
vendored
@ -1,7 +1,7 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const {app, BrowserWindow, ipcMain, dialog, clipboard, nativeImage, shell, Tray, Menu, globalShortcut} = require('electron')
|
const {app, BrowserWindow, ipcMain, dialog, clipboard, nativeImage, shell, Tray, Menu, globalShortcut, Notification} = require('electron')
|
||||||
const {autoUpdater} = require("electron-updater")
|
const {autoUpdater} = require("electron-updater")
|
||||||
const log = require("electron-log");
|
const log = require("electron-log");
|
||||||
const fsProm = require('fs/promises');
|
const fsProm = require('fs/promises');
|
||||||
@ -503,6 +503,21 @@ ipcMain.on('closeScreenshot', (event) => {
|
|||||||
event.returnValue = "ok"
|
event.returnValue = "ok"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知
|
||||||
|
*/
|
||||||
|
ipcMain.on('openNotification', (event, args) => {
|
||||||
|
const notifiy = new Notification(args);
|
||||||
|
notifiy.addListener('click', _ => {
|
||||||
|
mainWindow.webContents.send("clickNotification", args)
|
||||||
|
})
|
||||||
|
notifiy.addListener('reply', (event, reply) => {
|
||||||
|
mainWindow.webContents.send("replyNotification", Object.assign(args, {reply}))
|
||||||
|
})
|
||||||
|
notifiy.show()
|
||||||
|
event.returnValue = "ok"
|
||||||
|
})
|
||||||
|
|
||||||
//================================================================
|
//================================================================
|
||||||
// Update
|
// Update
|
||||||
//================================================================
|
//================================================================
|
||||||
@ -557,7 +572,10 @@ ipcMain.on('mainWindowTop', (event) => {
|
|||||||
/**
|
/**
|
||||||
* 将主窗口激活
|
* 将主窗口激活
|
||||||
*/
|
*/
|
||||||
ipcMain.on('mainWindowFocus', (event) => {
|
ipcMain.on('mainWindowActive', (event) => {
|
||||||
|
if (!mainWindow.isVisible()) {
|
||||||
|
mainWindow.show()
|
||||||
|
}
|
||||||
mainWindow.focus()
|
mainWindow.focus()
|
||||||
event.returnValue = "ok"
|
event.returnValue = "ok"
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1018,6 +1018,16 @@ export default {
|
|||||||
this.$store.dispatch('openDialog', dialog_id)
|
this.$store.dispatch('openDialog', dialog_id)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else if (this.$Electron) {
|
||||||
|
this.$Electron.sendMessage('openNotification', {
|
||||||
|
icon: $A.originUrl('images/logo.png'),
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
data,
|
||||||
|
tag: "dialog",
|
||||||
|
hasReply: true,
|
||||||
|
replyPlaceholder: this.$L('回复消息')
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.notificationManage.replaceOptions({
|
this.notificationManage.replaceOptions({
|
||||||
icon: $A.originUrl('images/logo.png'),
|
icon: $A.originUrl('images/logo.png'),
|
||||||
@ -1124,38 +1134,39 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化通知
|
||||||
|
*/
|
||||||
notificationInit() {
|
notificationInit() {
|
||||||
this.notificationManage = new notificationKoro(this.$L("打开通知成功"));
|
this.notificationManage = new notificationKoro(this.$L("打开通知成功"));
|
||||||
if (this.notificationManage.support) {
|
if (this.notificationManage.support) {
|
||||||
this.notificationManage.notificationEvent({
|
this.notificationManage.notificationEvent({
|
||||||
onclick: ({target}) => {
|
onclick: ({target}) => {
|
||||||
console.log("[Notification] Click", target);
|
console.log("[Notification] A Click", target);
|
||||||
this.notificationManage.close();
|
this.notificationManage.close();
|
||||||
try {
|
this.notificationClick(target)
|
||||||
window.focus()
|
window.focus()
|
||||||
if (this.$Electron) {
|
|
||||||
this.$Electron.sendMessage('mainWindowFocus')
|
|
||||||
}
|
|
||||||
}catch (e) {}
|
|
||||||
//
|
|
||||||
const {tag, data} = target;
|
|
||||||
if (tag == 'dialog') {
|
|
||||||
if (!$A.isJson(data)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.goForward({name: 'manage-messenger'});
|
|
||||||
this.$store.dispatch('openDialog', data.dialog_id)
|
|
||||||
//
|
|
||||||
if (this.$Electron) {
|
|
||||||
this.$Electron.sendMessage('mainWindowTop')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.notificationPermission();
|
this.notificationPermission();
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
if (this.$Electron) {
|
||||||
|
this.$Electron.registerMsgListener('clickNotification', target => {
|
||||||
|
console.log("[Notification] B Click", target);
|
||||||
|
this.$Electron.sendMessage('mainWindowActive')
|
||||||
|
this.notificationClick(target)
|
||||||
|
})
|
||||||
|
this.$Electron.registerMsgListener('replyNotification', target => {
|
||||||
|
console.log("[Notification] B Reply", target);
|
||||||
|
this.notificationReply(target)
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通知权限
|
||||||
|
*/
|
||||||
notificationPermission() {
|
notificationPermission() {
|
||||||
const userSelectFn = msg => {
|
const userSelectFn = msg => {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
@ -1181,6 +1192,48 @@ export default {
|
|||||||
};
|
};
|
||||||
this.notificationManage.initNotification(userSelectFn);
|
this.notificationManage.initNotification(userSelectFn);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击通知(客户端)
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
notificationClick(target) {
|
||||||
|
const {tag, data} = target;
|
||||||
|
if (tag == 'dialog') {
|
||||||
|
if (!$A.isJson(data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.goForward({name: 'manage-messenger'});
|
||||||
|
this.$nextTick(_ => {
|
||||||
|
this.$store.dispatch('openDialog', data.dialog_id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回复通知(客户端)
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
notificationReply(target) {
|
||||||
|
const {tag, data, reply} = target;
|
||||||
|
if (tag == 'dialog' && reply) {
|
||||||
|
this.$store.dispatch("call", {
|
||||||
|
url: 'dialog/msg/sendtext',
|
||||||
|
data: {
|
||||||
|
dialog_id: data.dialog_id,
|
||||||
|
text: reply,
|
||||||
|
},
|
||||||
|
method: 'post',
|
||||||
|
}).then(({data}) => {
|
||||||
|
this.$store.dispatch("saveDialogMsg", data);
|
||||||
|
this.$store.dispatch("increaseTaskMsgNum", data);
|
||||||
|
this.$store.dispatch("increaseMsgReplyNum", data);
|
||||||
|
this.$store.dispatch("updateDialogLastMsg", data);
|
||||||
|
}).catch(({msg}) => {
|
||||||
|
$A.modalError(msg)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user