# NXM Integration

OVLS registers an `nxm://` protocol handler for **"Download with Vortex"** buttons on Nexus Mods so the link can be passed to the official Vortex running through Proton. Handler registration and verification are the same in Desktop Mode and Game Mode; actual delivery depends on the environment. In SteamOS Game Mode it is verified only when Vortex is already open; see [Known limitations](limitations.md).

## How NXM works

When you click an `nxm://` link on Nexus Mods:

1. Your desktop environment opens the OVLS NXM handler (`ovls-nxm.desktop`).
2. The handler runs `ovls.py nxm --prefix <your-prefix> --uri "nxm://..."`.
3. OVLS passes the URI to Vortex. In Desktop Mode the launch path can start Vortex with the link when Vortex is not running; this was observed in the test environment. In SteamOS Game Mode delivery is verified only when Vortex is already open; with Vortex closed it is not guaranteed in the test environment and no OVLS fix is implemented.
4. When the link reaches Vortex, Vortex downloads and installs the mod through its normal Windows flow.

### Heroic Vortex prefixes

For a Heroic-managed Vortex prefix, `ovls.py nxm` resolves the existing Heroic sideload Vortex app by matching the prefix `GamesConfig` `winePrefix`. If Vortex is already running in that prefix, OVLS writes `ovls-pending-nxm.json` in Vortex user data and the OVLS Extension delivers it to Vortex. If the handoff fails, OVLS falls back to a direct Heroic runner launch with `-d <nxm://...>`. If Vortex is not running, OVLS opens `heroic://launch` for that sideload app with the `-d` URI argument.

## How OVLS registers NXM

OVLS installs three files:

| File | Location | Purpose |
|------|----------|---------|
| `ovls-nxm` | `~/.local/share/ovls/ovls-nxm` | Wrapper script that runs `ovls.py nxm --prefix ... --uri "$1"` |
| `ovls-nxm.desktop` | `~/.local/share/applications/ovls-nxm.desktop` | Desktop entry declaring the `nxm://` protocol handler (hidden from the applications menu; `NoDisplay=true`) |
| `nxm-previous-default` | `~/.local/share/ovls/nxm-previous-default` | Stores the previous handler for `~/.config/mimeapps.list` (first line) and for `~/.local/share/applications/mimeapps.list` (second line, if present) so OVLS can restore both on uninstall. An optional third line records that the one-time portal check has already been done. |

OVLS sets the default in two places: with `xdg-mime default` in `$XDG_CONFIG_HOME/mimeapps.list`, and directly in `$XDG_DATA_HOME/applications/mimeapps.list`. The second entry is needed by sandboxed browsers such as Flatpak Chrome, which read the data directory. Both edits touch only the `x-scheme-handler/nxm` lines and leave other associations intact. Each file keeps at most one `mimeapps.list.ovls-backup-<UTC>` recovery copy when it changes; OVLS does not restore from those copies automatically. If no previous handler existed in a file, uninstall removes only OVLS's own entry from that file.

## Flatpak Chrome portal choice

Flatpak Chrome can keep its own remembered `nxm://` handler in the portal permission store. During Install / Update, OVLS checks that store once. It removes a choice **only** when all of these match exactly: table `desktop-used-apps`, object `x-scheme-handler/nxm`, app `com.google.Chrome`, and handler `steam_http_loader`. Any other handler — including a choice you made yourself — is left untouched.

After that stale choice is cleared, the portal may show an application chooser the next time you click an NXM link. Select **OVLS NXM Handler** (or `ovls-nxm.desktop`). OVLS performs this cleanup on a best-effort basis: if Flatpak or D-Bus is unavailable, or the command fails, installation continues and the check can be retried on the next Install / Update. Uninstall never restores or removes a portal choice.

## Installing or updating the NXM handler

The NXM handler is installed automatically when you run **Install / Update** in OVLS Manager or `bash install.sh install`. It is also updated when you change your Proton prefix.

## Verifying NXM

Run:

```bash
bash install.sh verify
```

The verification output includes the NXM handler status. If it shows anything other than `ok`, re-run **Install / Update** from OVLS Manager.

## Uninstalling the NXM handler

Running **Uninstall** in OVLS Manager or `bash install.sh uninstall` removes:

- `~/.local/share/ovls/ovls-nxm` (the wrapper script)
- `~/.local/share/applications/ovls-nxm.desktop` (the desktop entry)
- `~/.local/share/ovls/nxm-previous-default` (the state file)

For each of the two files where OVLS is the current default, uninstall tries to restore the saved handler, but only if its name is recorded in `nxm-previous-default`, its `.desktop` file still exists, and switching back succeeds. Otherwise OVLS removes its own `ovls-nxm.desktop` entry from the `x-scheme-handler/nxm` line in both `mimeapps.list` files, even when another application is the default; other handlers are preserved, but the previous handler is not guaranteed to be restored. State files from older versions contain a single line; those are still read, and the data-directory entry is simply removed on uninstall. `mimeapps.list.ovls-backup-*` copies are temporary recovery points: they are removed during uninstall after any data that could not be restored has been reported.

## Known limitations

- OVLS registers `nxm://` only for your desktop user. It does not modify system-wide handler configuration.
- If another application later registers itself as the default `nxm://` handler, OVLS will no longer receive links. Re-run **Install / Update** to re-register.
- A browser that was already running when OVLS changed the handler may need a restart before it picks up the new default.
- The portal cleanup is best-effort. It clears only the known stale `steam_http_loader` choice for Flatpak Chrome and NXM; it does not guarantee that a link clicked in SteamOS Game Mode reaches Vortex.
- SteamOS Game Mode is only partially verified: NXM delivery, mod downloads and text input work with Vortex already open. Closed-Vortex delivery and window visibility are not guaranteed. See [Known limitations](limitations.md).
- OVLS does not modify the official Vortex application files; it installs its own Extension into Vortex's plugin directory and provides an external desktop handler that receives an `nxm://` link and passes it to Vortex. For Heroic prefixes, when Vortex is already running in that prefix, the handler writes a pending NXM handoff file in Vortex user data and the OVLS Extension delivers it inside Vortex. There is no two-way IPC channel between the Python side and the Extension.
