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() { func (af *AfterLock) hybernateDisplayLoop() {
for { for {
screenLocked, err := af.LockScreen.IsActive() if !af.screenLocked() {
if err != nil {
panic(err)
}
if !screenLocked {
return return
} }
displayOn, err := af.Display.IsOn() if af.displayIsOn() {
if err != nil { af.suspendDisplay()
panic(err)
}
if displayOn {
err := af.Display.Suspend()
if err != nil {
panic(err)
}
} }
for { for {
@ -113,3 +102,26 @@ func (af *AfterLock) hybernateDisplayLoop() {
} }
} }
} }
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)
}
}