github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/appstate.go (about) 1 // Copyright 2017 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package service 5 6 import ( 7 "fmt" 8 "strings" 9 10 "github.com/keybase/client/go/libkb" 11 "github.com/keybase/client/go/protocol/keybase1" 12 "github.com/keybase/go-framed-msgpack-rpc/rpc" 13 "golang.org/x/net/context" 14 ) 15 16 type appStateHandler struct { 17 *BaseHandler 18 libkb.Contextified 19 } 20 21 func newAppStateHandler(xp rpc.Transporter, g *libkb.GlobalContext) *appStateHandler { 22 return &appStateHandler{ 23 BaseHandler: NewBaseHandler(g, xp), 24 Contextified: libkb.NewContextified(g), 25 } 26 } 27 28 func (a *appStateHandler) UpdateAppState(ctx context.Context, state keybase1.MobileAppState) (err error) { 29 a.G().Trace(fmt.Sprintf("UpdateAppState(%v)", state), &err)() 30 31 // Update app state 32 a.G().MobileAppState.Update(state) 33 return nil 34 } 35 36 func (a *appStateHandler) UpdateMobileNetState(ctx context.Context, stateStr string) (err error) { 37 a.G().Log.CDebugf(ctx, "UpdateMobileNetState(%v)", stateStr) 38 39 // normalize what the frontend gives us, `bluetooth`, `ethernet`, and 40 // `wimax` are android only values. 41 var state keybase1.MobileNetworkState 42 switch stateStr { 43 case "bluetooth", "ethernet": 44 stateStr = "wifi" 45 case "wimax": 46 stateStr = "cellular" 47 } 48 49 state, ok := keybase1.MobileNetworkStateMap[strings.ToUpper(stateStr)] 50 if !ok { 51 state = keybase1.MobileNetworkState_UNKNOWN 52 } 53 a.G().MobileNetState.Update(state) 54 return nil 55 } 56 57 func (a *appStateHandler) PowerMonitorEvent(ctx context.Context, event string) (err error) { 58 a.G().Log.CDebugf(ctx, "PowerMonitorEvent(%v)", event) 59 a.G().DesktopAppState.Update(a.MetaContext(ctx), event, a.xp) 60 return nil 61 }