Lutra/apps/lutra-desktop/installer/hooks.nsh
danny b17d26b400
Some checks are pending
ci / ci (macos-15) (push) Waiting to run
ci / ci (ubuntu-24.04) (push) Waiting to run
ci / ci (windows-2025) (push) Waiting to run
B2: setup finish without hang, Open with for PHP files, 0.1.0-alpha
- Finish page starts Lutra through Explorer (Exec, returns at once)
  instead of RunAsUser/ShellExecute on the setup's UI thread. The 0.0.0
  setup hung there while the new, unsigned exe was checked (Norton 360
  active); Windows ended it and left lutra-desktop.exe suspended.
  The NSIS template is an adapted copy of tauri-bundler 2.10.2's.
- installer/hooks.nsh registers Lutra only under OpenWithProgids and
  Applications\lutra-desktop.exe for .php/.phtml/.phpt/.inc; the
  default app stays. The uninstaller removes exactly those entries.
  macOS gets an Alternate-rank CFBundleDocumentTypes entry and handles
  RunEvent::Opened.
- A file path argument opens the file inside its Git/Composer root (or
  folder); a running instance takes it over, switching projects only
  when the file lies outside (never over unsaved changes).
- Version 0.1.0-alpha in the workspace, tauri.conf.json and ui; a test
  keeps tauri.conf.json in step with the crate version.
- xtask bundle passes CARGO_TARGET_DIR to the Tauri CLI as an absolute
  path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 22:37:56 +01:00

55 lines
2.6 KiB
NSIS

; Lutra's NSIS installer hooks (`bundle.windows.nsis.installerHooks`).
;
; Offers Lutra in Explorer's "Open with" menu for PHP files without making
; it the default app. Tauri's `bundle.fileAssociations` would set the
; extension's default value to its ProgID (the bundler's `APP_ASSOCIATE`
; macro), taking over the double-click, so on Windows Lutra registers only:
;
; - the ProgID `Lutra.PhpFile` (description, icon, open command);
; - the ProgID as a value under `Software\Classes\.<ext>\OpenWithProgids`,
; leaving `.<ext>`'s default value (the user's default app) alone;
; - `Software\Classes\Applications\lutra-desktop.exe` with `SupportedTypes`,
; so "Open with → Choose another app" lists Lutra under its own name.
;
; All of it goes to SHCTX, which is HKCU for Lutra's per-user setup. The
; uninstaller removes the same entries and nothing else: other apps' values
; under `OpenWithProgids` stay, and so does the user's default app.
!define LUTRA_PROGID "Lutra.PhpFile"
; Registers Lutra as an "Open with" choice for `.${EXT}` files.
!macro LUTRA_OPEN_WITH EXT
WriteRegStr SHCTX "Software\Classes\.${EXT}\OpenWithProgids" "${LUTRA_PROGID}" ""
WriteRegStr SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe\SupportedTypes" ".${EXT}" ""
!macroend
; Removes what `LUTRA_OPEN_WITH` wrote for `.${EXT}`.
!macro LUTRA_UN_OPEN_WITH EXT
DeleteRegValue SHCTX "Software\Classes\.${EXT}\OpenWithProgids" "${LUTRA_PROGID}"
!macroend
; The extensions Lutra offers to open.
!macro LUTRA_FOR_EACH_EXT MACRO
!insertmacro ${MACRO} "php"
!insertmacro ${MACRO} "phtml"
!insertmacro ${MACRO} "phpt"
!insertmacro ${MACRO} "inc"
!macroend
!macro NSIS_HOOK_POSTINSTALL
WriteRegStr SHCTX "Software\Classes\${LUTRA_PROGID}" "" "PHP file"
WriteRegStr SHCTX "Software\Classes\${LUTRA_PROGID}\DefaultIcon" "" "$INSTDIR\${MAINBINARYNAME}.exe,0"
WriteRegStr SHCTX "Software\Classes\${LUTRA_PROGID}\shell\open\command" "" '"$INSTDIR\${MAINBINARYNAME}.exe" "%1"'
WriteRegStr SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe" "FriendlyAppName" "${PRODUCTNAME}"
WriteRegStr SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe\DefaultIcon" "" "$INSTDIR\${MAINBINARYNAME}.exe,0"
WriteRegStr SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe\shell\open\command" "" '"$INSTDIR\${MAINBINARYNAME}.exe" "%1"'
!insertmacro LUTRA_FOR_EACH_EXT LUTRA_OPEN_WITH
!insertmacro UPDATEFILEASSOC
!macroend
!macro NSIS_HOOK_POSTUNINSTALL
!insertmacro LUTRA_FOR_EACH_EXT LUTRA_UN_OPEN_WITH
DeleteRegKey SHCTX "Software\Classes\${LUTRA_PROGID}"
DeleteRegKey SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe"
!insertmacro UPDATEFILEASSOC
!macroend