diff --git a/libgm/events/qr.go b/libgm/events/qr.go index c0e1738..68e5712 100644 --- a/libgm/events/qr.go +++ b/libgm/events/qr.go @@ -1,22 +1,5 @@ package events type QRCODE_UPDATED struct { - Image []byte - Height int - Width int - - googleUrl string -} - -func NewQrCodeUpdated(image []byte, height int, width int, googleUrl string) *QRCODE_UPDATED { - return &QRCODE_UPDATED{ - Image: image, - Height: height, - Width: width, - googleUrl: googleUrl, - } -} - -func (q *QRCODE_UPDATED) GetGoogleUrl() string { - return q.googleUrl + URL string } diff --git a/libgm/pair.go b/libgm/pair.go index 999992b..4a43828 100644 --- a/libgm/pair.go +++ b/libgm/pair.go @@ -7,6 +7,7 @@ import ( "go.mau.fi/mautrix-gmessages/libgm/binary" "go.mau.fi/mautrix-gmessages/libgm/crypto" + "go.mau.fi/mautrix-gmessages/libgm/events" "go.mau.fi/mautrix-gmessages/libgm/payload" "go.mau.fi/mautrix-gmessages/libgm/util" ) @@ -16,7 +17,6 @@ type Pairer struct { KeyData *crypto.JWK ticker *time.Ticker tickerTime time.Duration - qrCodePx int pairingKey []byte } @@ -35,17 +35,12 @@ func (c *Client) NewPairer(keyData *crypto.JWK, refreshQrCodeTime int) (*Pairer, p := &Pairer{ client: c, KeyData: keyData, - qrCodePx: 214, tickerTime: time.Duration(refreshQrCodeTime) * time.Second, } c.pairer = p return p, nil } -func (p *Pairer) SetQRCodePx(pixels int) { - p.qrCodePx = pixels -} - func (p *Pairer) RegisterPhoneRelay() (*binary.RegisterPhoneRelayResponse, error) { body, _, err := payload.RegisterPhoneRelay(p.KeyData) if err != nil { @@ -69,11 +64,11 @@ func (p *Pairer) RegisterPhoneRelay() (*binary.RegisterPhoneRelayResponse, error return nil, err3 } p.pairingKey = res.GetPairingKey() - qrCode, qrErr := p.GenerateQRCode(p.qrCodePx) + url, qrErr := p.GenerateQRCodeData() if qrErr != nil { return nil, qrErr } - p.client.triggerEvent(qrCode) + p.client.triggerEvent(&events.QRCODE_UPDATED{URL: url}) p.startRefreshRelayTask() return res, err } @@ -115,11 +110,11 @@ func (p *Pairer) RefreshPhoneRelay() { } p.pairingKey = res.GetPairKey() p.client.Logger.Debug().Any("res", res).Msg("RefreshPhoneRelayResponse") - qrCode, qrErr := p.GenerateQRCode(p.qrCodePx) + url, qrErr := p.GenerateQRCodeData() if qrErr != nil { log.Fatal(qrErr) } - p.client.triggerEvent(qrCode) + p.client.triggerEvent(&events.QRCODE_UPDATED{URL: url}) } func (p *Pairer) GetWebEncryptionKey() { diff --git a/libgm/qr.go b/libgm/qr.go index 9e6ed4f..828ffa7 100644 --- a/libgm/qr.go +++ b/libgm/qr.go @@ -3,10 +3,7 @@ package textgapi import ( "go.mau.fi/mautrix-gmessages/libgm/binary" "go.mau.fi/mautrix-gmessages/libgm/crypto" - "go.mau.fi/mautrix-gmessages/libgm/events" "go.mau.fi/mautrix-gmessages/libgm/util" - - "github.com/skip2/go-qrcode" ) func (p *Pairer) GenerateQRCodeData() (string, error) { @@ -22,15 +19,3 @@ func (p *Pairer) GenerateQRCodeData() (string, error) { cData := crypto.Base64Encode(encodedUrlData) return util.QR_CODE_URL + cData, nil } - -func (p *Pairer) GenerateQRCode(size int) (*events.QRCODE_UPDATED, error) { - data, err1 := p.GenerateQRCodeData() - if err1 != nil { - return nil, err1 - } - png, err2 := qrcode.Encode(data, qrcode.Highest, size) - if err2 != nil { - return nil, err2 - } - return events.NewQrCodeUpdated(png, size, size, data), nil -}