diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-14 12:32:54 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-14 12:33:40 +0200 |
| commit | 50733fe4ebac28136144d5b85721ee5fd0b7850a (patch) | |
| tree | 6546058f9ea41b81502e833c50ab32ef96718ec8 /internal/display | |
| parent | 52e70e2a065da95cdfcf7d370173003d3ce395cd (diff) | |
Add macOS support with automatic window activation
This commit adds full macOS support for loadbars, allowing it to run
natively on macOS for both localhost monitoring and remote Linux hosts.
Key changes:
- Embed both Linux and Darwin monitoring scripts in the binary
- Auto-detect localhost OS and use appropriate script
- Darwin script uses native macOS tools (sysctl, vm_stat, netstat, iostat)
- Remote hosts always use Linux script (assumes /proc filesystem)
- Automatic window activation on macOS using build tags
- No external helper scripts needed
The binary now works seamlessly on macOS:
- localhost monitoring uses macOS-specific commands
- Remote Linux hosts work via SSH with Linux script
- SDL window automatically comes to foreground on macOS
- Cross-platform build with single binary for all scenarios
Technical implementation:
- internal/collector/script.go: Embeds both scripts
- internal/collector/loadbars-remote-darwin.sh: macOS monitoring
- internal/collector/loadbars-remote.sh: Linux monitoring (copied from scripts/)
- internal/display/activate_darwin.go: macOS window activation
- internal/display/activate.go: No-op for other platforms
- Updated README.md with macOS installation instructions
- Added MACOS.md with detailed macOS documentation
Diffstat (limited to 'internal/display')
| -rw-r--r-- | internal/display/activate.go | 8 | ||||
| -rw-r--r-- | internal/display/activate_darwin.go | 24 | ||||
| -rw-r--r-- | internal/display/display.go | 3 |
3 files changed, 35 insertions, 0 deletions
diff --git a/internal/display/activate.go b/internal/display/activate.go new file mode 100644 index 0000000..b9040d7 --- /dev/null +++ b/internal/display/activate.go @@ -0,0 +1,8 @@ +// +build !darwin + +package display + +// activateWindow is a no-op on non-macOS platforms +func activateWindow() { + // Nothing needed on Linux/other platforms +} diff --git a/internal/display/activate_darwin.go b/internal/display/activate_darwin.go new file mode 100644 index 0000000..54c6b94 --- /dev/null +++ b/internal/display/activate_darwin.go @@ -0,0 +1,24 @@ +// +build darwin + +package display + +import ( + "os" + "os/exec" + "time" +) + +// activateWindow brings the SDL window to the foreground on macOS +func activateWindow() { + // Give SDL a moment to create the window + go func() { + time.Sleep(500 * time.Millisecond) + // Get the executable path + execPath, err := os.Executable() + if err != nil { + return + } + // Use open -a to bring the window to foreground + exec.Command("open", "-a", execPath).Run() + }() +} diff --git a/internal/display/display.go b/internal/display/display.go index 231b8c6..10a0b04 100644 --- a/internal/display/display.go +++ b/internal/display/display.go @@ -87,6 +87,9 @@ func Run(ctx context.Context, cfg *config.Config, src stats.Source) error { defer renderer.Destroy() window.SetTitle(title) + // On macOS, bring the window to the foreground + activateWindow() + state := newRunState(cfg, int32(width), int32(height)) ticker := time.NewTicker(time.Duration(constants.IntervalSDL * float64(time.Second))) defer ticker.Stop() |
