-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 979 Bytes
/
main.go
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
package main
import (
"os/exec"
"time"
"tinygo.org/x/bluetooth"
)
var (
deviceMAC = "" // Bluetooth Device MAC ID
minRSSI int16 = -60 // Minimum RSSI tolerance value of the bluetooth device
timeout = 30 * time.Second // Timeout Time
adapter = bluetooth.DefaultAdapter // Bluetooth Receiver
)
var timer = time.NewTicker(timeout)
func lockWindows() {
err := exec.Command("cmd", "/C", "rundll32.exe user32.dll,LockWorkStation").Run()
if err != nil {
return
}
}
func startTimer() {
go func() {
for range timer.C {
lockWindows()
}
}()
}
func main() {
startTimer()
err := adapter.Enable()
if err != nil {
panic("Failed to initialize adapter!")
}
err = adapter.Scan(func(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
if device.Address.String() == deviceMAC {
if device.RSSI > minRSSI {
timer.Reset(timeout)
}
}
})
if err != nil {
panic("Scan Error!")
}
}