Skip to content

Commit 59cfb6c

Browse files
committed
pair: update PairClientType to a string
1 parent 876de1e commit 59cfb6c

2 files changed

Lines changed: 38 additions & 36 deletions

File tree

pair-code.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ import (
2929

3030
// PairClientType is the type of client to use with PairCode.
3131
// The type is automatically filled based on store.DeviceProps.PlatformType (which is what QR login uses).
32-
type PairClientType int
32+
type PairClientType string
3333

3434
const (
35-
PairClientUnknown PairClientType = iota
36-
PairClientChrome
37-
PairClientEdge
38-
PairClientFirefox
39-
PairClientIE
40-
PairClientOpera
41-
PairClientSafari
42-
PairClientElectron
43-
PairClientUWP
44-
PairClientOtherWebClient
35+
PairClientUnknown PairClientType = "0"
36+
PairClientChrome PairClientType = "1"
37+
PairClientEdge PairClientType = "2"
38+
PairClientFirefox PairClientType = "3"
39+
PairClientIE PairClientType = "4"
40+
PairClientOpera PairClientType = "5"
41+
PairClientSafari PairClientType = "6"
42+
PairClientElectron PairClientType = "7"
43+
PairClientUWP PairClientType = "8"
44+
PairClientOtherWebClient PairClientType = "9"
45+
PairClientAndroid PairClientType = "e"
4546
)
4647

4748
var notNumbers = regexp.MustCompile("[^0-9]")
@@ -114,7 +115,7 @@ func (cli *Client) PairPhone(ctx context.Context, phone string, showPushNotifica
114115
Content: []waBinary.Node{
115116
{Tag: "link_code_pairing_wrapped_companion_ephemeral_pub", Content: ephemeralKey},
116117
{Tag: "companion_server_auth_key_pub", Content: cli.Store.NoiseKey.Pub[:]},
117-
{Tag: "companion_platform_id", Content: strconv.Itoa(int(clientType))},
118+
{Tag: "companion_platform_id", Content: clientType},
118119
{Tag: "companion_platform_display", Content: clientDisplayName},
119120
{Tag: "link_code_pairing_nonce", Content: []byte{0}},
120121
},

pair.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,39 @@ func (cli *Client) handlePairDevice(ctx context.Context, node *waBinary.Node) {
8080
}
8181

8282
func (cli *Client) getQRClientType() PairClientType {
83-
if cli.QRClientType == PairClientUnknown {
84-
switch store.DeviceProps.GetPlatformType() {
85-
case waCompanionReg.DeviceProps_CHROME:
86-
return PairClientChrome
87-
case waCompanionReg.DeviceProps_FIREFOX:
88-
return PairClientFirefox
89-
case waCompanionReg.DeviceProps_EDGE:
90-
return PairClientEdge
91-
case waCompanionReg.DeviceProps_IE:
92-
return PairClientIE
93-
case waCompanionReg.DeviceProps_OPERA:
94-
return PairClientOpera
95-
case waCompanionReg.DeviceProps_SAFARI:
96-
return PairClientSafari
97-
case waCompanionReg.DeviceProps_UWP:
98-
return PairClientUWP
99-
default:
100-
if store.BaseClientPayload.WebInfo != nil &&
101-
store.BaseClientPayload.WebInfo.WebSubPlatform != nil &&
102-
store.BaseClientPayload.WebInfo.GetWebSubPlatform() == waWa6.ClientPayload_WebInfo_WEB_BROWSER {
103-
return PairClientOtherWebClient
104-
}
83+
if cli.QRClientType != "" {
84+
return cli.QRClientType
85+
}
86+
switch store.DeviceProps.GetPlatformType() {
87+
case waCompanionReg.DeviceProps_CHROME:
88+
return PairClientChrome
89+
case waCompanionReg.DeviceProps_FIREFOX:
90+
return PairClientFirefox
91+
case waCompanionReg.DeviceProps_EDGE:
92+
return PairClientEdge
93+
case waCompanionReg.DeviceProps_IE:
94+
return PairClientIE
95+
case waCompanionReg.DeviceProps_OPERA:
96+
return PairClientOpera
97+
case waCompanionReg.DeviceProps_SAFARI:
98+
return PairClientSafari
99+
case waCompanionReg.DeviceProps_UWP:
100+
return PairClientUWP
101+
case waCompanionReg.DeviceProps_ANDROID_PHONE:
102+
return PairClientAndroid
103+
default:
104+
if store.BaseClientPayload.UserAgent.GetPlatform() == waWa6.ClientPayload_UserAgent_WEB {
105+
return PairClientOtherWebClient
105106
}
107+
return PairClientUnknown
106108
}
107-
return cli.QRClientType
108109
}
109110

110111
func (cli *Client) makeQRData(ref []byte, clientType PairClientType) string {
111112
noise := base64.StdEncoding.EncodeToString(cli.Store.NoiseKey.Pub[:])
112113
identity := base64.StdEncoding.EncodeToString(cli.Store.IdentityKey.Pub[:])
113114
adv := base64.StdEncoding.EncodeToString(cli.Store.AdvSecretKey)
114-
return fmt.Sprintf("https://wa.me/settings/linked_devices#%s,%s,%s,%s,%d", ref, noise, identity, adv, clientType)
115+
return fmt.Sprintf("https://wa.me/settings/linked_devices#%s,%s,%s,%s,%s", ref, noise, identity, adv, clientType)
115116
}
116117

117118
func (cli *Client) handlePairSuccess(ctx context.Context, node *waBinary.Node) {

0 commit comments

Comments
 (0)