diff --git a/config/upgrade.go b/config/upgrade.go index 11edb5f..60a7a76 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -105,6 +105,7 @@ var SpacedBlocks = [][]string{ {"appservice", "as_token"}, {"segment_key"}, {"metrics"}, + {"google_messages"}, {"bridge"}, {"bridge", "command_prefix"}, {"bridge", "management_room_text"}, diff --git a/example-config.yaml b/example-config.yaml index 2092473..3485976 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -90,10 +90,10 @@ metrics: google_messages: # OS name to tell the phone. This is the name that shows up in the paired devices list. - os: mautrix-gmessages + os: Android (mautrix) # Browser type to tell the phone. This decides which icon is shown. # Valid types: OTHER, CHROME, FIREFOX, SAFARI, OPERA, IE, EDGE - browser: OTHER + browser: CHROME # 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 diff --git a/libgm/util/constants.go b/libgm/util/constants.go index 8f33680..0cb81e3 100644 --- a/libgm/util/constants.go +++ b/libgm/util/constants.go @@ -1,8 +1,9 @@ package util const GoogleAPIKey = "AIzaSyCA4RsOZUFrm9whhtGosPlJLmVPnfSHKz8" -const UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" +const UserAgent = "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36" const SecUA = `"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"` -const UAPlatform = "Linux" +const UAPlatform = "Android" const XUserAgent = "grpc-web-javascript/0.1" const QRCodeURLBase = "https://support.google.com/messages/?p=web_computer#?c=" +const SecUAMobile = "?1" diff --git a/libgm/util/func.go b/libgm/util/func.go index 0b98181..9b0c8e3 100644 --- a/libgm/util/func.go +++ b/libgm/util/func.go @@ -27,7 +27,7 @@ func BuildRelayHeaders(req *http.Request, contentType string, accept string) { if len(contentType) > 0 { req.Header.Add("content-type", contentType) } - req.Header.Add("sec-ch-ua-mobile", "?0") + req.Header.Add("sec-ch-ua-mobile", SecUAMobile) req.Header.Add("user-agent", UserAgent) req.Header.Add("sec-ch-ua-platform", "\""+UAPlatform+"\"") req.Header.Add("accept", accept) @@ -44,7 +44,7 @@ func BuildUploadHeaders(req *http.Request, metadata string) { req.Header.Add("connection", "keep-alive") req.Header.Add("x-goog-download-metadata", metadata) req.Header.Add("sec-ch-ua", SecUA) - req.Header.Add("sec-ch-ua-mobile", "?0") + req.Header.Add("sec-ch-ua-mobile", SecUAMobile) req.Header.Add("user-agent", UserAgent) req.Header.Add("sec-ch-ua-platform", "\""+UAPlatform+"\"") req.Header.Add("accept", "*/*") @@ -67,7 +67,7 @@ func NewMediaUploadHeaders(imageSize string, command string, uploadOffset string headers.Add("x-goog-upload-protocol", protocol) } headers.Add("x-goog-upload-header-content-length", imageSize) - headers.Add("sec-ch-ua-mobile", "?0") + headers.Add("sec-ch-ua-mobile", SecUAMobile) headers.Add("user-agent", UserAgent) if imageContentType != "" { headers.Add("x-goog-upload-header-content-type", imageContentType) diff --git a/user.go b/user.go index b2a201e..9aa7172 100644 --- a/user.go +++ b/user.go @@ -397,7 +397,7 @@ func (user *User) Login(maxAttempts int) (<-chan qrChannelItem, error) { user.createClient(libgm.NewAuthData()) qr, err := user.Client.StartLogin() if err != nil { - user.DeleteConnection() + user.unlockedDeleteConnection() user.pairSuccessChan = nil user.loginInProgress.Store(false) return nil, fmt.Errorf("failed to connect to Google Messages: %w", err)