2020-08-18 11:59:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"after-lock/afterlock"
|
2020-08-20 14:57:57 +00:00
|
|
|
"after-lock/display"
|
|
|
|
"after-lock/keypressdetector"
|
2020-08-20 13:57:17 +00:00
|
|
|
"after-lock/lockfile"
|
2020-08-20 14:57:57 +00:00
|
|
|
"after-lock/lockscreen"
|
2020-08-20 13:57:17 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-08-20 14:57:57 +00:00
|
|
|
"runtime/debug"
|
2020-08-18 11:59:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
initialDelay = 3
|
|
|
|
loopDelay = 6
|
|
|
|
keyboardDeviceNode = "/dev/input/by-id/usb-Dell_Dell_USB_Entry_Keyboard-event-kbd"
|
2020-08-20 13:57:17 +00:00
|
|
|
lockfilePath = "/tmp/after-lock.lock"
|
|
|
|
printStackTraces = false
|
2020-08-18 11:59:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
2020-08-20 13:57:17 +00:00
|
|
|
defer handleErrors()
|
|
|
|
|
|
|
|
lock := grabExclusiveProcessLock()
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
2020-08-18 11:59:20 +00:00
|
|
|
al := afterlock.New(keyboardDeviceNode)
|
|
|
|
al.InitialDelay = initialDelay
|
|
|
|
al.LoopDelay = loopDelay
|
2020-08-20 14:57:57 +00:00
|
|
|
al.Display = display.Xset{}
|
|
|
|
al.LockScreen = lockscreen.XDG{}
|
|
|
|
al.KeypressDetector = keypressdetector.Evdev{}
|
2020-08-18 11:59:20 +00:00
|
|
|
|
|
|
|
al.Start()
|
2020-08-20 13:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func handleErrors() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
fmt.Printf("Crashed with unexpected error: %v!\n", err)
|
|
|
|
if printStackTraces {
|
|
|
|
fmt.Printf("Stack trace:\n\n")
|
|
|
|
debug.PrintStack()
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func grabExclusiveProcessLock() *lockfile.Lockfile {
|
|
|
|
lf := lockfile.New(lockfilePath)
|
|
|
|
err := lf.Lock()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return lf
|
2020-08-18 11:59:20 +00:00
|
|
|
}
|