diff --git a/client/react-native/common/bridge/service/daemon/daemon.pb.json b/client/react-native/common/bridge/service/daemon/daemon.pb.json index c6ab64def9..cd3cf6dab7 100644 --- a/client/react-native/common/bridge/service/daemon/daemon.pb.json +++ b/client/react-native/common/bridge/service/daemon/daemon.pb.json @@ -15,7 +15,7 @@ }, "GetLocalGrpcInfos": { "requestType": "Void", - "responseType": "Void" + "responseType": "GRPCInfos" }, "GetNetworkConfig": { "requestType": "Void", @@ -29,9 +29,9 @@ "requestType": "Config", "responseType": "Void" }, - "IsBotRunning": { + "GetBotState": { "requestType": "Void", - "responseType": "Void" + "responseType": "BotState" }, "ListAccounts": { "requestType": "Void", @@ -69,10 +69,6 @@ "requestType": "Void", "responseType": "Void" }, - "ThrowException": { - "requestType": "Void", - "responseType": "Void" - }, "UpdateNetworkConfig": { "requestType": "NetworkConfig", "responseType": "Void" @@ -82,6 +78,14 @@ "Void": { "fields": {} }, + "BotState": { + "fields": { + "isBotRunning": { + "type": "bool", + "id": 1 + } + } + }, "StartRequest": { "fields": { "nickname": { @@ -90,6 +94,14 @@ } } }, + "GRPCInfos": { + "fields": { + "json": { + "type": "string", + "id": 1 + } + } + }, "NetworkConfig": { "fields": { "json": { diff --git a/client/react-native/common/components/Screens/Settings/Devtools/List.js b/client/react-native/common/components/Screens/Settings/Devtools/List.js index 1b7f18b30c..711e6fff0a 100644 --- a/client/react-native/common/components/Screens/Settings/Devtools/List.js +++ b/client/react-native/common/components/Screens/Settings/Devtools/List.js @@ -112,10 +112,10 @@ class List extends PureComponent { const { bridge } = this.props try { - let running = await bridge.isBotRunning({}) + const { isBotRunning } = await bridge.getBotState({}) this.setState({ - botRunning: running, + botRunning: isBotRunning, botStateLoaded: true, }) } catch (err) { @@ -227,45 +227,41 @@ class List extends PureComponent { return ( - {(Platform.OS !== 'web' || Platform.Desktop) && ( - - } - /> - )} + + } + /> - {(Platform.OS !== 'web' || Platform.Desktop) && ( - - } - /> - )} + + } + /> 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintDaemon(dAtA, i, uint64(len(m.Json))) + i += copy(dAtA[i:], m.Json) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + func (m *NetworkConfig) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1689,6 +1813,21 @@ func (m *Void) Size() (n int) { return n } +func (m *BotState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.IsBotRunning { + n += 2 + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + func (m *StartRequest) Size() (n int) { if m == nil { return 0 @@ -1705,6 +1844,22 @@ func (m *StartRequest) Size() (n int) { return n } +func (m *GRPCInfos) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Json) + if l > 0 { + n += 1 + l + sovDaemon(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + func (m *NetworkConfig) Size() (n int) { if m == nil { return 0 @@ -1949,6 +2104,80 @@ func (m *Void) Unmarshal(dAtA []byte) error { } return nil } +func (m *BotState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDaemon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: BotState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BotState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsBotRunning", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDaemon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsBotRunning = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipDaemon(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDaemon + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthDaemon + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *StartRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -2035,6 +2264,92 @@ func (m *StartRequest) Unmarshal(dAtA []byte) error { } return nil } +func (m *GRPCInfos) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDaemon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GRPCInfos: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GRPCInfos: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Json", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDaemon + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDaemon + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDaemon + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Json = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDaemon(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthDaemon + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthDaemon + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *NetworkConfig) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/core/daemon/daemon.proto b/core/daemon/daemon.proto index 4365ec50b5..a28d9c03bb 100644 --- a/core/daemon/daemon.proto +++ b/core/daemon/daemon.proto @@ -6,11 +6,11 @@ option go_package = "berty.tech/core/daemon"; service Daemon { rpc DropDatabase (Void) returns (Void) {}; - rpc GetLocalGrpcInfos (Void) returns (Void) {}; + rpc GetLocalGrpcInfos (Void) returns (GRPCInfos) {}; rpc GetNetworkConfig (Void) returns (NetworkConfig) {}; rpc GetPort (Void) returns (GetPortResponse) {}; rpc Initialize (Config) returns (Void) {}; - rpc IsBotRunning (Void) returns (Void) {}; + rpc GetBotState (Void) returns (BotState) {}; rpc ListAccounts (Void) returns (ListAccountsResponse) {}; rpc Panic (Void) returns (Void) {}; rpc Restart (Void) returns (Void) {}; @@ -20,16 +20,24 @@ service Daemon { rpc StartLocalGRPC (Void) returns (Void) {}; rpc StopBot (Void) returns (Void) {}; rpc StopLocalGRPC (Void) returns (Void) {}; - rpc ThrowException (Void) returns (Void) {}; rpc UpdateNetworkConfig (NetworkConfig) returns (Void) {}; } message Void {} +message BotState { + bool isBotRunning = 1; +} + message StartRequest { string nickname = 1; } +// @TODO: switch to protobuf message instead of json +message GRPCInfos { + string json = 1; +} + // @TODO: switch to protobuf message instead of json message NetworkConfig { string json = 1; diff --git a/core/daemon/run.go b/core/daemon/run.go index dae5f1a5f7..dbec472e55 100644 --- a/core/daemon/run.go +++ b/core/daemon/run.go @@ -95,7 +95,9 @@ func (d *Daemon) daemon(ctx context.Context, cfg *Config, accountName string) er accountOptions = append(accountOptions, account.WithBot()) } - accountOptions = append(accountOptions, account.WithNotificationDriver(d.Notification)) + if d.Notification != nil { + accountOptions = append(accountOptions, account.WithNotificationDriver(d.Notification)) + } pushDispatchers, err := listPushDispatchers(cfg) if err != nil { @@ -118,6 +120,16 @@ func (d *Daemon) daemon(ctx context.Context, cfg *Config, accountName string) er return err } + if d.appConfig.LocalGRPC { + _, err = d.StartLocalGRPC(ctx, &Void{}) + if err != nil { + logger().Error(err.Error()) + d.appConfig.LocalGRPC = false + } + // Continue if local gRPC fails (e.g wifi not connected) + // Still re-enableable via toggle in devtools + } + go func() { var err error