$ show Jaysce/Spaceman
Spaceman is a macOS menu bar utility that displays the current virtual desktop (Space) and related information. It uses private CGS APIs to observe space changes and renders a custom icon in the status bar showing the active space, fullscreen apps, and multi-display gaps. The app supports multiple display styles (rectangles, numbers, named spaces) and allows users to name spaces. The architecture follows a simple MVVM pattern with AppKit for the status bar and SwiftUI for preferences. It integrates Sparkle for automatic updates, LaunchAtLogin, and KeyboardShortcuts for a force-refresh shortcut. The codebase is well-structured, with clear separation of concerns, though it is tightly coupled to macOS-specific APIs and the Spaceman domain.
The LLM identified 3 files worth highlighting for reuse:
Generates the composite NSImage displayed in the menu bar. It handles multiple icon styles (rectangles, numbers, named spaces) by compositing overlay images and text using Core Graphics. The `mergeIcons` function correctly spaces icons and adds display gaps. While tightly coupled to the Space model, the image compositing logic is self-contained and could be adapted for other menu bar applications requiring dynamic icon generation.
Monitors macOS virtual desktop changes using private CGS functions (`_CGSDefaultConnection`, `CGSCopyManagedDisplaySpaces`). It parses display dictionaries to extract space information, manages space naming via UserDefaults, and notifies delegates on space updates. The pattern of using a delegate protocol and parsing system dictionaries is reusable for any macOS app that needs to observe system-level state changes, though the specific CGS calls are private and may break.
Manages the NSStatusItem and its menu, including integration with Sparkle for automatic updates. It demonstrates a clean pattern for handling scheduled updates with gentle reminders, updating the menu item title dynamically. The `SPUStandardUserDriverDelegate` implementation is a good example of how to customize Sparkle's update flow in a menu bar app without a main window.