Skip to content

Commit eb354e3

Browse files
hongarcclaude
andcommitted
feat(tray): macOS menu bar icon, and brew services starts it at login
The tray code is shared between Windows and macOS; the platform files hold the icon format, the clipboard and browser commands, and the left-click behaviour. macOS binaries are now built with CGO on a macOS runner. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 9002423 commit eb354e3

10 files changed

Lines changed: 208 additions & 101 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ permissions:
77
contents: write
88

99
jobs:
10-
release:
10+
# Windows and Linux need no C compiler, so they build on Linux.
11+
build-windows-linux:
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: actions/checkout@v4
@@ -29,20 +30,71 @@ jobs:
2930
# so it is published as the bare .exe.
3031
GOOS=windows GOARCH=amd64 go build -ldflags "-H=windowsgui -s -w -X main.version=$v" \
3132
-o dist/dpi-bypass-windows-amd64.exe ./cmd/dpi-bypass
32-
# macOS and Linux binaries are published as .tar.gz: a plain download loses the
33-
# executable bit, an archive keeps it. Each holds the binary and the README.
34-
pack() { # os arch name
35-
d=work/$3; mkdir -p "$d"
36-
GOOS=$1 GOARCH=$2 go build -ldflags "-s -w -X main.version=$v" -o "$d/dpi-bypass" ./cmd/dpi-bypass
33+
# The Linux binary is published as .tar.gz: a plain download loses the
34+
# executable bit, an archive keeps it. It holds the binary and the README.
35+
d=work/dpi-bypass-linux-amd64; mkdir -p "$d"
36+
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=$v" -o "$d/dpi-bypass" ./cmd/dpi-bypass
37+
cp README.md "$d/"
38+
chmod 755 "$d/dpi-bypass"
39+
tar -C work -czf dist/dpi-bypass-linux-amd64.tar.gz dpi-bypass-linux-amd64
40+
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: dist-windows-linux
44+
path: dist/*
45+
46+
# The macOS menu bar icon is Cocoa code, so the macOS binaries are built with CGO
47+
# on a macOS runner (the Intel build is cross-compiled by the same Apple compiler).
48+
build-macos:
49+
runs-on: macos-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- uses: actions/setup-go@v5
53+
with:
54+
go-version-file: go.mod
55+
cache: false
56+
57+
- name: build and package
58+
env:
59+
CGO_ENABLED: "1"
60+
run: |
61+
v=${GITHUB_REF_NAME}
62+
mkdir -p dist work
63+
pack() { # arch name
64+
d=work/$2; mkdir -p "$d"
65+
GOOS=darwin GOARCH=$1 go build -ldflags "-s -w -X main.version=$v" -o "$d/dpi-bypass" ./cmd/dpi-bypass
3766
cp README.md "$d/"
3867
chmod 755 "$d/dpi-bypass"
39-
tar -C work -czf "dist/$3.tar.gz" "$3"
68+
tar -C work -czf "dist/$2.tar.gz" "$2"
4069
}
41-
pack darwin arm64 dpi-bypass-macos-apple-silicon
42-
pack darwin amd64 dpi-bypass-macos-intel
43-
pack linux amd64 dpi-bypass-linux-amd64
44-
(cd dist && sha256sum * > SHA256SUMS.txt)
45-
ls -l dist
70+
pack arm64 dpi-bypass-macos-apple-silicon
71+
pack amd64 dpi-bypass-macos-intel
72+
73+
- name: the macOS binaries start
74+
run: |
75+
tar -xzf dist/dpi-bypass-macos-apple-silicon.tar.gz -C "$RUNNER_TEMP"
76+
[ "$("$RUNNER_TEMP"/dpi-bypass-macos-apple-silicon/dpi-bypass --version)" = "${GITHUB_REF_NAME}" ]
77+
78+
- uses: actions/upload-artifact@v4
79+
with:
80+
name: dist-macos
81+
path: dist/*
82+
83+
release:
84+
needs: [build-windows-linux, build-macos]
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/download-artifact@v4
88+
with:
89+
path: dist
90+
pattern: dist-*
91+
merge-multiple: true
92+
93+
- name: checksums
94+
run: |
95+
cd dist
96+
sha256sum dpi-bypass-* > SHA256SUMS.txt
97+
ls -l
4698
4799
- name: archives keep the executable bit
48100
run: |
@@ -55,8 +107,8 @@ jobs:
55107
env:
56108
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57109
run: |
58-
gh release create "$GITHUB_REF_NAME" dist/* --title "$GITHUB_REF_NAME" --generate-notes \
59-
--notes "Windows: download the .exe and double-click it (a tray icon appears; Windows may warn because the file is not code-signed: More info > Run anyway). macOS: brew install hong4rc/tap/dpi-bypass (avoids the Apple could-not-verify warning), or extract the .tar.gz, run xattr -d com.apple.quarantine dpi-bypass, then ./dpi-bypass in a terminal (experimental). Linux: extract the .tar.gz and run ./dpi-bypass in a terminal (experimental). See the README."
110+
gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" --title "$GITHUB_REF_NAME" --generate-notes \
111+
--notes "Windows: download the .exe and double-click it (a tray icon appears; Windows may warn because the file is not code-signed: More info > Run anyway). macOS: brew install hong4rc/tap/dpi-bypass (a dot appears in the menu bar, and it avoids the Apple could-not-verify warning; brew services start dpi-bypass runs it at login), or extract the .tar.gz, run xattr -d com.apple.quarantine dpi-bypass, then ./dpi-bypass. Linux: extract the .tar.gz and run ./dpi-bypass in a terminal (experimental). See the README."
60112
61113
# Opens a pull request on the Homebrew tap that points the formula at this release.
62114
# Needs a repository secret TAP_TOKEN: a personal access token that can write

‎README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Download from [Releases](../../releases). Each download is everything you need:
1111
| OS | Download | Run |
1212
|---|---|---|
1313
| Windows | `dpi-bypass-windows-amd64.exe` | double-click it. A tray icon appears. Windows may warn because the file is not code-signed: **More info > Run anyway** |
14-
| macOS | `brew install hong4rc/tap/dpi-bypass` (recommended), or `dpi-bypass-macos-apple-silicon.tar.gz` / `dpi-bypass-macos-intel.tar.gz` | run `dpi-bypass` in a terminal (experimental). Homebrew avoids the "Apple could not verify" warning. With a manual download, macOS blocks it until you run `xattr -d com.apple.quarantine dpi-bypass` |
14+
| macOS | `brew install hong4rc/tap/dpi-bypass` (recommended), or `dpi-bypass-macos-apple-silicon.tar.gz` / `dpi-bypass-macos-intel.tar.gz` | run `dpi-bypass`; a dot appears in the menu bar (experimental). Homebrew avoids the "Apple could not verify" warning. With a manual download, macOS blocks it until you run `xattr -d com.apple.quarantine dpi-bypass` |
1515
| Linux | `dpi-bypass-linux-amd64.tar.gz` | extract, then `./dpi-bypass` in a terminal (experimental) |
1616

1717
macOS and Linux are `.tar.gz` because a plain downloaded binary loses its "executable" permission; the archive keeps it. `SHA256SUMS.txt` lists the checksums.
@@ -27,7 +27,9 @@ Or build it yourself: `just build` / `go build -o dpi.exe ./cmd/dpi-bypass`.
2727
3. **Right-click the tray icon** for quick actions: Turn on/off, Share with other devices, Open dashboard, Clear log, Start with Windows, Quit. There are no notifications for normal things (starting, switching something, learning a site): the icon colour, the checkmarks and the dashboard are the feedback. A notification only appears when something really failed, for example when something else is using the port.
2828
4. **Left-click the tray icon** to turn the bypass on or off. For the dashboard, choose Open dashboard, start the exe a second time, or open `http://127.0.0.1:18080/`.
2929

30-
macOS/Linux: run the binary in a terminal, open the dashboard address it prints, stop with Ctrl+C. On Linux without GNOME, set your system proxy auto-config (PAC) URL to `http://127.0.0.1:18080/proxy.pac` yourself.
30+
macOS: run `dpi-bypass` in a terminal, or start it at every login with `brew services start dpi-bypass`. A dot appears in the menu bar (green when the bypass is on). **Click it** for the same menu as on Windows (Turn on/off, Share with other devices, Open dashboard, Clear log, Quit). The menu has no "Start with Windows" item: use `brew services` for that.
31+
32+
Linux: run the binary in a terminal, open the dashboard address it prints, stop with Ctrl+C. On Linux without GNOME, set your system proxy auto-config (PAC) URL to `http://127.0.0.1:18080/proxy.pac` yourself.
3133

3234
## Dashboard
3335

@@ -125,7 +127,7 @@ The app is meant to run for a very long time without a restart:
125127

126128
- Only fixes **SNI-based** blocking over HTTPS. Not IP or DNS blocking, not UDP/QUIC.
127129
- Only apps that honor the system proxy are covered (browsers, Steam client, most launchers).
128-
- macOS and Linux builds are untested on real machines and have no tray icon.
130+
- The macOS and Linux builds are experimental. Linux has no tray icon.
129131

130132
## Develop
131133

@@ -135,4 +137,4 @@ just run # run from source with console output
135137
go test ./...
136138
```
137139

138-
Layout: `cmd/dpi-bypass` (entry), `internal/policy` (modes, decisions, evidence), `internal/proxy` (split, retries, PAC), `internal/dashboard` (web UI + API), `internal/stats` (devices, identities, activity), `internal/identify` (HTTPS identify page), `internal/blacklist`, `internal/settings`, `internal/sysproxy` (Windows / macOS / Linux + crash guard), `internal/tray` (Windows icon and menu), `internal/autostart`, `internal/app`, `internal/notify`, `internal/logx`.
140+
Layout: `cmd/dpi-bypass` (entry), `internal/policy` (modes, decisions, evidence), `internal/proxy` (split, retries, PAC), `internal/dashboard` (web UI + API), `internal/stats` (devices, identities, activity), `internal/identify` (HTTPS identify page), `internal/blacklist`, `internal/settings`, `internal/sysproxy` (Windows / macOS / Linux + crash guard), `internal/tray` (Windows tray and macOS menu bar icon and menu), `internal/autostart`, `internal/app`, `internal/notify`, `internal/logx`.

‎docs/releasing.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A release is a `v*` tag pushed to `main`. `.github/workflows/release.yml` does t
44

55
## What the workflow does
66

7-
1. **release** runs the tests, builds the Windows `.exe` and the macOS and Linux `.tar.gz` archives, writes `SHA256SUMS.txt`, and publishes the GitHub release.
7+
1. **build-windows-linux** runs the tests and builds the Windows `.exe` and the Linux `.tar.gz` on Linux. **build-macos** builds the two macOS `.tar.gz` archives on a macOS runner with CGO, because the menu bar icon is Cocoa code and cannot be cross-compiled from Linux. **release** then writes `SHA256SUMS.txt` and publishes the GitHub release.
88
2. **tap** points `Formula/dpi-bypass.rb` in [hong4rc/homebrew-tap](https://github.com/hong4rc/homebrew-tap) at the new tag, using `scripts/bump-formula.py` and the release checksums, and opens a pull request there.
99
3. **verify-brew** installs from that pull request's branch on a clean macOS runner. It runs `brew audit --strict --online`, `brew install`, `brew test`, then checks that `dpi-bypass --version` equals the tag and that the installed binary has no `com.apple.quarantine` attribute (that attribute is what triggers the "Apple could not verify" warning).
1010

‎internal/notify/policy_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func TestNotificationsAreOnlyForRealFailures(t *testing.T) {
1717
allowed := map[string]int{
1818
"cmd/dpi-bypass/main.go": 1, // another copy is already running: the app exits, there is no other way to say so
19-
"internal/tray/tray_windows.go": 2, // sharing could not be switched on / start with Windows could not be changed
19+
"internal/tray/tray.go": 2, // sharing could not be switched on / start at login could not be changed
2020
}
2121

2222
root := filepath.Join("..", "..")

‎internal/tray/icon.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build windows || darwin
2+
3+
package tray
4+
5+
import (
6+
"bytes"
7+
"image"
8+
"image/color"
9+
"image/png"
10+
)
11+
12+
// circlePNG returns an n x n PNG of a filled circle so no binary assets are needed.
13+
func circlePNG(c color.NRGBA, n int) []byte {
14+
img := image.NewNRGBA(image.Rect(0, 0, n, n))
15+
mid, r := float64(n-1)/2, float64(n)*14/32
16+
for y := 0; y < n; y++ {
17+
for x := 0; x < n; x++ {
18+
dx, dy := float64(x)-mid, float64(y)-mid
19+
if dx*dx+dy*dy <= r*r {
20+
img.SetNRGBA(x, y, c)
21+
}
22+
}
23+
}
24+
var p bytes.Buffer
25+
png.Encode(&p, img)
26+
return p.Bytes()
27+
}

‎internal/tray/icon_windows.go‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎internal/tray/platform_darwin.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package tray
2+
3+
import (
4+
"image/color"
5+
"os/exec"
6+
"strings"
7+
)
8+
9+
// leftClickToggles: on macOS a click on the menu bar icon opens its menu, as every
10+
// other menu bar app does; turning the bypass on or off is the first menu item.
11+
const leftClickToggles = false
12+
13+
// autostartLabel is empty: on macOS start at login is `brew services start dpi-bypass`.
14+
const autostartLabel = ""
15+
16+
// makeIcon returns a 44x44 (22 points at 2x) filled-circle PNG, which is what the
17+
// menu bar takes.
18+
func makeIcon(c color.NRGBA) []byte { return circlePNG(c, 44) }
19+
20+
// OpenURL opens url in the default browser.
21+
func OpenURL(url string) { exec.Command("open", url).Start() }
22+
23+
// copyText puts s on the clipboard using pbcopy.
24+
func copyText(s string) {
25+
cmd := exec.Command("pbcopy")
26+
cmd.Stdin = strings.NewReader(s)
27+
cmd.Run()
28+
}

‎internal/tray/platform_windows.go‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package tray
2+
3+
import (
4+
"bytes"
5+
"encoding/binary"
6+
"image/color"
7+
"os/exec"
8+
"strings"
9+
"syscall"
10+
11+
"golang.org/x/sys/windows"
12+
)
13+
14+
// leftClickToggles: on Windows a left click flips the bypass and a right click opens the menu.
15+
const leftClickToggles = true
16+
17+
// autostartLabel is the text of the start-at-login menu item.
18+
const autostartLabel = "Start with Windows"
19+
20+
// makeIcon returns a 32x32 filled-circle .ico (PNG payload) so no binary assets are needed.
21+
func makeIcon(c color.NRGBA) []byte {
22+
p := circlePNG(c, 32)
23+
var b bytes.Buffer
24+
binary.Write(&b, binary.LittleEndian, []uint16{0, 1, 1}) // ICONDIR: reserved, type=icon, count
25+
b.Write([]byte{32, 32, 0, 0}) // width, height, palette, reserved
26+
binary.Write(&b, binary.LittleEndian, []uint16{1, 32}) // planes, bits per pixel
27+
binary.Write(&b, binary.LittleEndian, uint32(len(p))) // image size
28+
binary.Write(&b, binary.LittleEndian, uint32(22)) // image offset
29+
b.Write(p)
30+
return b.Bytes()
31+
}
32+
33+
// OpenURL opens url in the default browser without flashing a console window.
34+
func OpenURL(url string) {
35+
cmd := exec.Command("rundll32", "url.dll,FileProtocolHandler", url)
36+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NO_WINDOW}
37+
cmd.Start()
38+
}
39+
40+
// copyText puts s on the clipboard using clip.exe (hidden, no console flash).
41+
func copyText(s string) {
42+
cmd := exec.Command("clip")
43+
cmd.Stdin = strings.NewReader(s)
44+
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NO_WINDOW}
45+
cmd.Run()
46+
}

0 commit comments

Comments
 (0)