-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·44 lines (37 loc) · 1.12 KB
/
app.js
File metadata and controls
executable file
·44 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var chokidar = require('chokidar');
var watcher = chokidar.watch('file');
var exec = require('child_process').exec;
const appToKill = 'notepad';
const appToStart = 'notepad.exe';
const fileToWatch = 'filename.txt';
const secondsToWait = 0;
const maxAge = 15 // seconds (60 = 1 minute, 300 = 5 minutes)
var lastFileChange = 0;
var log = console.log.bind(console);
watcher
.on('change', function(path) {
log('File '+path+' has changed.');
lastFileChange = 0;
});
watcher.add(fileToWatch);
log('Rustmin ready to work. Watching for file changes.');
function resetApp() {
exec('powershell.exe Stop-Process -processname '+appToKill);
setTimeout(function(){
exec('powershell.exe Start-Process '+appToStart, function(err) {
if (err) {
throw new Error('Something\'s fucky: '+err);
}
});
lastFileChange = 0;
}, secondsToWait*1000);
};
setInterval(function() {
if (lastFileChange >= maxAge) {
resetApp();
console.log('Last File Change: '+lastFileChange+' seconds ago.');
} else {
lastFileChange+= 1;
console.log('Last File Change: '+lastFileChange+' seconds ago.');
}
},1000);