-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (53 loc) · 1.49 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
function getMillisecondsToNextHalfHourOrHour() {
let now = new Date(); // 获取当前时间
let minutes = now.getMinutes(); // 获取当前的分钟数
let nextTime;
if (minutes < 30) {
// 如果当前分钟小于30,则下一个时间点是当前小时的30分钟
nextTime = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
now.getHours(),
30,
0,
0
);
} else {
// 否则,下一个时间点是下一个小时的整点
nextTime = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
now.getHours() + 1,
0,
0,
0
);
}
// 计算差值(毫秒)
let millisecondsToNext = nextTime.getTime() - now.getTime();
return millisecondsToNext;
}
function restart() {
if(process.platform === 'win32') {
const restartWin = require('./restart-win');
restartWin('ShareMouse/ShareMouse.exe');
}
else {
const restartMac = require('./restart-mac');
restartMac('ShareMouse.app');
}
}
function jihua() {
let millisecondsUntilNext = getMillisecondsToNextHalfHourOrHour();
console.log("距离下一个30分钟或整点还有多少毫秒:", millisecondsUntilNext);
// restart();
setTimeout(() => {
console.log('重启');
restart();
jihua();
}, millisecondsUntilNext);
}
jihua();