electron-egg electron-egg
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
首页
  • v4.x
  • v3.x
  • v2.x
插件
  • v4.x
  • v3.x
demo
支持
知识点
案例
交流
  • GitHub (opens new window)
  • Gitee (opens new window)
❤️成为赞助商
  • 框架

  • 操作系统

    • 文件
    • 视图
    • 窗口
    • 桌面通知
      • 电源监控
      • 屏幕信息
      • 系统主题
    • 特效

    • 硬件

    • 优惠券
    • 异常处理
    目录

    桌面通知

    调用操作系统通知api

    # 弹出桌面通知

      // frontend/src/views/os/notification/Index.vue
      <script>
        let content = [
            {
              type: 'main',
              title: '通知标题',
              subtitle: '副标题', // macOS系统专有属性
              body: '这是通知内容-默认',
              silent: true,
            },
            {
              type: 'main',
              title: '提示音',
              subtitle: '副标题-提示音',
              body: '这是通知内容-提示音',
              silent: false,
            },
            {
              type: 'main',
              title: '点击通知事件',
              subtitle: '副标题-点击通知事件',
              body: '这是通知内容-点击通知事件',
              clickEvent: true
            },
            {
              type: 'main',
              title: '关闭通知事件',
              subtitle: '副标题-关闭通知事件',
              body: '这是通知内容-点击通知事件',
              closeEvent: true
            },             
          ],
        sendNotification (index) {
          this.$ipc.send(ipcApiRoute.sendNotification, this.content[index]);
        },
      </script> 
      
      // electron/controller/os.js
      /**
       * 创建系统通知
       */
      sendNotification(args, event) {
        const { title, subtitle, body, silent} = args;
        if (!Notification.isSupported()) {
          return '当前系统不支持通知';
        }
        let options = {};
        if (!_.isEmpty(title)) {
          options.title = title;
        }
        if (!_.isEmpty(subtitle)) {
          options.subtitle = subtitle;
        }
        if (!_.isEmpty(body)) {
          options.body = body;
        }
        if (!_.isEmpty(silent)) {
          options.silent = silent;
        }
        this.service.os.createNotification(options, event);
        return true
      } 
      
      // Make sure to add code blocks to your code group

      # 完整代码

      • github前端代码 (opens new window)
      • github主进程代码 (opens new window)
      • gitee前端代码 (opens new window)
      • gitee主进程代码 (opens new window)
      上次更新: 2025/06/06, 07:21:49
      窗口
      电源监控

      ← 窗口 电源监控→

      Theme by Vdoing | Copyright © 2023-2025 哆啦好梦 | 京ICP备15041380号-2
      • 跟随系统
      • 浅色模式
      • 深色模式
      • 阅读模式
      ×