在基于电子的桌面应用程序中找到用户空闲时间的最佳方法

问题描述 投票:0回答:1

我想知道在使用electronicjs制作的桌面应用程序中包括空闲时间时最好的选择是什么。

electron desktop-application desktop
1个回答
0
投票

我为此找到了一个简单的脚本。在我的情况下,我会在3分钟的空闲时间后触发锁定屏幕,但我认为脚本可以轻松调整。每次移动或按下鼠标时,计时器都会从头开始计时。

function inactivityTime () {
    var t;
    window.onload = resetTimer;
    // DOM Events
    document.onmousemove = resetTimer;
    document.onkeypress = resetTimer;

    function lock() {
        $('#lockscreen').css('display', 'block'); 
    }

    function resetTimer() {
        clearTimeout(t);
        t = setTimeout(lock, 180000) //3 Minuten timeout
    }
};

并将其加载到document.ready:

$("document").ready(function () {
    inactivityTime();
});
© www.soinside.com 2019 - 2024. All rights reserved.