Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Linux: browser integration for Ubuntu's Snap Firefox; Snap Chromium no longer offered (#164) (#178)

Ahmed Nefzaoui2aa2b1cbf12b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ffe2eb7..adf8fbb1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -344,6 +344,12 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Linux: Ubuntu's Firefox reaches MDM** (part of [#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164)):
+ the Snap Firefox never makes the folder MDM looked for, so browser integration wasn't set up
+ for it and its extension couldn't find MDM. It is now, and the Snap goes through the desktop,
+ which asks once (**Allow**); the help says how to be asked again after **Don't allow**.
+ Chromium as a Snap ran MDM's helper inside its sandbox, away from MDM (it started a second,
+ sandboxed MDM): MDM no longer offers it, and the help says why.
- **Linux: the first window opens seconds sooner, and no longer freezes on a busy computer**
(part of [#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164)): MDM asked
fontconfig for its fonts one at a time (one program for each of some thirty scripts, more each
diff --git a/ROADMAP.md b/ROADMAP.md
index e110dcde..6302d295 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,9 @@ Everything below ships together, in one release.
### Done
+- ✅ Linux: Ubuntu's Firefox (the Snap) reaches MDM: browser integration is set up for it, and the
+ help says what the desktop asks the first time; Chromium as a Snap, which can't reach MDM, is no
+ longer offered (part of [#164](https://github.com/anefzaoui/misterdownloadmanager/issues/164))
- ✅ A smaller download: the installer 15 % and the zips 19 % smaller, nothing removed
([#158](https://github.com/anefzaoui/misterdownloadmanager/issues/158))
- ✅ Linux: MDM's first window opens seconds sooner; the system's fonts are looked up all at once
diff --git a/crates/app/src/unix.rs b/crates/app/src/unix.rs
index 8c633f72..b8b7f24c 100644
--- a/crates/app/src/unix.rs
+++ b/crates/app/src/unix.rs
@@ -706,16 +706,33 @@ pub fn browsers() -> Vec<(String, PathBuf)> {
.unwrap_or_default()
};
// A Flatpak browser (`app.zen_browser.zen` …) isn't listed: its sandbox can't start the
- // native host, so the extension couldn't reach MDM (docs/browser-help.md).
+ // native host, so the extension couldn't reach MDM (docs/browser-help.md). Nor is a Chromium
+ // browser that runs as a Snap (Ubuntu's Chromium): it starts the host inside its sandbox,
+ // which can't read MDM's data folder (~/.local/share is hidden from Snaps) and so started a
+ // second, sandboxed MDM. The Snap Firefox is listed: it starts the host through the desktop
+ // portal, outside its sandbox.
mdm_ipc::browsers::BROWSERS
.iter()
.filter_map(|b| {
let names = if mac { b.mac_apps } else { b.linux_cmds };
- found(names, &dirs).map(|p| (b.name.to_owned(), p))
+ found(names, &dirs).map(|p| (b, p))
})
+ .filter(|(b, p)| mac || b.family == mdm_ipc::browsers::Family::Gecko || !is_snap(p))
+ .map(|(b, p)| (b.name.to_owned(), p))
.collect()
}
+/// Linux: whether the command `p` starts a Snap: /snap/bin's links to `snap`, or the short
+/// scripts some distributions put in /usr/bin to start the Snap in a package's place.
+fn is_snap(p: &Path) -> bool {
+ if std::fs::canonicalize(p).is_ok_and(|real| real.ends_with("usr/bin/snap")) {
+ return true;
+ }
+ std::fs::metadata(p).is_ok_and(|m| m.len() < 16 * 1024)
+ && std::fs::read(p)
+ .is_ok_and(|b| b.starts_with(b"#!") && b.windows(10).any(|w| w == b"/snap/bin/"))
+}
+
/// Open `url` in the browser whose program is `program` (from `browsers`).
pub fn open_in(program: &Path, url: &str) {
if cfg!(target_os = "macos") {
diff --git a/crates/ipc/src/browsers.rs b/crates/ipc/src/browsers.rs
index 68904f37..b2190126 100644
--- a/crates/ipc/src/browsers.rs
+++ b/crates/ipc/src/browsers.rs
@@ -158,7 +158,9 @@ pub const BROWSERS: &[Browser] = &[
&["firefox"],
&["Mozilla", "Firefox"],
&["mozilla"],
- &[".mozilla"],
+ // The Snap (Ubuntu's own Firefox) keeps its profile in its snap folder and never makes
+ // ~/.mozilla; it reaches the host through the desktop portal, which reads ~/.mozilla's.
+ &[".mozilla", "snap/firefox/common/.mozilla"],
),
gecko(
"Zen Browser",
@@ -255,7 +257,8 @@ pub fn windows_can_run_extension(program: &str) -> bool {
/// Firefox and its forks (Zen, LibreWolf, Floorp, Waterfox) all read Mozilla's own user folder,
/// `~/.mozilla/native-messaging-hosts` or `~/Library/Application Support/Mozilla/
/// NativeMessagingHosts`, even when they keep their data elsewhere (Firefox's newer
-/// `~/.config/mozilla`, Zen's `~/.zen`): it is given, to be created, when any of them is there.
+/// `~/.config/mozilla`, Zen's `~/.zen`, the Snap's `~/snap/firefox`): it is given, to be created,
+/// when any of them is there.
pub fn host_dirs(home: &Path, config: &Path, mac: bool, all_users: bool) -> Vec<(PathBuf, Family)> {
let mut dirs: Vec<(PathBuf, Family)> = Vec::new();
if all_users {
@@ -397,6 +400,20 @@ mod tests {
);
}
+ /// Ubuntu's Snap Firefox has no ~/.mozilla; the portal it goes through reads it.
+ #[test]
+ fn snap_firefox_alone_gets_mozillas_folder() {
+ let h = tempfile::tempdir().unwrap();
+ std::fs::create_dir_all(h.path().join("snap/firefox/common/.mozilla/firefox")).unwrap();
+ assert_eq!(
+ user(h.path(), false),
+ vec![(
+ h.path().join(".mozilla/native-messaging-hosts"),
+ Family::Gecko
+ )]
+ );
+ }
+
/// #41: Helium reads its own folder (then Chrome's, which a Helium-only user doesn't have).
#[test]
fn helium_gets_its_own_folder() {
diff --git a/docs/browser-help.md b/docs/browser-help.md
index 8e81a15a..77665e63 100644
--- a/docs/browser-help.md
+++ b/docs/browser-help.md
@@ -33,6 +33,7 @@ The browser started MDM's helper, but it stopped before answering. Security soft
- Allow `misterdownloadmanager-nmhost.exe` (in MDM's folder) in your antivirus or anti-malware program.
- Reinstall MDM to restore its files.
+- On Linux, with Firefox or Chromium installed as a Snap, see [Flatpak and Snap browsers](#linux-sandbox).
## MDM doesn't accept this copy of the extension {#forbidden}
@@ -75,7 +76,13 @@ An add-on loaded with **Load Temporary Add-on** (from `about:debugging`) is remo
## Linux: Flatpak and Snap browsers {#linux-sandbox}
-Browsers installed as a Flatpak or a Snap run in a sandbox that may keep them from starting programs outside it, so they may not be able to reach MDM. Flatpak browsers (such as Zen's `app.zen_browser.zen`) can't start MDM's helper, so MDM doesn't list them in **Add Mister Download Manager to your browser**. Install the browser from your distribution's packages (or the browser maker's own `.deb`, `.rpm`, tarball or AppImage) to use browser integration.
+Browsers installed as a Flatpak or a Snap run in a sandbox, which decides whether they can reach MDM.
+
+- **Firefox as a Snap** (Ubuntu's own Firefox) reaches MDM through the desktop. The first time the extension calls MDM, the desktop asks **Allow Firefox to start WebExtension backend?** for Mister Download Manager: choose **Allow**. After **Don't allow**, the extension says the connection failed and the desktop doesn't ask again; to be asked again, run this in a terminal, then use the extension again:
+
+ `gdbus call --session --dest org.freedesktop.impl.portal.PermissionStore --object-path /org/freedesktop/impl/portal/PermissionStore --method org.freedesktop.impl.portal.PermissionStore.Delete webextensions com.misterdownloadmanager.host`
+- **Chromium as a Snap** (Ubuntu's Chromium) starts MDM's helper inside its sandbox, where it can't reach MDM, so MDM doesn't list it in **Add Mister Download Manager to your browser**. Use Firefox, or Google Chrome from its own `.deb`.
+- **Flatpak browsers** (such as Zen's `app.zen_browser.zen`) can't start MDM's helper, so MDM doesn't list them either. Install the browser from your distribution's packages (or the browser maker's own `.deb`, `.rpm`, tarball or AppImage) to use browser integration.
## Next steps
diff --git a/docs/getting-started.md b/docs/getting-started.md
index 3a677d3e..d8488f58 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -30,7 +30,7 @@ We haven't tried them ourselves yet, so you'd be among the first: please
| `...-linux-x86_64-experimental.rpm` | For Fedora, openSUSE and RHEL: `sudo dnf install ./<file>.rpm`. |
| `...-linux-x86_64-experimental.tar.gz` | The plain programs, for any distribution. |
-Browser integration is set up by MDM itself at each start on Linux and macOS (the browsers installed then are found); add the extension as in [Browser integration](browser-integration.md). Browsers installed as a Flatpak or a Snap may not be able to reach MDM.
+Browser integration is set up by MDM itself at each start on Linux and macOS (the browsers installed then are found); add the extension as in [Browser integration](browser-integration.md). Firefox installed as a Snap (Ubuntu's) reaches MDM once you allow it; other Snap and Flatpak browsers can't (see [Flatpak and Snap browsers](browser-help.md#linux-sandbox)).
In a Wayland session (GNOME, KDE Plasma and others), MDM's windows run through XWayland when it is there: Wayland doesn't let a program place its own windows, so MDM's menus and drop-down lists would open in the middle of the screen. To run on Wayland itself anyway, start it with `MDM_WAYLAND=1 misterdownloadmanager`.