Refactor error handling for cleaner code

This commit is contained in:
Kristóf Tóth 2020-09-08 15:45:26 +02:00
parent b652c48bd4
commit 6cea681f6f

View File

@ -84,23 +84,12 @@ func (af *AfterLock) detectKeypresses() {
func (af *AfterLock) hybernateDisplayLoop() {
for {
screenLocked, err := af.LockScreen.IsActive()
if err != nil {
panic(err)
}
if !screenLocked {
if !af.screenLocked() {
return
}
displayOn, err := af.Display.IsOn()
if err != nil {
panic(err)
}
if displayOn {
err := af.Display.Suspend()
if err != nil {
panic(err)
}
if af.displayIsOn() {
af.suspendDisplay()
}
for {
@ -112,4 +101,27 @@ func (af *AfterLock) hybernateDisplayLoop() {
break
}
}
}
func (af *AfterLock) screenLocked() bool {
screenLocked, err := af.LockScreen.IsActive()
if err != nil {
panic(err)
}
return screenLocked
}
func (af *AfterLock) displayIsOn() bool {
displayOn, err := af.Display.IsOn()
if err != nil {
panic(err)
}
return displayOn
}
func (af *AfterLock) suspendDisplay() {
err := af.Display.Suspend()
if err != nil {
panic(err)
}
}