This repository was archived by the owner on Aug 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdevice.js
58 lines (54 loc) · 1.55 KB
/
device.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
auto();
const targetBrightness = 0;
const targetMediaVolume = 0;
const autoBrightnessMode = 1;
const isAutoBrightnessMode = device.getBrightnessMode();
const previousBrightness = device.getBrightness();
const previousMusicVolume = device.getMusicVolume();
module.exports = {
/**
* 监听“音量下”键
*/
setEventListener : () => {
// 手动退出
threads.start(function() {
// 启用按键监听
events.observeKey();
// 监听音量下键按下
events.onKeyDown("volume_down", function (event) {
log("程序即将退出");
revertPower();
threads.shutDownAll();
toastLog("程序手动退出");
exit();
});
});
},
/**
* 检查无障碍和截图权限
*/
checkPermission : () => {
auto();
if (!requestScreenCapture(true)) {
toastLog('请求截图失败,程序结束');
exit();
}
// this.savePower();
},
/**
* 调节亮度及音量,进入低功耗模式
*/
savePower : () => {
log("save power");
device.setBrightness(targetBrightness);
device.setMusicVolume(targetMediaVolume);
},
}
/**
* 还原运行时脚本之前的屏幕亮度及设备音量
*/
revertPower = () => {
log("revert power");
isAutoBrightnessMode ? device.setBrightnessMode(autoBrightnessMode) : device.setBrightness(previousBrightness);
device.setMusicVolume(previousMusicVolume);
}