aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/superpowers/specs/2026-11-26-default-apps-design.md118
1 files changed, 118 insertions, 0 deletions
diff --git a/docs/superpowers/specs/2026-11-26-default-apps-design.md b/docs/superpowers/specs/2026-11-26-default-apps-design.md
new file mode 100644
index 0000000..0c5f6db
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-26-default-apps-design.md
@@ -0,0 +1,118 @@
+# Default apps page
+
+A settings page that shows and sets the default application per file type,
+a frontend for what `xdg-mime query default` / `xdg-mime default` read and
+write: `~/.config/mimeapps.list`.
+
+## Why not xdg-mime
+
+`xdg-mime default` sets an entry but cannot remove one, so a remove button
+would edit the file anyway: two write paths. The page owns the file instead,
+one read and one write path, both in a tested JS file.
+
+Quickshell's `DesktopEntry` has no `mimeTypes` property (checked against the
+binary), so which apps can open which types comes from the `.desktop` files.
+
+## Layout
+
+`desktop/modules/mimeapps/`:
+
+- `MimeAppsModule.qml`: `name: "mimeapps"`, `label: "Default apps"`,
+ `settings: true`, `group: "Desktop"`. Keywords: `xdg`, `mime`, `mimeapps`,
+ `open with`, `file type`, `browser`, `mail`, `association`.
+ `searchItems` are the role labels and every explicit MIME type.
+- `MimeAppsPage.qml`: the page.
+- `MimeApps.js`: parse and edit, no QML dependencies.
+- `test_mimeapps.js`: node test, same shape as `test_fonts.js`.
+- `README.md`.
+
+## Data
+
+**Which apps declare which types.** One `Process` runs
+`grep -rH '^MimeType=' <dir>/applications` over every `XDG_DATA_DIRS` entry
+plus `~/.local/share/applications`. `MimeApps.js` turns the output into
+`{ desktopId: [mime, ...] }`. The desktop id is the path below
+`applications/` with `/` replaced by `-`, as the spec says. Where the same id
+turns up in two directories, the user's dir wins, then the first data dir.
+Names and icons come from `DesktopEntries.byId(id)`. An id with no entry
+shows its raw id. The scan runs when the page opens (`refresh()`).
+
+**The user's defaults.** A `FileView` on `$XDG_CONFIG_HOME/mimeapps.list`
+(falls back to `~/.config`), with `watchChanges`. The page keeps its own copy
+of the text, set on load and on every write, because `FileView.text()` lags
+`setText()` (AGENTS.md).
+
+## MimeApps.js
+
+- `parse(text)`: returns `{ mime: desktopId }` for `[Default Applications]`.
+ It walks the lines, never "everything up to the next `[`" (AGENTS.md).
+ A value is a `;`-separated list, and the first non-empty item is the
+ default.
+- `set(text, mime, id)`: returns the new text with `mime=id;` set in
+ `[Default Applications]`. It replaces the existing line in place or appends
+ it to the end of that section. If the section is missing, it is created at
+ the end of the file. If the file is empty, the result is the section alone.
+- `remove(text, mime)`: returns the new text without that line.
+- `scan(grepOutput)`: returns `{ desktopId: [mimes] }` as above.
+- `ROLES`: an ordered list of `{ label, mimes }`.
+
+Every edit leaves all other lines byte for byte, which covers
+`[Added Associations]`, other sections, comments and blank lines. The test
+pins exactly that, along with the cases above.
+
+## Roles
+
+| Role | Types |
+| --- | --- |
+| Browser | `text/html`, `application/xhtml+xml`, `x-scheme-handler/http`, `x-scheme-handler/https` |
+| Mail | `x-scheme-handler/mailto` |
+| Text | `text/plain` |
+| PDF | `application/pdf` |
+| Image | `image/png`, `image/jpeg`, `image/gif`, `image/webp`, `image/svg+xml` |
+| Video | `video/mp4`, `video/x-matroska`, `video/webm` |
+| Audio | `audio/mpeg`, `audio/flac`, `audio/ogg`, `audio/x-wav` |
+| Files | `inode/directory` |
+| Archive | `application/zip`, `application/x-tar`, `application/x-7z-compressed`, `application/gzip` |
+
+These lists are fixed in `ROLES`. Each role row shows the app most of its
+types currently map to. If none of them is set, the row reads "not set".
+If the types disagree, it reads "mixed (n apps)". The picker lists the apps
+that declare at least one of the role's types, and a "show all apps" toggle
+lists every `DesktopEntries` application. Picking one runs `set` for every
+type in the role, in one write.
+
+## Explicit section
+
+Every `[Default Applications]` entry, sorted by MIME type, with the app's
+icon and name, a picker built the same way as for a role (the apps declaring
+that type), and a remove button. Above it is a search field over every type
+any installed app declares. Choosing a type adds a row, and the row is only
+written once an app is picked for it.
+
+A row whose app is not installed (it has no `.desktop` file in the scan) shows
+the raw id in `Theme.red`, so a stale entry is visible.
+
+## Errors
+
+- If the file is missing, both sections render empty and the first write
+ creates the file (`FileView.setText` creates parent directories, per
+ AGENTS.md). The content is never empty after a `set`.
+- A `remove` that leaves `[Default Applications]` empty keeps the section
+ header, so the written text is never empty either. That avoids the
+ `setText("")` trap.
+- If the grep fails or finds nothing, the pickers offer only "show all apps".
+ The rows still render.
+
+## Out of scope
+
+Cleaning up `[Added Associations]`, system-wide `mimeapps.list` files,
+desktop-specific `<desktop>-mimeapps.list`, and a terminal role (Hyprland
+does not read one from mimeapps).
+
+## Verifying
+
+- `node desktop/modules/mimeapps/test_mimeapps.js`.
+- In the running shell: set the Browser role, then check
+ `xdg-mime query default x-scheme-handler/https` matches. Remove an explicit
+ entry and diff the file to confirm only that line changed.
+- Anything visual is checked by the user.