57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"after-lock/afterlock"
|
|
"after-lock/display"
|
|
"after-lock/keypressdetector"
|
|
"after-lock/lockfile"
|
|
"after-lock/lockscreen"
|
|
"fmt"
|
|
"os"
|
|
"runtime/debug"
|
|
)
|
|
|
|
const (
|
|
initialDelay = 3
|
|
loopDelay = 6
|
|
keyboardDeviceNode = "/dev/input/by-id/usb-Dell_Dell_USB_Entry_Keyboard-event-kbd"
|
|
lockfilePath = "/tmp/after-lock.lock"
|
|
printStackTraces = false
|
|
)
|
|
|
|
|
|
func main() {
|
|
defer handleErrors()
|
|
|
|
lock := grabExclusiveProcessLock()
|
|
defer lock.Unlock()
|
|
|
|
al := afterlock.New(keyboardDeviceNode)
|
|
al.InitialDelay = initialDelay
|
|
al.LoopDelay = loopDelay
|
|
al.Display = display.Xset{}
|
|
al.LockScreen = lockscreen.XDG{}
|
|
al.KeypressDetector = keypressdetector.Evdev{}
|
|
|
|
al.Start()
|
|
}
|
|
|
|
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
|
|
} |