Skip to content

Use all your internet connections at once on Windows, macOS, Linux and Android: per-connection load balancing over Wi-Fi, Ethernet, mobile data and phone tethers

Tray: show the version and a newer release in the menu (#42)

E4crypt3dc90c560d1cdc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 452f639..a98b974 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ entry here before pushing a version tag.
## [Unreleased]
+### Added
+- **The tray menu shows the version** you are running (like `v0.3.3`), on the line above *Quit*, so a
+ bug report has it without opening a terminal. It also asks GitHub for the newest release, at start and
+ then every 6 hours, and turns into *Update to v0.3.4* when there is one; click it to open the release
+ page.
+
## [0.3.3] - 2026-10-20
### Added
diff --git a/README.md b/README.md
index 2e3d2fa..f0a6d83 100644
--- a/README.md
+++ b/README.md
@@ -323,7 +323,10 @@ net-merge when you do not want that.
`net-merge tray -auto-pause=false`.
4. **Hover** the icon to see the speed of each connection and the total.
5. **Right-click** the icon (on Mac, click it) to open the menu. It shows each connection's speed, how
- many connections net-merge gave it, and the buttons *Pause merging* / *Start merging* and *Quit*.
+ many connections net-merge gave it, and the buttons *Pause merging* / *Start merging* and *Quit*. The
+ line above *Quit* is the version you are running, like `v0.3.3`. It reads the newest release number
+ from GitHub (at start, and again every 6 hours) and turns into *Update to v0.3.4* if there is one;
+ click it to open the release page.
6. To start it at sign-in: tick *Start at sign-in* in the menu (or the box in the Windows installer, or run
`net-merge autostart on`). On a Mac this needs `sudo net-merge install` once.
diff --git a/cmd/net-merge/tray.go b/cmd/net-merge/tray.go
index 3a3c56e..100451d 100644
--- a/cmd/net-merge/tray.go
+++ b/cmd/net-merge/tray.go
@@ -89,5 +89,5 @@ func cmdTray(args []string) {
state.Clear(c.stateDir)
os.Exit(0)
}()
- tray.Run(t, sched, bal, c.stateDir, !*startOff, *autoPause, ready)
+ tray.Run(t, sched, bal, c.stateDir, version, !*startOff, *autoPause, ready)
}
diff --git a/internal/platform/platform_darwin.go b/internal/platform/platform_darwin.go
index 8d6da06..baa619a 100644
--- a/internal/platform/platform_darwin.go
+++ b/internal/platform/platform_darwin.go
@@ -130,3 +130,19 @@ func CheckDriver() error { return nil }
// WaitForTray is a no-op: the menu bar exists as soon as the login session does.
func WaitForTray(max time.Duration) bool { return true }
+
+// OpenURL shows url in the default browser. The tray runs as root (see autostart_darwin.go), and root
+// has no GUI session of its own, so when sudo tells us who signed in, hand the URL to that user.
+func OpenURL(url string) error {
+ if u, err := signInUser(); err == nil {
+ if exec.Command("/bin/launchctl", "asuser", u.Uid, "open", url).Run() == nil {
+ return nil
+ }
+ }
+ cmd := exec.Command("open", url)
+ if err := cmd.Start(); err != nil {
+ return err
+ }
+ go cmd.Wait()
+ return nil
+}
diff --git a/internal/platform/platform_linux.go b/internal/platform/platform_linux.go
index e3d5f27..194042e 100644
--- a/internal/platform/platform_linux.go
+++ b/internal/platform/platform_linux.go
@@ -136,3 +136,13 @@ func CheckDriver() error {
// WaitForTray is a no-op on Linux: the tray library registers with the desktop's
// StatusNotifierWatcher over D-Bus whenever it is available.
func WaitForTray(max time.Duration) bool { return true }
+
+// OpenURL shows url in the default browser.
+func OpenURL(url string) error {
+ cmd := exec.Command("xdg-open", url)
+ if err := cmd.Start(); err != nil {
+ return err
+ }
+ go cmd.Wait()
+ return nil
+}
diff --git a/internal/platform/platform_windows.go b/internal/platform/platform_windows.go
index dc1fa16..f8199b7 100644
--- a/internal/platform/platform_windows.go
+++ b/internal/platform/platform_windows.go
@@ -3,8 +3,10 @@ package platform
import (
"log"
"os"
+ "os/exec"
"path/filepath"
"strings"
+ "syscall"
"golang.org/x/sys/windows"
)
@@ -61,3 +63,20 @@ func RelaunchElevated(args []string, hidden bool) error {
}
return windows.ShellExecute(0, verb, file, params, dir, show)
}
+
+// OpenURL shows url in the default browser. explorer.exe hands it to the shell, which runs as the
+// signed-in user: the tray is elevated, and a browser started from there would be elevated too and
+// could not reach the browser that is already open. DETACHED_PROCESS keeps it off our console, which
+// would otherwise make a console window appear next to the tray.
+func OpenURL(url string) error {
+ cmd := exec.Command("explorer.exe", url)
+ cmd.SysProcAttr = &syscall.SysProcAttr{
+ HideWindow: true,
+ CreationFlags: windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP,
+ }
+ if err := cmd.Start(); err != nil {
+ return err
+ }
+ go cmd.Wait() // explorer exits at once, but reap it either way
+ return nil
+}
diff --git a/internal/tray/tray.go b/internal/tray/tray.go
index 08e12d1..b029cfb 100644
--- a/internal/tray/tray.go
+++ b/internal/tray/tray.go
@@ -16,14 +16,15 @@ import (
"net-merge/internal/platform"
"net-merge/internal/state"
"net-merge/internal/tun"
+ "net-merge/internal/update"
)
const trayRows = 4 // adapters shown in the menu; extra rows stay hidden
// Run shows the tray icon and blocks until Quit, and closes ready once the icon exists. With
// startOn it merges as soon as it can (at once, or, with autoPause, once two connections work).
-func Run(t *tun.Tun, sched *engine.Scheduler, bal *engine.Balancer, stateDir string, startOn, autoPause bool, ready chan struct{}) {
- ui := &trayUI{tun: t, sched: sched, bal: bal, stateDir: stateDir, startOn: startOn,
+func Run(t *tun.Tun, sched *engine.Scheduler, bal *engine.Balancer, stateDir, version string, startOn, autoPause bool, ready chan struct{}) {
+ ui := &trayUI{tun: t, sched: sched, bal: bal, stateDir: stateDir, version: version, startOn: startOn,
iconOn: icon.Tray(true), iconOff: icon.Tray(false), ready: ready}
ui.ap.enabled = autoPause
exit := func() { t.Close(); state.Clear(stateDir) }
@@ -36,6 +37,7 @@ type trayUI struct {
bal *engine.Balancer
sched *engine.Scheduler
stateDir string
+ version string
startOn bool
iconOn []byte
iconOff []byte
@@ -44,6 +46,7 @@ type trayUI struct {
ap autoPauser
header, toggleItem, v6Item, autoItem, signInItem *systray.MenuItem
+ versionItem *systray.MenuItem
rows []*systray.MenuItem
lastOn *bool
lastHeader string
@@ -73,7 +76,9 @@ func (u *trayUI) onReady() {
u.autoItem = systray.AddMenuItemCheckbox("Pause when there is only one connection", "Pauses merging by itself when fewer than two connections have internet, and starts it again when a second one works. Pausing or starting by hand always wins.", u.ap.enabled)
u.signInItem = systray.AddMenuItemCheckbox("Start at sign-in", "Starts net-merge when you sign in, with no password or admin prompt.", platform.AutostartEnabled())
u.toggleItem = systray.AddMenuItem("Start merging", "")
+ u.versionItem = systray.AddMenuItem(versionLabel(u.version), "The version of net-merge that is running (the same as net-merge version). Click to open the release page on GitHub.")
quit := systray.AddMenuItem("Quit", "Turns system-wide mode off and exits")
+ go u.watchUpdates()
go func() {
u.ap.start(u.startOn)
@@ -121,6 +126,10 @@ func (u *trayUI) onReady() {
u.v6Item.Check()
u.bal.SetV6Mode(engine.V6Auto)
}
+ case <-u.versionItem.ClickedCh:
+ if err := platform.OpenURL(update.ReleasesURL); err != nil {
+ logx.Printf("error: opening the release page: %v\n", err)
+ }
case <-quit.ClickedCh:
systray.Quit()
return
@@ -281,6 +290,26 @@ func stateWord(on bool) string {
return "Paused"
}
+// versionLabel is the line above Quit, so a bug report has the version without a terminal.
+// Release builds pass "0.3.3" and get "v0.3.3"; a build from source says "dev".
+func versionLabel(v string) string {
+ if v = strings.TrimSpace(v); v == "" {
+ v = "dev"
+ }
+ return withV(v)
+}
+
+// updateLabel replaces the version line once GitHub has a newer release.
+func updateLabel(latest string) string { return "Update to " + withV(latest) }
+
+// withV adds the "v" that releases are tagged with, unless the build says "dev" or has one already.
+func withV(v string) string {
+ if v == "" || v == "dev" || strings.HasPrefix(v, "v") {
+ return v
+ }
+ return "v" + v
+}
+
// trayTooltip lists each adapter's speed and a Total line, e.g.
//
// Merging
diff --git a/internal/tray/tray_test.go b/internal/tray/tray_test.go
index 9631344..b2832c0 100644
--- a/internal/tray/tray_test.go
+++ b/internal/tray/tray_test.go
@@ -23,6 +23,30 @@ func TestShortenCountsUTF16AndKeepsRunesWhole(t *testing.T) {
}
}
+func TestVersionLabel(t *testing.T) {
+ for _, c := range []struct{ in, want string }{
+ {"0.3.3", "v0.3.3"},
+ {"v0.3.3", "v0.3.3"}, // already prefixed: do not double it
+ {"dev", "dev"},
+ {"", "dev"}, // a build without -X main.version
+ } {
+ if got := versionLabel(c.in); got != c.want {
+ t.Errorf("versionLabel(%q) = %q, want %q", c.in, got, c.want)
+ }
+ }
+}
+
+func TestUpdateLabel(t *testing.T) {
+ for _, c := range []struct{ in, want string }{
+ {"v0.3.4", "Update to v0.3.4"},
+ {"0.3.4", "Update to v0.3.4"}, // GitHub tags start with v, but do not depend on it
+ } {
+ if got := updateLabel(c.in); got != c.want {
+ t.Errorf("updateLabel(%q) = %q, want %q", c.in, got, c.want)
+ }
+ }
+}
+
func TestTrayTooltipFitsWindowsLimit(t *testing.T) {
const mbit = 125_000
mk := func(name string, down, up float64) engine.SlotStats {
diff --git a/internal/tray/update.go b/internal/tray/update.go
new file mode 100644
index 0000000..6be129c
--- /dev/null
+++ b/internal/tray/update.go
@@ -0,0 +1,58 @@
+package tray
+
+import (
+ "context"
+ "time"
+
+ "net-merge/internal/logx"
+ "net-merge/internal/update"
+)
+
+// updateEvery is how often the tray asks GitHub for a newer release. Releases are rare and GitHub
+// rate-limits anonymous requests, so this is deliberately slow.
+const updateEvery = 6 * time.Hour
+
+// updateRetry is the first wait after a failed check. Started at sign-in the network is often not up
+// yet, so a failure must not hide an update for six hours. It doubles per failure up to updateMax.
+const (
+ updateRetry = 2 * time.Minute
+ updateMax = 30 * time.Minute
+)
+
+// watchUpdates turns the version line into "Update to vX" when GitHub has a newer release. It stays
+// quiet when offline: the check is a convenience, not something to warn about.
+func (u *trayUI) watchUpdates() {
+ if !update.IsVersion(u.version) { // a build from source says "dev": nothing to compare
+ return
+ }
+ retry := updateRetry
+ for {
+ latest, err := latestRelease()
+ if err != nil {
+ logx.Printf("update check: %v (next try in %s)\n", err, retry)
+ time.Sleep(retry)
+ retry = min(2*retry, updateMax)
+ continue
+ }
+ if update.Newer(u.version, latest) {
+ u.showUpdate(latest)
+ }
+ retry = updateRetry // a success means the network works again
+ time.Sleep(updateEvery)
+ }
+}
+
+// latestRelease asks GitHub with a deadline: the tray must never wait on the network.
+func latestRelease() (string, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ return update.Latest(ctx)
+}
+
+// showUpdate keeps the version in the tooltip, so a bug report still has it.
+func (u *trayUI) showUpdate(latest string) {
+ logx.Printf("update check: %s is available\n", latest)
+ u.versionItem.SetTitle(updateLabel(latest))
+ u.versionItem.SetTooltip("You are running " + versionLabel(u.version) +
+ ". Click to open the " + versionLabel(latest) + " release page on GitHub.")
+}
diff --git a/internal/update/update.go b/internal/update/update.go
new file mode 100644
index 0000000..331d801
--- /dev/null
+++ b/internal/update/update.go
@@ -0,0 +1,104 @@
+// Package update asks GitHub for the newest release, so the tray menu can point at a newer version.
+package update
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "strconv"
+ "strings"
+ "time"
+)
+
+// Repo is where releases are read from.
+const Repo = "rohit267/net-merge"
+
+// ReleasesURL is what the tray opens: GitHub redirects it to the newest release.
+const ReleasesURL = "https://github.com/" + Repo + "/releases/latest"
+
+var (
+ client = &http.Client{Timeout: 8 * time.Second}
+ apiBase = "https://api.github.com" // tests point this at a local server
+)
+
+// Latest returns the tag of the newest release, e.g. "v0.3.4". GitHub leaves out prereleases.
+func Latest(ctx context.Context) (string, error) {
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiBase+"/repos/"+Repo+"/releases/latest", nil)
+ if err != nil {
+ return "", err
+ }
+ req.Header.Set("Accept", "application/vnd.github+json")
+ req.Header.Set("User-Agent", "net-merge")
+ resp, err := client.Do(req)
+ if err != nil {
+ return "", err
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ return "", fmt.Errorf("github: %s", resp.Status)
+ }
+ var rel struct {
+ TagName string `json:"tag_name"`
+ }
+ // A release carries its notes, so the reply can be tens of kB; the limit only guards against a
+ // wrong server answering.
+ if err := json.NewDecoder(io.LimitReader(resp.Body, 1<<20)).Decode(&rel); err != nil {
+ return "", err
+ }
+ if rel.TagName == "" {
+ return "", fmt.Errorf("github: no tag_name in the release")
+ }
+ return rel.TagName, nil
+}
+
+// IsVersion reports whether v starts with a version number ("0.3.3", "0.3.3-dev", "v1.2").
+// A build from source says "dev", which is not one.
+func IsVersion(v string) bool {
+ _, ok := numbers(v)
+ return ok
+}
+
+// Newer reports whether release tag latest is newer than current. Anything after the number is
+// ignored, so a dev build of 0.3.3 still hears about 0.3.4.
+func Newer(current, latest string) bool {
+ c, ok := numbers(current)
+ if !ok {
+ return false
+ }
+ l, ok := numbers(latest)
+ if !ok {
+ return false
+ }
+ for i := range c {
+ if c[i] != l[i] {
+ return l[i] > c[i]
+ }
+ }
+ return false
+}
+
+// numbers reads the leading dotted numbers, up to three: "v0.3.3-dev+1" -> 0.3.3.
+func numbers(v string) ([3]int, bool) {
+ v = strings.TrimPrefix(strings.TrimSpace(v), "v")
+ var out [3]int
+ n := 0
+ for n < len(out) {
+ i := 0
+ for i < len(v) && v[i] >= '0' && v[i] <= '9' {
+ i++
+ }
+ if i == 0 {
+ break
+ }
+ x, err := strconv.Atoi(v[:i])
+ if err != nil {
+ return out, false
+ }
+ out[n] = x
+ n++
+ v = strings.TrimPrefix(v[i:], ".")
+ }
+ return out, n > 0
+}
diff --git a/internal/update/update_test.go b/internal/update/update_test.go
new file mode 100644
index 0000000..353f689
--- /dev/null
+++ b/internal/update/update_test.go
@@ -0,0 +1,106 @@
+package update
+
+import (
+ "context"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestNewer(t *testing.T) {
+ for _, c := range []struct {
+ current, latest string
+ want bool
+ }{
+ {"0.3.3", "v0.3.4", true},
+ {"v0.3.3", "v0.3.4", true},
+ {"0.3.3", "v0.3.3", false},
+ {"0.3.4", "v0.3.3", false},
+ {"0.3.10", "v0.3.9", false}, // numbers, not text
+ {"0.9.9", "v0.10.0", true},
+ {"0.3", "v0.3.0", false}, // missing numbers count as zero
+ {"0.3.3-dev+abc", "v0.3.4", true},
+ {"0.3.3", "v0.3.4-rc1", true}, // GitHub leaves prereleases out, but be able to read one
+ {"dev", "v0.3.4", false}, // a build from source has nothing to compare
+ {"0.3.3", "dev", false},
+ } {
+ if got := Newer(c.current, c.latest); got != c.want {
+ t.Errorf("Newer(%q, %q) = %v, want %v", c.current, c.latest, got, c.want)
+ }
+ }
+}
+
+func TestIsVersion(t *testing.T) {
+ for v, want := range map[string]bool{
+ "0.3.3": true,
+ "v1.2": true,
+ "0.3.3-dev+menu": true,
+ "dev": false,
+ "": false,
+ } {
+ if got := IsVersion(v); got != want {
+ t.Errorf("IsVersion(%q) = %v, want %v", v, got, want)
+ }
+ }
+}
+
+func TestLatestReadsTheTagAndIdentifiesItself(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/repos/"+Repo+"/releases/latest" {
+ t.Errorf("asked for %q", r.URL.Path)
+ }
+ if r.Header.Get("User-Agent") == "" {
+ t.Error("GitHub wants a User-Agent")
+ }
+ io.WriteString(w, `{"tag_name":"v0.3.4"}`)
+ }))
+ defer srv.Close()
+ old := apiBase
+ apiBase = srv.URL
+ defer func() { apiBase = old }()
+
+ tag, err := Latest(context.Background())
+ if err != nil {
+ t.Fatalf("Latest: %v", err)
+ }
+ if tag != "v0.3.4" {
+ t.Fatalf("Latest = %q, want v0.3.4", tag)
+ }
+}
+
+func TestLatestHandlesABigReleaseBody(t *testing.T) {
+ // A release carries its notes: the reply can be far bigger than the tag we want.
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ io.WriteString(w, `{"tag_name":"v0.3.4","body":"`)
+ io.WriteString(w, strings.Repeat("x", 200<<10))
+ io.WriteString(w, `"}`)
+ }))
+ defer srv.Close()
+ old := apiBase
+ apiBase = srv.URL
+ defer func() { apiBase = old }()
+
+ tag, err := Latest(context.Background())
+ if err != nil {
+ t.Fatalf("Latest with long release notes: %v", err)
+ }
+ if tag != "v0.3.4" {
+ t.Fatalf("Latest = %q, want v0.3.4", tag)
+ }
+}
+
+func TestLatestFailsLoudly(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "rate limited", http.StatusForbidden)
+ }))
+ defer srv.Close()
+ old := apiBase
+ apiBase = srv.URL
+ defer func() { apiBase = old }()
+
+ if _, err := Latest(context.Background()); err == nil {
+ t.Fatal("a 403 must be an error, not an empty tag")
+ }
+}