-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (49 loc) · 1.36 KB
/
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
52
53
54
55
56
57
package main
import (
"context"
"log"
"log/slog"
"os"
"os/signal"
"time"
"github.com/keylogme/keylogme-zero/keylog"
"github.com/keylogme/keylogme-zero/keylog/storage"
"github.com/keylogme/keylogme-zero/keylog/utils"
)
// Use lsinput to see the usb_name to be used
// apt install input-utils
// sudo lsinput
// If your keyboard name appeared multiple times,
// try with all of them
// See readme
func main() {
// Get config
file_config := os.Getenv("CONFIG_FILE")
if file_config == "" {
log.Fatal("CONFIG_FILE is not set")
}
var config keylog.KeylogmeZeroConfigV1
err := utils.ParseFromFile(file_config, &config)
if err != nil {
log.Fatal("Could not parse config file")
}
// Start logger
ctx, cancel := context.WithCancel(context.Background())
ffs := storage.MustGetNewFileStorage(ctx, config.Storage)
chEvt := make(chan keylog.DeviceEvent)
devices := []keylog.Device{}
for _, dev := range config.Keylog.Devices {
d := keylog.GetDevice(ctx, dev, chEvt)
devices = append(devices, *d)
}
sd := keylog.MustGetNewShortcutsDetector(config.Keylog.ShortcutGroups)
keylog.Start(chEvt, &devices, sd, ffs)
// Graceful shutdown
ctxInt, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
<-ctxInt.Done()
slog.Info("Shutting down, graceful wait...")
cancel()
time.Sleep(3 * time.Second) // graceful wait
slog.Info("Logger closed.")
}