From 90518de261555814df7e9fd499cdda2a4ade0d3d Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 16:13:55 +0800 Subject: [PATCH] install.sh: --uninstall takes the mimeapps.list xdg-mime made when nothing else is in it After 305c624ed a curl-piped install and --uninstall in a fresh HOME left ~/.config/mimeapps.list holding only the "[Default Applications]" header xdg-mime wrote at install. A list with no entry left (only section headers and blank lines) now goes; one with any line of the user's stays as it is, less magpie's. Run at 305c624ed + this: node --test site/install.test.mjs worker.test.mjs stable.test.mjs on mote (53 pass); install.test.mjs in WSL magpie-desktop (14 pass); dash -n ok. Real run in WSL with the real 0.1.2345 release, sandbox HOME: with a text/html line of the user's the list keeps it, and the rest of the run is as 305c624ed says. Broken by hand: the rm taken out turns the --uninstall and --purge tests red (the list is still there). Not tried: a mimeapps.list with comments only (a # line counts as an entry and keeps the file). --- site/install.test.mjs | 7 ++++++- site/public/install.sh | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/site/install.test.mjs b/site/install.test.mjs index 4c9f7b157..b6db00b90 100644 --- a/site/install.test.mjs +++ b/site/install.test.mjs @@ -211,6 +211,11 @@ test("--uninstall takes off the command, menu entry, icon and magpie:// default, assert.equal(u.status, 0, u.stderr); for (const p of [r.exe, r.entry, r.icon]) assert.equal(existsSync(p), false, p); assert.equal(readFileSync(r.mime, "utf8"), "[Default Applications]\ntext/html=firefox.desktop\n"); + // with no line of the user's, the list xdg-mime made goes with it + const bare = installedDesktop(t); + const bu = bare.run(["--uninstall"]); + assert.equal(bu.status, 0, bu.stderr); + assert.equal(existsSync(bare.mime), false); assert.ok(existsSync(r.settings), "the settings stay"); assert.equal(r.calls(), "", "magpie isn't asked to uninstall"); assert.equal(u.calls.length, 0, "nothing is downloaded"); @@ -260,7 +265,7 @@ test("--purge has magpie uninstall itself first, then takes off the install", (t assert.match(r.calls(), /^uninstall --yes$/m); for (const p of [r.exe, r.entry, r.icon, r.settings]) assert.equal(existsSync(p), false, p); // magpie took the menu entry itself; its icon and magpie:// default go too - assert.doesNotMatch(readFileSync(r.mime, "utf8"), /magpie/); + assert.equal(existsSync(r.mime), false); assert.doesNotMatch(u.stdout, /kept your settings/); // magpie failing to: the command stays, to run it again diff --git a/site/public/install.sh b/site/public/install.sh index 3adb30ef5..0e3bdafe8 100644 --- a/site/public/install.sh +++ b/site/public/install.sh @@ -152,6 +152,8 @@ if [ -n "$uninstall" ]; then if [ -f "$list" ] && grep -qx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list"; then grep -vx 'x-scheme-handler/magpie=magpie\.desktop;\{0,1\}' "$list" > "$list.magpie-new" || true mv "$list.magpie-new" "$list" + # a list left with no entry at all (the one xdg-mime made) goes + grep -qv -e '^\[.*\]$' -e '^[[:space:]]*$' "$list" || rm -f "$list" removed=1; say "removed magpie:// from $list" fi if [ -d "$apps" ] && ! ls "$apps" | grep -q '\.desktop$'; then