zoukankan      html  css  js  c++  java
  • electron-开机自启动,启用操作系统气泡提示,有任务时,阻止电脑休眠


    //
    开机自启动 const exeName = path.basename(process.execPath); ipcMain.on('boot-start', (event, args) => { if (!app.isPackaged) { app.setLoginItemSettings({ openAtLogin: args, path: process.execPath }); } else { app.setLoginItemSettings({ openAtLogin: args }); } }); app.setLoginItemSettings({ openAtLogin: app.getLoginItemSettings().openAtLogin, openAsHidden: false, path: process.execPath, args: [ '--processStart', `"${exeName}"`, ] });

    操作系统气泡提示,下载依赖 ,

    npm i node-notifier --save

    在electron-bootstrap.ts中引用

    const notifier = require('node-notifier');

    app.setAppUserModelId(process.execPath);
            ipcMain.on('send-notification', (event, args) => {
              notifier.notify(
                {
                  title: args.title,
                  message: args.message,
                  icon: path.join(__dirname, 'src/favicon.png'),
                  sound: true,
                  wait: true,
                  appName : ''
                },
                function (err, response) {
                  // Response is response from notification
                  console.log(err);
                  console.log(response);
                }
              );
              notifier.on('click', function (notifierObject, options, event) {
                // Triggers if `wait: true` and user clicks notification
                console.log(notifierObject);
              });
    
              notifier.on('timeout', function (notifierObject, options) {
                // Triggers if `wait: true` and notification closes
                console.log(notifierObject);
              });
            });

    阻止电脑休眠,在渲染进程触发。

    ipcMain.on('prevent-power-sleep', (event, args) => {
              const id = powerSaveBlocker.start('prevent-display-sleep');
              if (args) {
                powerSaveBlocker.stop(id);
              }
              console.log('powerSaveBlocker start>>>' + powerSaveBlocker.isStarted(id));
            });
  • 相关阅读:
    Spring Cloud 五 Feign的文件上传实现
    Spring Cloud 四:服务消费(Feign)【Dalston版】
    Spring Cloud 三:服务消费(Ribbon)【Dalston版】
    Spring Cloud二:服务消费(基础)【Dalston版】
    Spring Cloud 一:服务注册与发现(Eureka)【Dalston版】
    mybatis 单个参数
    医院设置(图论Floyd)
    Mysql学习——安装登录
    字母游戏(搜索)
    子数列连续和
  • 原文地址:https://www.cnblogs.com/huangmin1992/p/13063816.html
Copyright © 2011-2022 走看看