fix(desktop): open default browser on startup (#2095)

Fixes #934

## Summary

The Go desktop binary started its local server and printed the URL,
but never opened a browser automatically.

This PR:

- opens the default browser after the listener successfully binds
- uses the actual runtime URL
- uses a stdlib-only cross-platform launcher
- keeps browser-open failures non-fatal
- adds `--no-browser` for headless/Docker use
- leaves the normal Vite/web development flow unchanged

The listener is created before launching the browser so the browser
cannot race the server startup path.

## Platform behavior

- Windows: `rundll32 url.dll,FileProtocolHandler`
- macOS: `open`
- Linux: `xdg-open`

No shell command strings are used; arguments are passed directly through
`exec.Command`.

## Testing

- `go test ./...`
- `go vet ./...`
- `go build ./...`
- `git diff --check`
- repeated manual Windows startup verification (3 clean runs, confirmed
the
  browser opened and hit the server, no duplicate launches)
- `--no-browser` verification (confirmed no launch attempt occurs)
- non-fatal launcher failure covered by a unit test that injects a
  nonexistent opener binary

macOS/Linux launch paths were not runtime-tested on this Windows machine
—
they follow the standard `open`/`xdg-open` convention used across other
Go
CLIs but are unverified here. The full packaged release flow (`gox`,
`go.rice`, `go-winres`) was not exercised locally.
This commit is contained in:
Nitish Reddy M
2026-08-24 00:28:40 -04:00
committed by GitHub
parent 5c1c3fd8cb
commit 29cf3f1a97
4 changed files with 33 additions and 16 deletions
+2 -7
View File
@@ -9,19 +9,14 @@ require (
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/maputnik/desktop v1.0.7
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/urfave/cli v1.22.12
)
require (
github.com/GeertJohan/go.incremental v1.0.0 // indirect
github.com/akavel/rsrc v0.8.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/daaku/go.zipexe v1.0.2 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/jessevdk/go-flags v1.4.0 // indirect
github.com/nkovacs/streamquote v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.0.1 // indirect
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
golang.org/x/sys v0.1.0 // indirect
)