我想知道 node.js 程序/脚本是否有可能阻止操作系统(Windows)进入睡眠或休眠模式?
问问题
4070 次
2 回答
3
这将对您有所帮助。
https://www.npmjs.com/package/stay-awake
var stayAwake = require('stay-awake');
// do something not so important
// prevent auto sleep
stayAwake.prevent(function(err, data) {
// handle error
console.log('%d routines are preventing sleep', data);
});
// do something which needs the computer to stay awake
// do something async
doAsync(function() {
// do something
stayAwake.prevent(function() {}); // second call
// do long processing
stayAwake.allow(function() {}); // this subroutine no longer needs to prevent sleep
});
// once done allow the computer to sleep as configured in power management
stayAwake.allow(function(err, data) {
if(data == 0) {
console.log('Will sleep automatically');
}
}); // allow
于 2017-04-12T04:58:24.200 回答
1
我被用来“保持清醒”,但它在“节点 14”中不起作用。
于 2021-09-06T16:12:27.563 回答