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

 

posted @ 2020-06-08 09:30  面包_girl  阅读(1679)  评论(0编辑  收藏  举报
/* 鼠标点击文字特效 */