【问题标题】:Electron App -How to automatically log out a user after inactivity for 15 minutes?Electron App - 如何在不活动 15 分钟后自动注销用户?
【发布时间】:2016-12-22 00:15:07
【问题描述】:

我正在制作一个电子应用程序,想知道如何在用户闲置 15 分钟后自动注销用户!非常感谢!

const electron = require('electron');
const app = electron.app;

let willQuitApp = false;
let window;

app.on('ready', () => {
  window = new electron.BrowserWindow();

  window.on('close', (e) => {
    if (willQuitApp) {
    window = null;
   } else {
      /* the user only tried to close the window */
    e.preventDefault();
    window.hide();
   }
  });

  window.loadURL(`mypage`); /* load your page */

});
app.on('activate', () => window.show());

app.on('before-quit', () => willQuitApp = true);

【问题讨论】:

    标签: javascript timeout desktop-application logout electron


    【解决方案1】:

    如果您特别对应用中的空闲时间感兴趣,那么这就是previously answered。另一方面,如果你对系统空闲时间感兴趣,那么你会想要使用https://github.com/paulcbetts/node-system-idle-time

    【讨论】:

      【解决方案2】:

      查看Electron Power monitor API's 和 实现一个 Interval 函数来检查时间是否超过 15 分钟然后注销用户

      const {powerMonitor} = require('electron'); 
      const idle = powerMonitor.getSystemIdleTime() // it returns in seconds when I am writing this
      console.log('Current System Idle Time - ', idle); 
      

      【讨论】:

      • OP 要求电子应用空闲时间而不是系统空闲时间。
      猜你喜欢
      • 1970-01-01
      • 2011-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 2023-03-16
      • 2016-04-13
      相关资源
      最近更新 更多