github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/service/delegate_ui.go (about)

     1  // Copyright 2015 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  	"github.com/keybase/client/go/libkb"
     8  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
     9  	context "golang.org/x/net/context"
    10  )
    11  
    12  // DelegateUICtlHandler is the RPC handler for notify control messages
    13  type DelegateUICtlHandler struct {
    14  	libkb.Contextified
    15  	*BaseHandler
    16  	id          libkb.ConnectionID
    17  	rekeyMaster *rekeyMaster
    18  }
    19  
    20  // NewDelegateUICtlHandler creates a new handler for setting up notification
    21  // channels
    22  func NewDelegateUICtlHandler(xp rpc.Transporter, id libkb.ConnectionID, g *libkb.GlobalContext, rekeyMaster *rekeyMaster) *DelegateUICtlHandler {
    23  	return &DelegateUICtlHandler{
    24  		Contextified: libkb.NewContextified(g),
    25  		BaseHandler:  NewBaseHandler(g, xp),
    26  		id:           id,
    27  		rekeyMaster:  rekeyMaster,
    28  	}
    29  }
    30  
    31  func (d *DelegateUICtlHandler) RegisterIdentifyUI(ctx context.Context) error {
    32  	d.G().UIRouter.SetUI(d.id, libkb.IdentifyUIKind)
    33  	d.pushGregorIdentifyUIHandler(ctx)
    34  	return nil
    35  }
    36  
    37  func (d *DelegateUICtlHandler) RegisterIdentify3UI(ctx context.Context) error {
    38  	d.G().UIRouter.SetUI(d.id, libkb.Identify3UIKind)
    39  	d.pushGregorIdentifyUIHandler(ctx)
    40  	return nil
    41  }
    42  
    43  func (d *DelegateUICtlHandler) pushGregorIdentifyUIHandler(_ context.Context) {
    44  	if d.G().GregorListener == nil {
    45  		return
    46  	}
    47  
    48  	// Let Gregor related code know that a IdentifyUI client
    49  	// (probably Electron) has connected, and to sync out state to it
    50  	d.G().GregorListener.PushHandler(NewIdentifyUIHandler(d.G(), d.id))
    51  }
    52  
    53  func (d *DelegateUICtlHandler) RegisterChatUI(_ context.Context) error {
    54  	d.G().UIRouter.SetUI(d.id, libkb.ChatUIKind)
    55  	return nil
    56  }
    57  
    58  func (d *DelegateUICtlHandler) RegisterLogUI(_ context.Context) error {
    59  	d.G().UIRouter.SetUI(d.id, libkb.LogUIKind)
    60  	return nil
    61  }
    62  
    63  func (d *DelegateUICtlHandler) RegisterSecretUI(_ context.Context) error {
    64  	d.G().UIRouter.SetUI(d.id, libkb.SecretUIKind)
    65  	return nil
    66  }
    67  
    68  func (d *DelegateUICtlHandler) RegisterUpdateUI(_ context.Context) error {
    69  	d.G().UIRouter.SetUI(d.id, libkb.UpdateUIKind)
    70  	return nil
    71  }
    72  
    73  func (d *DelegateUICtlHandler) RegisterHomeUI(_ context.Context) error {
    74  	d.G().UIRouter.SetUI(d.id, libkb.HomeUIKind)
    75  	return nil
    76  }
    77  
    78  func (d *DelegateUICtlHandler) RegisterGregorFirehose(ctx context.Context) error {
    79  	return d.registerGregorFirehose(ctx, nil)
    80  }
    81  
    82  func (d *DelegateUICtlHandler) RegisterGregorFirehoseFiltered(ctx context.Context, oobmSystems []string) error {
    83  	return d.registerGregorFirehose(ctx, oobmSystems)
    84  }
    85  
    86  func (d *DelegateUICtlHandler) registerGregorFirehose(ctx context.Context, oobmSystems []string) error {
    87  	if d.G().GregorListener != nil {
    88  		d.G().Log.Debug("Registering firehose on connection %d", d.id)
    89  		d.G().GregorListener.PushFirehoseHandler(newGregorFirehoseHandler(d.G(), d.id, d.xp, oobmSystems))
    90  	} else {
    91  		d.G().Log.Info("Failed to register firehose on connection %d", d.id)
    92  	}
    93  	return nil
    94  }
    95  
    96  func (d *DelegateUICtlHandler) RegisterRekeyUI(_ context.Context) error {
    97  	d.G().UIRouter.SetUI(d.id, libkb.RekeyUIKind)
    98  	if d.rekeyMaster != nil {
    99  		d.rekeyMaster.newUIRegistered()
   100  	}
   101  	return nil
   102  }