Skip to content

Commit

Permalink
check nil everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgamma committed Feb 9, 2022
1 parent 2bb4b3b commit f850c3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
19 changes: 13 additions & 6 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,14 +1026,21 @@ func (b *GethStatusBackend) AppStateChange(state string) {
b.log.Info("App State changed", "new-state", s)
b.appState = s

wakuext := b.statusNode.WakuExtService()
if b.statusNode != nil {
wakuext := b.statusNode.WakuExtService()

if wakuext != nil {
messenger := wakuext.Messenger()

if wakuext != nil {
if s == appStateForeground {
wakuext.Messenger().ToForeground()
} else {
wakuext.Messenger().ToBackground()
if messenger != nil {
if s == appStateForeground {
messenger.ToForeground()
} else {
messenger.ToBackground()
}
}
}

}

// TODO: put node in low-power mode if the app is in background (or inactive)
Expand Down
8 changes: 6 additions & 2 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,15 @@ func (m *Messenger) resendExpiredMessages() error {
}

func (m *Messenger) ToForeground() {
m.imageServer.ToForeground()
if m.imageServer != nil {
m.imageServer.ToForeground()
}
}

func (m *Messenger) ToBackground() {
m.imageServer.ToBackground()
if m.imageServer != nil {
m.imageServer.ToBackground()
}
}

func (m *Messenger) Start() (*MessengerResponse, error) {
Expand Down

0 comments on commit f850c3e

Please sign in to comment.