Skip to content

System Tray and Auto Updater

buntatoes edited this page Nov 28, 2026 · 1 revision

System Tray and Auto-Updater

RubyLock RPC provides a persistent, zero-dependency native system tray icon on both Windows and Linux (lib/rubylock_rpc/tray.rb) alongside a verified GitHub Releases auto-updater (lib/rubylock_rpc/updater.rb).


Persistent System Tray (RubylockRpc::Tray)

Unless --no-tray is passed (which instantiates Tray::NullTray), RubyLock RPC creates a platform-native tray icon that stays live in the notification area and reflects your current Deadlock phase in real time.

Tray Menu Actions

Both Windows and Linux expose the exact same menu layout and actions:

Menu Item Behavior
RubyLock RPC v1.3.0 (disabled header) Displays the running version.
Status: <live status> (disabled header) Live Rich Presence summary (<details> — <state>, "Waiting for Deadlock", or "Connecting to Discord...").
Launch Deadlock Invokes Launcher.launch_deadlock (starts Deadlock via Steam with -condebug if not already running).
Exit When Game Closes (checkmark toggle) Flips shared.exit_when_game_closes in memory and immediately persists general.exit_when_game_closes to config.toml.
Auto-Update (checkmark toggle) Flips shared.auto_update in memory and immediately persists general.auto_update to config.toml.
Check for Updates Runs an immediate interactive Updater.check_and_apply(auto_update: false) check and notifies you if you are already on the latest version.
Open Config Folder Opens RpcLogger.resolve_data_dir in explorer.exe (Windows) or xdg-open (Linux).
Quit RubyLock RPC Clears Discord Rich Presence (SET_ACTIVITY with nil), closes IPC, removes the tray icon, releases the single-instance lock, and exits cleanly.

Windows Implementation (Tray::WindowsTray)

On 64-bit Windows (Gem.win_platform? && Fiddle::SIZEOF_VOIDP == 8), WindowsTray drives the Win32 notification area directly through Ruby's standard-library Fiddle bindings — no .NET, no PowerShell, and no compiled tray DLLs:

  • Bound Win32 Libraries:
    • kernel32.dll: GetModuleHandleW
    • user32.dll: RegisterClassExW, CreateWindowExW, DestroyWindow, DefWindowProcW, PeekMessageW, TranslateMessage, DispatchMessageW, PostMessageW, LoadImageW, DestroyIcon, CreatePopupMenu, AppendMenuW, TrackPopupMenu, DestroyMenu, GetCursorPos, SetForegroundWindow, RegisterWindowMessageW
    • shell32.dll: Shell_NotifyIconW
  • Hidden Message Window: Registers a per-PID window class (RubyLockRpcTrayWindow_<pid>) with a Fiddle::Closure::BlockCaller window procedure.
  • Icon & Tooltip: Loads assets/icon.ico via LoadImageW (LR_LOADFROMFILE | LR_DEFAULTSIZE), constructs a 976-byte NOTIFYICONDATAW buffer (NIM_ADD / NIM_MODIFY / NIM_DELETE), and updates tooltips (truncated to 127 UTF-16LE characters) from the 50ms PeekMessageW loop.
  • Explorer Restart Recovery: Registers "TaskbarCreated" via RegisterWindowMessageW and automatically re-adds the icon with NIM_ADD if explorer.exe restarts.
  • Click Handling: Both left-click (WM_LBUTTONUP) and right-click (WM_RBUTTONUP) open the popup menu at the cursor position (GetCursorPos + SetForegroundWindow + TrackPopupMenu), dispatching the selected action on a background thread.

Linux Implementation (Tray::LinuxDbusTray & Tray::DbusWire)

On Linux, RubyLock RPC speaks the D-Bus binary wire protocol (little-endian v1) directly in pure Ruby over a UNIXSocket — requiring neither libdbus, libayatana-appindicator, nor dbus-send:

D-Bus Session Bus Connection & Auth

  1. Reads $DBUS_SESSION_BUS_ADDRESS (or falls back to $XDG_RUNTIME_DIR/bus if a socket exists).
  2. Supports both filesystem (unix:path=...) and abstract (unix:abstract=...) UNIX sockets with percent-decoding.
  3. Authenticates using AUTH EXTERNAL <hex-encoded-uid> (falling back to AUTH ANONYMOUS), followed by BEGIN.
  4. Calls org.freedesktop.DBus.Hello, requests the bus name org.kde.StatusNotifierItem-<pid>-1, and registers /StatusNotifierItem with org.kde.StatusNotifierWatcher (RegisterStatusNotifierItem).
  5. Subscribes to NameOwnerChanged signals for org.kde.StatusNotifierWatcher so the tray icon automatically re-registers if the desktop shell or panel restarts.

