- Go 77.3%
- Shell 16.4%
- HTML 6.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
- packaging/icons: SVG source (favicon geometry: dark rounded tile, three amber bars) rendered to 32px tray PNG and 128px launcher icon - PKGBUILD installs both hicolor sizes - README: layout map, test lane, icon, changelog link - CHANGELOG.md: Keep-a-Changelog 0.1.0 entry |
||
| packaging | ||
| .gitignore | ||
| CHANGELOG.md | ||
| desktop.go | ||
| go.mod | ||
| go.sum | ||
| gtk.go | ||
| index.html | ||
| LICENSE | ||
| main.go | ||
| README.md | ||
| runui_stub.go | ||
| server_test.go | ||
| tag_off.go | ||
| tag_on.go | ||
| tray.go | ||
go-webview-hello
The smallest runnable version of the pattern described in "Ship a desktop Linux app as one Go binary": one binary, no Electron, no CGO.
Talk is cheap. This is the code:
- an embedded page (
//go:embedof a single HTML file — no SPA toolchain), - an
http.Serveron the loopback serving it plus one JSON endpoint, - a GTK webview window (
-tags desktop) through glaze / purego over the distro's WebKitGTK, - a tray icon (
fyne.io/systray, plain DBus, no GTK) in the buildr.fun favicon style (SVG source), - the close-button veto: the window's
delete-eventfires before GTK decides to destroy, so "close" hides to tray instead of quitting, - one shutdown funnel (
sync.Once) for window-quit, tray-quit and signals, - a
PKGBUILDwhose version is derived from the git checkout so every commit is a strictly newer package undervercmp.
Layout
main.go shared: embedded page, loopback server, /api/hello JSON
tag_on.go desktopTag = true (only with -tags desktop)
tag_off.go desktopTag = false (plain go build)
runui_stub.go headless stub so one tree compiles both faces
desktop.go desktop face: window, tray, signals, shutdown funnel
gtk.go close-button veto via purego dlopen("libgtk-3.so.0")
tray.go tray menu; GTK effects go through w.Dispatch
index.html the whole "SPA"
packaging/ PKGBUILD, desktop entry, icons (SVG source + rendered PNGs)
Run it
Headless face (server only):
go build -o hello .
./hello
# serving on http://127.0.0.1:NNNNN — Ctrl-C to stop
Desktop face (server + window + tray):
go build -tags desktop -o hello-desktop .
./hello-desktop
Close the window: it hides. Bring it back or quit from the tray icon.
Test it
go test -v . # headless face
go test -v -tags desktop . # desktop face (same suite; the GTK loop itself
# cannot run under go test — that is what the
# packaged check() and a real run are for)
Package it (Arch)
cd packaging && makepkg -f
sudo pacman -U go-webview-hello-*.pkg.tar.zst
check() inside the PKGBUILD runs both vets and both test suites before
anything is packaged. The app shows up in your launcher;
pacman -R go-webview-hello removes every file it ever laid down.
See CHANGELOG.md for what changed and when.
Requirements
Linux, Go ≥ 1.27 to build. At runtime the desktop face needs the system
web stack — webkit2gtk-4.1 gtk3 glib2 dbus — nothing else; the binary
dlopens libgtk-3.so.0 at startup and refuses to run on a GTK4/webkitgtk-6.0
stack (one process, one GTK major version).