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));
            });
  • 相关阅读:
    OutputStream之flush() · 李大白写点儿啥
    AQS总结
    深入理解JavaScript中的this关键字
    Cookie
    【翻译】Ext JS 5的平板支持
    【翻译】在Sencha Touch中创建离线/在线代理
    OpenCV——PS 图层混合算法 (三)
    OpenCV——PS 图层混合算法 (二)
    【翻译】在Ext JS和Sencha Touch中创建自定义布局
    OpenCV——PS 图层混合算法(一)
  • 原文地址:https://www.cnblogs.com/huangmin1992/p/13063816.html
Copyright © 2011-2022 走看看