aboutsummaryrefslogtreecommitdiffstats
path: root/docs/superpowers/specs/2026-11-26-default-apps-design.md
blob: 6034c80f2b03d43307f9bfa9c10c4d684b56c98d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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 (`DesktopEntries.byId` finds no entry for it) 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.