Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

The portable and installer executables are the same binary, and re-running the installer after install silently opens the app

Open PathGao opened this issue 4 months ago • 4 comments

build.yml ships two Windows executables that are byte-identical copies; get_app_mode() decides what to be by looking at its own filename for installer.

Two consequences:

  1. Renaming the file changes the program. Behaviour should not depend on what the file is called.
  2. After installing, the installer has no way in. The order is --uninstall → is_installed() → --install, and is_installed() short-circuits to "app". So a user who already installed and runs the installer again just gets the app — no Repair, no Uninstall, no way to change shortcut or file-association choices. Uninstalling has to go through Add/Remove Programs, which takes the separate --uninstall path.

The fix is small — check --install before is_installed() and land on a Repair/Uninstall screen — but it changes what an already-shipped executable does when double-clicked, so it seems worth your call rather than a drive-by PR.

(Related: #75 is about the install button being cut off; Installer.svelte uses height: 100vh; overflow: hidden with fixed heights, so raising the window only moves the threshold. Making that view scrollable would retire that class of report — happy to include it if you want this touched at all.)

PathGao avatar Aug 02 '26 21:08 PathGao

@PathGao

this results from an early naive attempt at building a custom installer. if we can recreate the features and theme into a separate installer, (or customize the NSIS installer?) we can scrap the multi-purpose executable.

alecdotdev avatar Aug 05 '26 00:08 alecdotdev

@alecdotdev — before you act on this: most of what I wrote in this issue is wrong or stale, and the premise you replied to doesn't hold. Correcting it, and reporting what I found while checking.

What is actually true, as of ebc20ab

Claim above
build.yml ships two byte-identical .exes Already gone. #355 removed the duplicate upload — merged 2026-08-02 16:05, about five hours before I filed this. I did not check my own recently-merged PR before writing. The workflow uploads the portable Markpad_<v>_<arch>.exe and the NSIS *-setup.exe, nothing else.
After installing, the installer offers no Repair/Uninstall Wrong. Installer.svelte has a full maintenance mode — version comparison, "Repair file associations", Update/Repair and Uninstall. check_install_status reads the registry, not the exe path.
is_installed() short-circuits to "app" Ordering right, consequence wrong. It asks "am I the exe at the install path?" — a downloaded copy in Downloads is not, so it does reach the installer.
get_app_mode() decides by its own filename Still true, and since #355 it is the only way in. Also documented rather than accidental: README.md:69 tells users to rename to MarkpadInstaller.exe.

Your reply's premise

if we can recreate the features and theme into a separate installer

I assumed the same thing you did and it turns out to be backwards. Feature by feature, the custom installer is the stronger of the two — it carries five fixes the NSIS path does not have:

  • #256 preserve file associations on uninstall
  • #252 environment handling
  • #358 don't terminate unrelated same-named processes
  • #364 recoverable install/uninstall
  • #400 create the shortcut directory first (the OS Error 3 cause)

plus one screen instead of a wizard, and a .md registration the user can decline. So "recreate the features" has it the wrong way round: the features are in the custom one.

But it is not the installer your users run. *-setup.exe is what a direct download gets and what tauri-plugin-updater executes on every auto-update, so it cannot be dropped. And since #355 no installer-named artifact ships, so the custom one is reachable only by deliberately renaming a file.

The result is that the hardening is stranded. The installer nobody can reach is the good one; the installer everyone runs is the unstyled default wizard, with <ProgID>_backup corruption (below) and — until #460 — a hooks file that never executed.

So I don't think the question is "custom or stock". It is how to get the custom installer's fixes into the path that actually runs, and installerHooks is the mechanism that was supposed to do it.

What I found while checking — #460

hooks.nsi defines NSIS_HOOK_POST_INSTALL; the bundler checks NSIS_HOOK_POSTINSTALL, no underscore, at every version from 2.0.0 to dev. !ifmacrodef fails silently, so the file has never run since it was added in January.

Worth knowing specifically: a5fda8e — "Fix markdown preview wrapping and open-with registration" — put the open-with registration into that file to fix a real report. That fix has never reached a user. The gap it was written for is probably still there. I did not revive it in #460 because it needs HKCU → SHCTX and a duplicate-label deconflict, both Windows-only checks.

#460 also declines to just rename the macros: doing that would have activated an unconditional $DESKTOP shortcut, and tauri-plugin-updater passes /UPDATE precisely so the template skips shortcut creation — the hook would have restored a desktop shortcut the user deleted, on every auto-update.

Two more, not fixed anywhere yet

The template corrupts .md associations the way #256 did. FileAssociation.nsh:70-71 writes the current handler into <ProgID>_backup unconditionally, so on reinstall it backs up Markpad's own ProgID over the user's original; APP_UNASSOCIATE then restores .md to a ProgID it deletes on the next line, and does so unconditionally, stomping an association another editor may have taken over since. Fixing it needs a PRE/POST hook pair — PREINSTALL alone runs before APP_ASSOCIATE — and arguably belongs upstream.

The two paths use different ProgIDs. NSIS writes Markdown File; setup.rs writes Markpad.File with its own PreviousAssociations subkey. They can clobber each other's .md default, so a user who has met both installers can end up with either.

Suggestion

Nothing here needs deciding today, and I have no stake in the outcome — I only wanted the premise to be right before you spent effort on it.

If it were mine: land #460, then port #256's association guard into the hooks now that they run, then add installerIcon / headerImage / sidebarImage so the shipped installer at least carries Markpad's identity — three images and three lines of config. That leaves the custom installer as the only thing still gated on a rename, which is the part actually worth removing, and the .md opt-out as the one feature that would genuinely be lost.

On #428 / #75: #428 landed in both Installer.svelte and Uninstaller.svelte, and the uninstaller outlives any of this — legacy installs point UninstallString at it until they migrate — so it keeps earning its place and #75 should be closed by it. No further layout work on Installer.svelte is worth doing.

What I could not verify

No Windows machine, so all of the following is read from source rather than observed: that hooks.nsi's failure shows up as a missing "Open with Markpad" verb; the runtime behaviour of is_installed / install_app / uninstall_app, all #[cfg(windows)]; the full <ProgID>_backup corruption across a real install → update → uninstall; and whether NSIS's PageReinstall races the legacy "…\Markpad.exe" --uninstall, which opens a UI and waits for a click while the deletion runs in a detached batch. That last one looks like a genuine hazard for anyone migrating from a pre-#355 install and I would want it checked on hardware before relying on that path.

Close this if you'd rather — what still stands is small, and the rest has moved to #460.

PathGao avatar Aug 05 '26 02:08 PathGao

One more consequence of this decision, which turned up today in #466.

The Windows portable exe is flagged by Microsoft as Trojan:Win32/Wacatac.B!ml on VirusTotal. It is a false positive, and the trigger is the custom uninstaller — setup.rs writes a .bat to %TEMP%, writes a .vbs that runs it with a hidden window and then deletes itself, and launches that through wscript.exe. That sequence is close to the definition of a behaviour classifier's malware pattern. Each property is deliberate and defensible in isolation (the batch waits on the PID rather than the image name so a portable copy survives an uninstall, #358) — the shape is what gets scored.

Two things make it relevant here rather than in its own thread:

The portable exe cannot reach that code and is flagged anyway. Per the correction above, get_app_mode() only enters installer mode on a filename containing installer or an --install argument, and no such artifact has shipped since #355. Heuristic and ML scanners read what is in the binary, not what the binary can reach.

It is the same root cause as #334, which you diagnosed in July — "a false positive caused by the custom uninstall script" — and said you would rework. It is still there, and now visible on the portable download rather than the installer.

So the tally on the custom installer as it stands: it holds five fixes the NSIS path does not have, no shipped artifact can reach it, and its uninstall half costs every portable-download user a Microsoft malware warning. That last one is the first consequence that reaches ordinary users rather than just maintenance.

Also worth stating because it is easy to assume otherwise: code signing does not fix this one. A certificate addresses SmartScreen reputation; it does not change a behaviour classifier's score. Same distinction applies to #209 on macOS — notarization fixes the quarantine and the TCC grant, not a heuristic detection.

PathGao avatar Aug 06 '26 00:08 PathGao

Closing: #481 removed the thing this was about.

The issue was that the portable and installer .exe are the same binary distinguished by filename, and that re-running the installer after installing silently opens the app instead of offering Repair/Uninstall. On @alecdotdev's call in #466, that code is gone — setup.rs (1684 lines), Installer.svelte and Uninstaller.svelte are deleted, and NSIS owns installation. There is now one binary with one mode, so there is no longer a distinction to get wrong.

What replaced the parts that mattered is written up in #466: NSIS's Section Install rewrites the legacy UninstallString unconditionally (line 682 of the bundler template, no $UpdateMode guard anywhere in that section), a hook in hooks.nsi clears a stale entry when the two disagree on a registry hive, and a stray --uninstall forwards to uninstall.exe.

Reopen if the shape of it survived somewhere I did not look.

PathGao avatar Aug 06 '26 04:08 PathGao