mirror of
https://github.com/danbulant/anti-sleep
synced 2026-07-05 11:00:34 +00:00
Handle exit and make interval configurable
This commit is contained in:
parent
64028cd91c
commit
493ddc123c
1 changed files with 35 additions and 5 deletions
40
index.ts
40
index.ts
|
|
@ -1,21 +1,24 @@
|
|||
import AutoPilot from 'https://deno.land/x/autopilot/mod.ts';
|
||||
import { parse } from "https://deno.land/std/flags/mod.ts";
|
||||
import { signal } from "https://deno.land/std/signal/mod.ts";
|
||||
|
||||
const args = parse(Deno.args, {
|
||||
alias: {
|
||||
inactivity: "a",
|
||||
interval: "i",
|
||||
start: "s",
|
||||
stop: "p"
|
||||
},
|
||||
default: {
|
||||
interval: 300000
|
||||
interval: 10000,
|
||||
start: 0,
|
||||
stop: 24,
|
||||
inactivity: 300000
|
||||
}
|
||||
});
|
||||
|
||||
const pilot = new AutoPilot();
|
||||
|
||||
pilot.notify("Do not sleep", "Do not sleep is now running!");
|
||||
|
||||
var last = {
|
||||
x: 0,
|
||||
y: 0
|
||||
|
|
@ -30,14 +33,41 @@ setInterval(() =>{
|
|||
wasActive = false;
|
||||
return;
|
||||
}
|
||||
if(!wasActive) {
|
||||
pilot.notify("Do not sleep", "Do not sleep is now active");
|
||||
}
|
||||
wasActive = true;
|
||||
var pos = pilot.mousePosition();
|
||||
if(pos.x !== last.x && pos.y !== last.y) {
|
||||
lastUpdate = Date.now();
|
||||
} else {
|
||||
if(Date.now() - lastUpdate > args.interval) { // 5minutes
|
||||
if(Date.now() - lastUpdate > args.inactivity) { // 5minutes
|
||||
pilot.moveMouse(pos.x + 1, pos.y + 1);
|
||||
pilot.notify("Do not sleep", "Your mouse was moved just now.");
|
||||
}
|
||||
}
|
||||
}, 10000);
|
||||
}, args.interval);
|
||||
|
||||
console.log("Ready");
|
||||
|
||||
const exit = () => {
|
||||
console.log('Goodbye!');
|
||||
pilot.notify("Do not sleep", "Do not sleep stopped");
|
||||
};
|
||||
|
||||
const sig = signal(
|
||||
Deno.Signal.SIGINT
|
||||
);
|
||||
|
||||
window.addEventListener("unload", exit);
|
||||
|
||||
function never() {
|
||||
return new Promise(async () => {
|
||||
for await (const _ of sig) {
|
||||
exit();
|
||||
Deno.exit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await never();
|
||||
Loading…
Reference in a new issue