-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
62 lines (43 loc) · 1.28 KB
/
example.ts
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
60
61
import Freestyle from "./dist";
import { emitKeypressEvents } from "readline";
const freestyle = new Freestyle("[email protected]", "password!");
async function main() {
await freestyle.init()
freestyle.printStatus();
await freestyle.watch();
freestyle.on('change', (data: any) => {
console.log('change detected')
console.log(data.changes);
})
freestyle.on('reportedState', (data: any) => {
console.log('reported state changed to:', data)
})
}
emitKeypressEvents(process.stdin);
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
console.log('press q to quit! (or: u, p, d, r)')
process.stdin.on('keypress', async (chunk, key) => {
if (key && key.name == 'u') {
console.log('unlocking');
await freestyle.unlock();
}
if (key && key.name == 'p') {
console.log('privacy locking');
await freestyle.privacyLock();
}
if (key && key.name == 'd') {
console.log('dead locking');
await freestyle.deadLock();
}
if (key && key.name == 'r') {
console.log('refreshing data');
await freestyle.getHome();
freestyle.printStatus();
}
if (key && key.name == 'q') {
console.log('quit');
process.exit(0);
}
});
main();