Exported D-Bus Objects & Interfaces

Object Path Interfaces Key Methods / Properties
/StatusNotifierItem org.kde.StatusNotifierItem
org.freedesktop.DBus.Properties
org.freedesktop.DBus.Introspectable
org.freedesktop.DBus.Peer
Category ("ApplicationStatus"), Id ("rubylock-rpc"), Title ("RubyLock RPC"), Status ("Active"), IconName, IconThemePath, ToolTip, ItemIsMenu (true), Menu ("/MenuBar"), plus NewToolTip signal on status changes.
/MenuBar com.canonical.dbusmenu
org.freedesktop.DBus.Properties
org.freedesktop.DBus.Introspectable
Version (3), GetLayout, GetGroupProperties, GetProperty, Event, EventGroup, AboutToShow, AboutToShowGroup, plus LayoutUpdated signal when status or checkboxes change.

Icon Resolution on Linux

  1. Prefers the installed XDG hicolor icon ($HOME/.local/share/icons/hicolor/256x256/apps/rubylock-rpc.png) using IconName = "rubylock-rpc" and IconThemePath = "".
  2. For portable / Git checkouts where the hicolor icon is not installed, falls back to IconName = "icon" with IconThemePath = "<repo>/assets" (assets/icon.png).

Tip

Works out of the box on KDE Plasma, COSMIC, and XFCE. On GNOME, install the AppIndicator and KStatusNotifierItem Support extension to display StatusNotifierItem icons in the top bar.


GitHub Releases Auto-Updater (RubylockRpc::Updater)

Updater checks https://api.github.com/repos/buntatoes/rubylock-rpc/releases/latest on startup (unless --no-update-check is passed), when triggered from the tray (Check for Updates), or via CLI (--check-update / --update).

Version & Release Filtering

  • Ignores draft and prerelease GitHub releases.
  • Parses semantic tags matching vMAJOR.MINOR[.PATCH] (rejecting pre-release suffixes containing -, such as v1.3.0-rc1).
  • Compares [major, minor, patch] tuples against RubylockRpc::VERSION (1.3.0) and only offers updates when remote > current.
  • Selects the platform asset automatically:
    • Windows: RubyLock-RPC-Setup-*.exe (fallback: *.exe)
    • Linux: rubylock-rpc-linux-x86_64.tar.gz (fallback: *linux*.tar.gz)

Security Hardening

Every download and extraction step enforces strict validation:

Guard Implementation
HTTPS-Only Host Allowlist (TRUSTED_HOSTS) Refuses any URL or redirect target that is not HTTPS on one of: github.com, api.github.com, objects.githubusercontent.com, release-assets.githubusercontent.com, github-releases.githubusercontent.com, codeload.github.com.
Redirect Limit Caps HTTP redirects at MAX_REDIRECTS = 5, re-validating trusted_download_url? on every hop.
Magic-Byte Verification Verifies downloaded bytes before executing or unpacking: "MZ" for Windows PE .exe installers and 0x1F 0x8B (gzip header) for Linux .tar.gz archives.
Safe Tar Extraction (extract_tar_gz) Uses Zlib::GzipReader + Gem::Package::TarReader directly in Ruby and rejects any archive member starting with /, containing .., or resolving outside the destination directory (Path traversal detected).

Update Flow by Platform

flowchart LR
    Check["GET /releases/latest"] --> Newer{"Remote > Current?"}
    Newer -->|No| Done["Up to date"]
    Newer -->|Yes| Mode{"auto_update = true?"}
    Mode -->|No| Prompt["Native Prompt (MessageBoxW / zenity / kdialog / notify-send)"]
    Prompt -->|Declined| Stop["Skip update"]
    Prompt -->|Accepted| Download["Download + Verify Host & Magic Bytes"]
    Mode -->|Yes| Download
    Download --> Win["Windows: Spawn Setup.exe --silent & Exit cleanly"]
    Download --> Lin["Linux: Safe extract tar.gz & Run install.sh --silent with detected PREFIX"]
Loading
  • Windows: Downloads the setup .exe to Dir.tmpdir, validates "MZ", spawns <setup>.exe --silent, detaches it, and calls the shutdown callback so the running RubyLock RPC instance exits cleanly before files in %LOCALAPPDATA%\RubyLock-RPC are replaced (the installer itself retries locked files up to 25 times at 200ms intervals).
  • Linux: Extracts the .tar.gz into a temporary directory, detects the current install prefix (detect_linux_install_prefix: strips /share/rubylock-rpc when installed there, otherwise uses $PREFIX or $HOME/.local), runs sh install.sh --silent via Open3.capture3, and notifies the user to restart RubyLock RPC.

Clone this wiki locally