Fix device type field and default to tablet. Fixes #8

This commit is contained in:
Tulir Asokan 2023-08-24 11:16:08 +03:00
parent 97a3c97b8e
commit 6f21016ccf
9 changed files with 182 additions and 113 deletions

View file

@ -35,6 +35,7 @@ type Config struct {
GoogleMessages struct { GoogleMessages struct {
OS string `yaml:"os"` OS string `yaml:"os"`
Browser string `yaml:"browser"` Browser string `yaml:"browser"`
Device string `yaml:"device"`
AggressiveReconnect bool `yaml:"aggressive_reconnect"` AggressiveReconnect bool `yaml:"aggressive_reconnect"`
} `yaml:"google_messages"` } `yaml:"google_messages"`

View file

@ -94,6 +94,10 @@ google_messages:
# Browser type to tell the phone. This decides which icon is shown. # Browser type to tell the phone. This decides which icon is shown.
# Valid types: OTHER, CHROME, FIREFOX, SAFARI, OPERA, IE, EDGE # Valid types: OTHER, CHROME, FIREFOX, SAFARI, OPERA, IE, EDGE
browser: OTHER browser: OTHER
# Device type to tell the phone. This also affects the icon, as well as how many sessions are allowed simultaneously.
# One web, two tablets and one PWA should be able to connect at the same time.
# Valid types: WEB, TABLET, PWA
device: TABLET
# Should the bridge aggressively set itself as the active device if the user opens Google Messages in a browser? # Should the bridge aggressively set itself as the active device if the user opens Google Messages in a browser?
# If this is disabled, the user must manually use the `set-active` command to reactivate the bridge. # If this is disabled, the user must manually use the `set-active` command to reactivate the bridge.

View file

@ -86,6 +86,58 @@ func (BrowserType) EnumDescriptor() ([]byte, []int) {
return file_authentication_proto_rawDescGZIP(), []int{0} return file_authentication_proto_rawDescGZIP(), []int{0}
} }
type DeviceType int32
const (
DeviceType_UNKNOWN_DEVICE_TYPE DeviceType = 0
DeviceType_WEB DeviceType = 1
DeviceType_TABLET DeviceType = 2
DeviceType_PWA DeviceType = 3
)
// Enum value maps for DeviceType.
var (
DeviceType_name = map[int32]string{
0: "UNKNOWN_DEVICE_TYPE",
1: "WEB",
2: "TABLET",
3: "PWA",
}
DeviceType_value = map[string]int32{
"UNKNOWN_DEVICE_TYPE": 0,
"WEB": 1,
"TABLET": 2,
"PWA": 3,
}
)
func (x DeviceType) Enum() *DeviceType {
p := new(DeviceType)
*p = x
return p
}
func (x DeviceType) String() string {
return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))
}
func (DeviceType) Descriptor() protoreflect.EnumDescriptor {
return file_authentication_proto_enumTypes[1].Descriptor()
}
func (DeviceType) Type() protoreflect.EnumType {
return &file_authentication_proto_enumTypes[1]
}
func (x DeviceType) Number() protoreflect.EnumNumber {
return protoreflect.EnumNumber(x)
}
// Deprecated: Use DeviceType.Descriptor instead.
func (DeviceType) EnumDescriptor() ([]byte, []int) {
return file_authentication_proto_rawDescGZIP(), []int{1}
}
type BrowserDetails struct { type BrowserDetails struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -94,7 +146,7 @@ type BrowserDetails struct {
UserAgent string `protobuf:"bytes,1,opt,name=userAgent,proto3" json:"userAgent,omitempty"` UserAgent string `protobuf:"bytes,1,opt,name=userAgent,proto3" json:"userAgent,omitempty"`
BrowserType BrowserType `protobuf:"varint,2,opt,name=browserType,proto3,enum=authentication.BrowserType" json:"browserType,omitempty"` BrowserType BrowserType `protobuf:"varint,2,opt,name=browserType,proto3,enum=authentication.BrowserType" json:"browserType,omitempty"`
OS string `protobuf:"bytes,3,opt,name=OS,proto3" json:"OS,omitempty"` OS string `protobuf:"bytes,3,opt,name=OS,proto3" json:"OS,omitempty"`
SomeBool bool `protobuf:"varint,6,opt,name=someBool,proto3" json:"someBool,omitempty"` DeviceType DeviceType `protobuf:"varint,6,opt,name=deviceType,proto3,enum=authentication.DeviceType" json:"deviceType,omitempty"`
} }
func (x *BrowserDetails) Reset() { func (x *BrowserDetails) Reset() {
@ -150,11 +202,11 @@ func (x *BrowserDetails) GetOS() string {
return "" return ""
} }
func (x *BrowserDetails) GetSomeBool() bool { func (x *BrowserDetails) GetDeviceType() DeviceType {
if x != nil { if x != nil {
return x.SomeBool return x.DeviceType
} }
return false return DeviceType_UNKNOWN_DEVICE_TYPE
} }
type Device struct { type Device struct {
@ -1576,69 +1628,71 @@ func file_authentication_proto_rawDescGZIP() []byte {
return file_authentication_proto_rawDescData return file_authentication_proto_rawDescData
} }
var file_authentication_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_authentication_proto_enumTypes = make([]protoimpl.EnumInfo, 2)
var file_authentication_proto_msgTypes = make([]protoimpl.MessageInfo, 24) var file_authentication_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_authentication_proto_goTypes = []interface{}{ var file_authentication_proto_goTypes = []interface{}{
(BrowserType)(0), // 0: authentication.BrowserType (BrowserType)(0), // 0: authentication.BrowserType
(*BrowserDetails)(nil), // 1: authentication.BrowserDetails (DeviceType)(0), // 1: authentication.DeviceType
(*Device)(nil), // 2: authentication.Device (*BrowserDetails)(nil), // 2: authentication.BrowserDetails
(*ConfigVersion)(nil), // 3: authentication.ConfigVersion (*Device)(nil), // 3: authentication.Device
(*AuthenticationContainer)(nil), // 4: authentication.AuthenticationContainer (*ConfigVersion)(nil), // 4: authentication.ConfigVersion
(*AuthMessage)(nil), // 5: authentication.AuthMessage (*AuthenticationContainer)(nil), // 5: authentication.AuthenticationContainer
(*RevokeRelayPairingRequest)(nil), // 6: authentication.RevokeRelayPairingRequest (*AuthMessage)(nil), // 6: authentication.AuthMessage
(*RevokeRelayPairingResponse)(nil), // 7: authentication.RevokeRelayPairingResponse (*RevokeRelayPairingRequest)(nil), // 7: authentication.RevokeRelayPairingRequest
(*RegisterRefreshRequest)(nil), // 8: authentication.RegisterRefreshRequest (*RevokeRelayPairingResponse)(nil), // 8: authentication.RevokeRelayPairingResponse
(*RegisterRefreshResponse)(nil), // 9: authentication.RegisterRefreshResponse (*RegisterRefreshRequest)(nil), // 9: authentication.RegisterRefreshRequest
(*RegisterPhoneRelayResponse)(nil), // 10: authentication.RegisterPhoneRelayResponse (*RegisterRefreshResponse)(nil), // 10: authentication.RegisterRefreshResponse
(*CoordinateMessage)(nil), // 11: authentication.CoordinateMessage (*RegisterPhoneRelayResponse)(nil), // 11: authentication.RegisterPhoneRelayResponse
(*RefreshPhoneRelayResponse)(nil), // 12: authentication.RefreshPhoneRelayResponse (*CoordinateMessage)(nil), // 12: authentication.CoordinateMessage
(*WebEncryptionKeyResponse)(nil), // 13: authentication.WebEncryptionKeyResponse (*RefreshPhoneRelayResponse)(nil), // 13: authentication.RefreshPhoneRelayResponse
(*ECDSAKeys)(nil), // 14: authentication.ECDSAKeys (*WebEncryptionKeyResponse)(nil), // 14: authentication.WebEncryptionKeyResponse
(*CurrentDeviceData)(nil), // 15: authentication.CurrentDeviceData (*ECDSAKeys)(nil), // 15: authentication.ECDSAKeys
(*KeyData)(nil), // 16: authentication.KeyData (*CurrentDeviceData)(nil), // 16: authentication.CurrentDeviceData
(*WebAuthKey)(nil), // 17: authentication.WebAuthKey (*KeyData)(nil), // 17: authentication.KeyData
(*URLData)(nil), // 18: authentication.URLData (*WebAuthKey)(nil), // 18: authentication.WebAuthKey
(*TokenData)(nil), // 19: authentication.TokenData (*URLData)(nil), // 19: authentication.URLData
(*PairedData)(nil), // 20: authentication.PairedData (*TokenData)(nil), // 20: authentication.TokenData
(*RevokePairData)(nil), // 21: authentication.RevokePairData (*PairedData)(nil), // 21: authentication.PairedData
(*RegisterRefreshRequest_NestedEmptyArr)(nil), // 22: authentication.RegisterRefreshRequest.NestedEmptyArr (*RevokePairData)(nil), // 22: authentication.RevokePairData
(*RegisterRefreshResponse_AuthKeyData)(nil), // 23: authentication.RegisterRefreshResponse.AuthKeyData (*RegisterRefreshRequest_NestedEmptyArr)(nil), // 23: authentication.RegisterRefreshRequest.NestedEmptyArr
(*RegisterPhoneRelayResponse_AuthKeyData)(nil), // 24: authentication.RegisterPhoneRelayResponse.AuthKeyData (*RegisterRefreshResponse_AuthKeyData)(nil), // 24: authentication.RegisterRefreshResponse.AuthKeyData
(*EmptyArr)(nil), // 25: util.EmptyArr (*RegisterPhoneRelayResponse_AuthKeyData)(nil), // 25: authentication.RegisterPhoneRelayResponse.AuthKeyData
(*EmptyArr)(nil), // 26: util.EmptyArr
} }
var file_authentication_proto_depIdxs = []int32{ var file_authentication_proto_depIdxs = []int32{
0, // 0: authentication.BrowserDetails.browserType:type_name -> authentication.BrowserType 0, // 0: authentication.BrowserDetails.browserType:type_name -> authentication.BrowserType
5, // 1: authentication.AuthenticationContainer.authMessage:type_name -> authentication.AuthMessage 1, // 1: authentication.BrowserDetails.deviceType:type_name -> authentication.DeviceType
1, // 2: authentication.AuthenticationContainer.browserDetails:type_name -> authentication.BrowserDetails 6, // 2: authentication.AuthenticationContainer.authMessage:type_name -> authentication.AuthMessage
16, // 3: authentication.AuthenticationContainer.keyData:type_name -> authentication.KeyData 2, // 3: authentication.AuthenticationContainer.browserDetails:type_name -> authentication.BrowserDetails
15, // 4: authentication.AuthenticationContainer.deviceData:type_name -> authentication.CurrentDeviceData 17, // 4: authentication.AuthenticationContainer.keyData:type_name -> authentication.KeyData
3, // 5: authentication.AuthMessage.configVersion:type_name -> authentication.ConfigVersion 16, // 5: authentication.AuthenticationContainer.deviceData:type_name -> authentication.CurrentDeviceData
5, // 6: authentication.RevokeRelayPairingRequest.authMessage:type_name -> authentication.AuthMessage 4, // 6: authentication.AuthMessage.configVersion:type_name -> authentication.ConfigVersion
2, // 7: authentication.RevokeRelayPairingRequest.browser:type_name -> authentication.Device 6, // 7: authentication.RevokeRelayPairingRequest.authMessage:type_name -> authentication.AuthMessage
5, // 8: authentication.RegisterRefreshRequest.messageAuth:type_name -> authentication.AuthMessage 3, // 8: authentication.RevokeRelayPairingRequest.browser:type_name -> authentication.Device
2, // 9: authentication.RegisterRefreshRequest.currBrowserDevice:type_name -> authentication.Device 6, // 9: authentication.RegisterRefreshRequest.messageAuth:type_name -> authentication.AuthMessage
22, // 10: authentication.RegisterRefreshRequest.emptyRefreshArr:type_name -> authentication.RegisterRefreshRequest.NestedEmptyArr 3, // 10: authentication.RegisterRefreshRequest.currBrowserDevice:type_name -> authentication.Device
23, // 11: authentication.RegisterRefreshResponse.tokenData:type_name -> authentication.RegisterRefreshResponse.AuthKeyData 23, // 11: authentication.RegisterRefreshRequest.emptyRefreshArr:type_name -> authentication.RegisterRefreshRequest.NestedEmptyArr
11, // 12: authentication.RegisterPhoneRelayResponse.coordinates:type_name -> authentication.CoordinateMessage 24, // 12: authentication.RegisterRefreshResponse.tokenData:type_name -> authentication.RegisterRefreshResponse.AuthKeyData
2, // 13: authentication.RegisterPhoneRelayResponse.browser:type_name -> authentication.Device 12, // 13: authentication.RegisterPhoneRelayResponse.coordinates:type_name -> authentication.CoordinateMessage
24, // 14: authentication.RegisterPhoneRelayResponse.authKeyData:type_name -> authentication.RegisterPhoneRelayResponse.AuthKeyData 3, // 14: authentication.RegisterPhoneRelayResponse.browser:type_name -> authentication.Device
11, // 15: authentication.RefreshPhoneRelayResponse.coordinates:type_name -> authentication.CoordinateMessage 25, // 15: authentication.RegisterPhoneRelayResponse.authKeyData:type_name -> authentication.RegisterPhoneRelayResponse.AuthKeyData
11, // 16: authentication.WebEncryptionKeyResponse.coordinates:type_name -> authentication.CoordinateMessage 12, // 16: authentication.RefreshPhoneRelayResponse.coordinates:type_name -> authentication.CoordinateMessage
2, // 17: authentication.CurrentDeviceData.browser:type_name -> authentication.Device 12, // 17: authentication.WebEncryptionKeyResponse.coordinates:type_name -> authentication.CoordinateMessage
2, // 18: authentication.KeyData.mobile:type_name -> authentication.Device 3, // 18: authentication.CurrentDeviceData.browser:type_name -> authentication.Device
14, // 19: authentication.KeyData.ecdsaKeys:type_name -> authentication.ECDSAKeys 3, // 19: authentication.KeyData.mobile:type_name -> authentication.Device
17, // 20: authentication.KeyData.webAuthKeyData:type_name -> authentication.WebAuthKey 15, // 20: authentication.KeyData.ecdsaKeys:type_name -> authentication.ECDSAKeys
2, // 21: authentication.KeyData.browser:type_name -> authentication.Device 18, // 21: authentication.KeyData.webAuthKeyData:type_name -> authentication.WebAuthKey
2, // 22: authentication.PairedData.mobile:type_name -> authentication.Device 3, // 22: authentication.KeyData.browser:type_name -> authentication.Device
19, // 23: authentication.PairedData.tokenData:type_name -> authentication.TokenData 3, // 23: authentication.PairedData.mobile:type_name -> authentication.Device
2, // 24: authentication.PairedData.browser:type_name -> authentication.Device 20, // 24: authentication.PairedData.tokenData:type_name -> authentication.TokenData
2, // 25: authentication.RevokePairData.revokedDevice:type_name -> authentication.Device 3, // 25: authentication.PairedData.browser:type_name -> authentication.Device
25, // 26: authentication.RegisterRefreshRequest.NestedEmptyArr.emptyArr:type_name -> util.EmptyArr 3, // 26: authentication.RevokePairData.revokedDevice:type_name -> authentication.Device
27, // [27:27] is the sub-list for method output_type 26, // 27: authentication.RegisterRefreshRequest.NestedEmptyArr.emptyArr:type_name -> util.EmptyArr
27, // [27:27] is the sub-list for method input_type 28, // [28:28] is the sub-list for method output_type
27, // [27:27] is the sub-list for extension type_name 28, // [28:28] is the sub-list for method input_type
27, // [27:27] is the sub-list for extension extendee 28, // [28:28] is the sub-list for extension type_name
0, // [0:27] is the sub-list for field type_name 28, // [28:28] is the sub-list for extension extendee
0, // [0:28] is the sub-list for field type_name
} }
func init() { file_authentication_proto_init() } func init() { file_authentication_proto_init() }
@ -1947,7 +2001,7 @@ func file_authentication_proto_init() {
File: protoimpl.DescBuilder{ File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_authentication_proto_rawDesc, RawDescriptor: file_authentication_proto_rawDesc,
NumEnums: 1, NumEnums: 2,
NumMessages: 24, NumMessages: 24,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,

Binary file not shown.

View file

@ -16,11 +16,18 @@ enum BrowserType {
EDGE = 7; EDGE = 7;
} }
enum DeviceType {
UNKNOWN_DEVICE_TYPE = 0;
WEB = 1;
TABLET = 2;
PWA = 3;
}
message BrowserDetails { message BrowserDetails {
string userAgent = 1; string userAgent = 1;
BrowserType browserType = 2; BrowserType browserType = 2;
string OS = 3; string OS = 3;
bool someBool = 6; DeviceType deviceType = 6;
} }
message Device { message Device {

View file

@ -76,7 +76,6 @@ type ActionType int32
const ( const (
ActionType_UNSPECIFIED ActionType = 0 ActionType_UNSPECIFIED ActionType = 0
ActionType_LIST_CONVERSATIONS ActionType = 1 ActionType_LIST_CONVERSATIONS ActionType = 1
ActionType_LIST_CONVERSATIONS_SYNC ActionType = 1111 // fake value
ActionType_LIST_MESSAGES ActionType = 2 ActionType_LIST_MESSAGES ActionType = 2
ActionType_SEND_MESSAGE ActionType = 3 ActionType_SEND_MESSAGE ActionType = 3
ActionType_MESSAGE_UPDATES ActionType = 4 ActionType_MESSAGE_UPDATES ActionType = 4
@ -127,7 +126,6 @@ var (
ActionType_name = map[int32]string{ ActionType_name = map[int32]string{
0: "UNSPECIFIED", 0: "UNSPECIFIED",
1: "LIST_CONVERSATIONS", 1: "LIST_CONVERSATIONS",
1111: "LIST_CONVERSATIONS_SYNC",
2: "LIST_MESSAGES", 2: "LIST_MESSAGES",
3: "SEND_MESSAGE", 3: "SEND_MESSAGE",
4: "MESSAGE_UPDATES", 4: "MESSAGE_UPDATES",
@ -175,7 +173,6 @@ var (
ActionType_value = map[string]int32{ ActionType_value = map[string]int32{
"UNSPECIFIED": 0, "UNSPECIFIED": 0,
"LIST_CONVERSATIONS": 1, "LIST_CONVERSATIONS": 1,
"LIST_CONVERSATIONS_SYNC": 1111,
"LIST_MESSAGES": 2, "LIST_MESSAGES": 2,
"SEND_MESSAGE": 3, "SEND_MESSAGE": 3,
"MESSAGE_UPDATES": 4, "MESSAGE_UPDATES": 4,

Binary file not shown.

View file

@ -7,7 +7,7 @@ import (
var ConfigMessage = &gmproto.ConfigVersion{ var ConfigMessage = &gmproto.ConfigVersion{
Year: 2023, Year: 2023,
Month: 8, Month: 8,
Day: 10, Day: 17,
V1: 4, V1: 4,
V2: 6, V2: 6,
} }
@ -16,5 +16,5 @@ var BrowserDetailsMessage = &gmproto.BrowserDetails{
UserAgent: UserAgent, UserAgent: UserAgent,
BrowserType: gmproto.BrowserType_OTHER, BrowserType: gmproto.BrowserType_OTHER,
OS: "libgm", OS: "libgm",
SomeBool: true, DeviceType: gmproto.DeviceType_TABLET,
} }

View file

@ -73,6 +73,12 @@ func (br *GMBridge) Init() {
} else { } else {
util.BrowserDetailsMessage.BrowserType = gmproto.BrowserType(browserVal) util.BrowserDetailsMessage.BrowserType = gmproto.BrowserType(browserVal)
} }
deviceVal, ok := gmproto.DeviceType_value[br.Config.GoogleMessages.Device]
if !ok {
br.ZLog.Error().Str("device_value", br.Config.GoogleMessages.Device).Msg("Invalid device value")
} else {
util.BrowserDetailsMessage.DeviceType = gmproto.DeviceType(deviceVal)
}
Segment.log = br.ZLog.With().Str("component", "segment").Logger() Segment.log = br.ZLog.With().Str("component", "segment").Logger()
Segment.key = br.Config.SegmentKey Segment.key = br.Config.SegmentKey