Skip to content

Replace older copies and retire shadowing desktop entries - #21

Merged
nstarke merged 1 commit into
mainfrom
claude/vibrant-fermat-5une3p
Oct 30, 2026
Merged

nstarke merged 1 commit into
mainfrom
claude/vibrant-fermat-5une3p

Conversation

@nstarke

@nstarke nstarke commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds functionality to handle upgrades from manually-installed copies to the packaged (.deb) version of the LLM Usage Widget. When a newer version starts, it now stops older running copies and removes user-level desktop entries that would shadow the system package's autostart entry.

Key Changes

  • Version bump: Updated to 1.0.9
  • Process replacement logic: Added replace_older_copies() to detect and stop older running instances, then acquire the single-instance lock
    • older_copies() identifies running Python processes executing older versions or stale copies (started before script upgrade)
    • _process_start() reads process start time from /proc/[pid]/stat (Linux)
    • script_version() extracts version from __version__ in Python scripts
  • Desktop entry cleanup: Added retire_shadowing_entries() to remove per-user autostart and launcher entries that:
    • Point to older copies of the script
    • Would shadow the system package's /etc/xdg/autostart entry
    • Only runs for the packaged installation when system entry exists
    • _desktop_exec_script() parses .desktop files to extract the script path
  • Main flow integration: Modified main() to:
    • Call retire_shadowing_entries() on Linux and warn about removed entries
    • Attempt replace_older_copies() if single-instance lock acquisition fails
  • Claude usage display fix: Changed extra usage bar to show None percent when there's no spending cap (no bar to fill against)

Implementation Details

  • Process detection uses /proc/[pid]/stat and /proc/stat on Linux to determine start times
  • Version comparison uses semantic versioning via parse_version()
  • Desktop entry parsing handles both quoted and unquoted Exec= values
  • Respects XDG_CONFIG_HOME and XDG_DATA_HOME environment variables for user directories
  • Gracefully handles missing processes or unreadable files (returns empty lists)
  • Includes comprehensive test coverage for all new functionality

https://claude.ai/code/session_013mySqGaN3MoXy2yY16ZUG8

Installing the .deb over a copy set up with install.sh left the old copy in
charge: its ~/.config/autostart entry has the same name as the package's
/etc/xdg/autostart one, so it shadows it and starts at every login, and it
holds the single-instance lock, so the packaged version exits as "already
running". Users kept seeing the pre-0.0.2 menu (no cutoffs, Collapse, About)
and the unscaled extra usage amount after upgrading.

- When the lock is held by a copy running an older version, or one that
  started before its script was replaced, stop it and take the lock.
- The .deb's copy removes per-user autostart/launcher entries that run an
  older or deleted usage_widget.py, so its own entry applies again.
- Extra usage without a cap shows the spend alone, not a 0% bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013mySqGaN3MoXy2yY16ZUG8
@nstarke
nstarke merged commit e1d3d5a into main Oct 30, 2026
31 checks passed
@nstarke
nstarke deleted the claude/vibrant-fermat-5une3p branch October 30, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants