]> git.giacomolli.uk - onechat/commitdiff
Show the linked device as OneChat on the phone
authorAnderson A. Giacomolli <agiacomolli@gmail.com>
Sun, 8 Nov 2026 22:21:11 +0000 (19:21 -0300)
committerAnderson A. Giacomolli <agiacomolli@gmail.com>
Sun, 8 Nov 2026 23:15:49 +0000 (20:15 -0300)
The daemon sets the device properties of the library once before any
client exists, because they are global values of the library. The
properties have the OS name OneChat and the desktop platform type.
Without a known platform type, the phone ignores the name and shows the
device as "Other device".

The display name of the phone code pairing stays "Chrome (Linux)": the
server accepts only the form "Browser (OS)" with a common browser and
OS, and refuses the pairing otherwise. A comment says so.

The name applies at the pairing, so an existing link keeps its old name
until the user unlinks and pairs again.

README.rst
daemon.go
whatsapp.go

index 34d0d4966bfc487811f568e61ce9b7fcf3f9adf1..93be7846e95dbf24831375cf43c8d2e3a9817d04 100644 (file)
@@ -186,7 +186,10 @@ device. The terminal client and Telegram take three commands:
    Linked devices, tap Link a device, then tap Link with phone number
    instead, and enter the code. The code expires in about 2 minutes, and
    the same command gives a new code. When the link succeeds, the daemon
    Linked devices, tap Link a device, then tap Link with phone number
    instead, and enter the code. The code expires in about 2 minutes, and
    the same command gives a new code. When the link succeeds, the daemon
-   answers with the linked number.
+   answers with the linked number. Linked devices on the phone shows the
+   device as OneChat. The name applies at the pairing, so an existing
+   link keeps its old name until ``/whatsapp unlink`` and a new
+   ``/whatsapp pair PHONE``.
 
 ``/whatsapp status``
    Shows the link: not linked, linked and connected, or linked and
 
 ``/whatsapp status``
    Shows the link: not linked, linked and connected, or linked and
index 1366870a6322273239e959cd40747301af2ab891..ca3d5abc27598ca815ec1926e462dc04fc589d7b 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -63,6 +63,7 @@ func daemon(ctx context.Context, out io.Writer) (err error) {
                err = errors.Join(err, tokens.Close())
        }()
 
                err = errors.Join(err, tokens.Close())
        }()
 
+       whatsappSetDeviceProps()
        whatsapp, err := openWhatsApp(ctx, dir, time.Now, log.New(out, "whatsapp: ", log.LstdFlags), whatsappNewClient)
        if err != nil {
                return err
        whatsapp, err := openWhatsApp(ctx, dir, time.Now, log.New(out, "whatsapp: ", log.LstdFlags), whatsappNewClient)
        if err != nil {
                return err
index b883496aea73266c0ce87889c9e1d9895b25335a..75de73f96c57b25fb717bde9189103e5518b3937 100644 (file)
@@ -14,6 +14,7 @@ import (
        "time"
 
        "go.mau.fi/whatsmeow"
        "time"
 
        "go.mau.fi/whatsmeow"
+       "go.mau.fi/whatsmeow/proto/waCompanionReg"
        "go.mau.fi/whatsmeow/proto/waE2E"
        "go.mau.fi/whatsmeow/store"
        "go.mau.fi/whatsmeow/store/sqlstore"
        "go.mau.fi/whatsmeow/proto/waE2E"
        "go.mau.fi/whatsmeow/store"
        "go.mau.fi/whatsmeow/store/sqlstore"
@@ -594,6 +595,8 @@ func (w *WhatsApp) pair(ctx, runCtx context.Context, l *TurnLoop, phone string,
                return
        }
 
                return
        }
 
+       // The server accepts only a display name of the form "Browser (OS)"
+       // with a common browser and OS, and refuses the pairing otherwise.
        code, err := client.PairPhone(ctx, phone, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
        if err != nil {
                answer("WhatsApp refused the pairing: " + err.Error() + ". Check the phone number and run /whatsapp pair PHONE again.")
        code, err := client.PairPhone(ctx, phone, true, whatsmeow.PairClientChrome, "Chrome (Linux)")
        if err != nil {
                answer("WhatsApp refused the pairing: " + err.Error() + ". Check the phone number and run /whatsapp pair PHONE again.")
@@ -817,12 +820,20 @@ type WhatsAppRequest struct {
        answer func(text string)
 }
 
        answer func(text string)
 }
 
+// whatsappSetDeviceProps sets the device properties that the library sends at
+// the pairing. They are global values of the library, so the daemon sets them
+// once before any client exists. The phone shows the linked device with the
+// name OneChat and a desktop icon only when the platform type is known.
+func whatsappSetDeviceProps() {
+       store.SetOSInfo("OneChat", [3]uint32{0, 1, 0})
+       store.DeviceProps.PlatformType = waCompanionReg.DeviceProps_DESKTOP.Enum()
+}
+
 // whatsappNewClient returns the client of the library for device, with handle
 // as its event handler. The client tries again after a failed first connection,
 // acknowledges a message only after handle returns true, and downloads no old
 // whatsappNewClient returns the client of the library for device, with handle
 // as its event handler. The client tries again after a failed first connection,
 // acknowledges a message only after handle returns true, and downloads no old
-// history. The phone shows the device with the name OneChat.
+// history.
 func whatsappNewClient(device *store.Device, handle func(event any) bool) WhatsAppClient {
 func whatsappNewClient(device *store.Device, handle func(event any) bool) WhatsAppClient {
-       store.SetOSInfo("OneChat", [3]uint32{0, 1, 0})
        client := whatsmeow.NewClient(device, waLog.Noop)
        client.InitialAutoReconnect = true
        client.SynchronousAck = true
        client := whatsmeow.NewClient(device, waLog.Noop)
        client.InitialAutoReconnect = true
        client.SynchronousAck = true