Skip to content

Update shortcut removal to rely on menuinst.toml#1

Open
lrandersson wants to merge 8 commits into
dev-ra-829from
dev-ra-829-2
Open

Update shortcut removal to rely on menuinst.toml#1
lrandersson wants to merge 8 commits into
dev-ra-829from
dev-ra-829-2

Conversation

@lrandersson
Copy link
Copy Markdown
Owner

@lrandersson lrandersson commented May 14, 2026

Description

Use recorded paths from menuinst.toml for removal instead of recomputing from JSON. Falls back to computed paths for legacy installs.

api.py

  • Added get_recorded_paths(), delete_paths()
  • remove() now checks TOML first, falls back to computed paths. I wasn't sure if it's totally safe to remove the "old code", I was thinking that there might be a scenario where packages are installed, then menuinst is updated to a version with menuinst.toml, but the shortcuts installed before the update are not tracked in the .toml file.
  • install() records MenuItem paths (not Menu paths) to TOML

Platform files (win.py, osx.py, linux.py)

  • Split remove() into delete_paths() + cleanup_side_effects(). When using TOML paths, api.remove() handles file deletion directly (it has the TOML data). But platform-specific cleanup (registry, LaunchServices, MIME etc.) still needs the MenuItem objects. Separating these two lets api.py delete files from TOML data while platforms handle their own side-effects.
  • Original remove() preserved (calls both)

Removal Flow

To simplify the review, this is the removal flow:

api.remove()
 ├─ Read TOML paths for source
 │   ├─ Found → delete_paths(toml_paths)
 │   └─ Not found → fallback to old approach: menu_item.delete_paths()
 ├─ menu_item.cleanup_side_effects() (registry, LaunchServices, MIME)
 ├─ menu.remove() (directory cleanup)
 └─ remove_shortcut_records() from TOML

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@lrandersson lrandersson marked this pull request as ready for review May 15, 2026 13:33
@lrandersson lrandersson self-assigned this May 15, 2026
Comment thread menuinst/api.py
"""Get recorded shortcut paths for a source from menuinst.toml."""
data = read_menuinst_toml(prefix)
shortcuts = data.get("shortcuts", [])
return [s["path"] for s in shortcuts if s.get("source") == source and "path" in s]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should they be sources be converted into Path objects to not depend on string shenanigans? Or maybe even use Path.same_file()?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is good but here we are unfortunately comparing filename strings (basename) and not the actual path on disk so unfortunately Path.samefile is not applicable.

@marcoesters
Copy link
Copy Markdown

Before I review this in detail, I have a more general question: you use the API-level removal function to remove the shortcuts if loaded from TOML. Have you considered to instead just load the paths from the TOML file? Maybe as an optional input parameter for _paths() or as an optional input parameter for the __init__ methods?

That way, we don't have to touch any of the existing removal methods and keep everything located inside the classes.

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