From 29556f9e1f13daff5deebecb0e013654cf47c2d2 Mon Sep 17 00:00:00 2001
From: gaoshuaixing <530353222@qq.com>
Date: Mon, 11 Oct 2021 20:14:04 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E9=80=9A=E7=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
electron/ipc/example.js | 43 ++++++++++-
frontend/src/config/router.config.js | 7 +-
frontend/src/layouts/DemoMenu.vue | 6 ++
.../src/views/demo/notification/Index.vue | 75 +++++++++++++++++++
4 files changed, 129 insertions(+), 2 deletions(-)
create mode 100644 frontend/src/views/demo/notification/Index.vue
diff --git a/electron/ipc/example.js b/electron/ipc/example.js
index adb3171..9866520 100644
--- a/electron/ipc/example.js
+++ b/electron/ipc/example.js
@@ -9,11 +9,13 @@
* @param arg 接收到的消息
*/
-const {app, dialog, BrowserWindow, BrowserView} = require('electron');
+const {app, dialog, BrowserWindow, BrowserView, Notification} = require('electron');
const path = require('path');
+const _ = require('lodash');
let myTimer = null;
let browserViewObj = null;
+let notificationObj = null;
exports.hello = function (event, channel, msg) {
let newMsg = msg + " +1"
@@ -124,3 +126,42 @@ exports.removeViewContent = function () {
return winObj.id
}
+
+/**
+ * 创建系统通知
+ */
+ exports.sendNotification = function (event, channel, arg) {
+ if (!Notification.isSupported()) {
+ return '当前系统不支持通知';
+ }
+
+ let options = {};
+ if (!_.isEmpty(arg.title)) {
+ options.title = arg.title;
+ }
+ if (!_.isEmpty(arg.subtitle)) {
+ options.subtitle = arg.subtitle;
+ }
+ if (!_.isEmpty(arg.body)) {
+ options.body = arg.body;
+ }
+ if (!_.isEmpty(arg.silent)) {
+ options.silent = arg.silent;
+ }
+
+ notificationObj = new Notification(options);
+
+ if (arg.clickEvent) {
+ notificationObj.on('click', (e) => {
+ let data = {
+ type: 'click',
+ msg: '您点击了通知消息'
+ }
+ event.reply(`${channel}`, data)
+ });
+ }
+
+ notificationObj.show();
+
+ return true
+}
\ No newline at end of file
diff --git a/frontend/src/config/router.config.js b/frontend/src/config/router.config.js
index 06b931a..a5a2f01 100644
--- a/frontend/src/config/router.config.js
+++ b/frontend/src/config/router.config.js
@@ -37,7 +37,12 @@ export const constantRouterMap = [
path: '/demo/window/index',
name: 'DemoWindowIndex',
component: () => import('@/views/demo/window/Index')
- },
+ },
+ {
+ path: '/demo/notification/index',
+ name: 'DemoNotificationIndex',
+ component: () => import('@/views/demo/notification/Index')
+ },
{
path: '/demo/shortcut/index',
name: 'DemoShortcutIndex',
diff --git a/frontend/src/layouts/DemoMenu.vue b/frontend/src/layouts/DemoMenu.vue
index aa2510e..4064844 100644
--- a/frontend/src/layouts/DemoMenu.vue
+++ b/frontend/src/layouts/DemoMenu.vue
@@ -48,6 +48,12 @@ export default {
pageName: 'DemoWindowIndex',
params: {}
},
+ 'menu_402' : {
+ icon: 'profile',
+ title: '通知',
+ pageName: 'DemoNotificationIndex',
+ params: {}
+ },
'menu_500' : {
icon: 'profile',
title: '软件',
diff --git a/frontend/src/views/demo/notification/Index.vue b/frontend/src/views/demo/notification/Index.vue
new file mode 100644
index 0000000..d900a57
--- /dev/null
+++ b/frontend/src/views/demo/notification/Index.vue
@@ -0,0 +1,75 @@
+
+
+
+
+ 1. 弹出桌面通知(主进程)
+
+
+
+
+ 默认
+ 发出提示音
+ 点击通知触发事件
+
+
+
+
+
+