From b17d26b40070cfd0e33fda762b1a99589bbcb3ae Mon Sep 17 00:00:00 2001 From: danny Date: Sat, 31 Oct 2026 22:37:56 +0100 Subject: [PATCH] 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 --- Cargo.lock | 33 +- Cargo.toml | 2 +- NOTICE | 3 +- apps/lutra-desktop/Cargo.toml | 1 + apps/lutra-desktop/installer/hooks.nsh | 55 ++ apps/lutra-desktop/installer/installer.nsi | 997 +++++++++++++++++++++ apps/lutra-desktop/src/args.rs | 19 +- apps/lutra-desktop/src/host.rs | 25 +- apps/lutra-desktop/src/instance.rs | 125 ++- apps/lutra-desktop/src/main.rs | 57 +- apps/lutra-desktop/src/open.rs | 96 ++ apps/lutra-desktop/tauri.conf.json | 6 +- apps/lutra-desktop/tauri.macos.conf.json | 14 + docs/install.md | 29 +- ui/package.json | 2 +- ui/tests/App.test.ts | 4 +- xtask/src/bundle.rs | 20 +- 17 files changed, 1430 insertions(+), 58 deletions(-) create mode 100644 apps/lutra-desktop/installer/hooks.nsh create mode 100644 apps/lutra-desktop/installer/installer.nsi create mode 100644 apps/lutra-desktop/src/open.rs create mode 100644 apps/lutra-desktop/tauri.macos.conf.json diff --git a/Cargo.lock b/Cargo.lock index 95ec43f..89d9535 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2584,7 +2584,7 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" [[package]] name = "lutra-cli" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-control", "lutra-engine", @@ -2597,7 +2597,7 @@ dependencies = [ [[package]] name = "lutra-control" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "getrandom 0.3.4", "lutra-engine", @@ -2610,10 +2610,11 @@ dependencies = [ [[package]] name = "lutra-desktop" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-control", "lutra-engine", + "lutra-testkit", "png 0.18.1", "serde_json", "tauri", @@ -2627,7 +2628,7 @@ dependencies = [ [[package]] name = "lutra-engine" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-index", "lutra-lsp", @@ -2649,7 +2650,7 @@ dependencies = [ [[package]] name = "lutra-index" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "ignore", "lutra-syntax", @@ -2662,7 +2663,7 @@ dependencies = [ [[package]] name = "lutra-lsp" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-proc", "lutra-text", @@ -2679,7 +2680,7 @@ dependencies = [ [[package]] name = "lutra-mcp" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-control", "lutra-engine", @@ -2691,14 +2692,14 @@ dependencies = [ [[package]] name = "lutra-proc" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "windows-sys 0.61.2", ] [[package]] name = "lutra-search" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "globset", "grep-matcher", @@ -2713,7 +2714,7 @@ dependencies = [ [[package]] name = "lutra-syntax" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-text", "proptest", @@ -2723,7 +2724,7 @@ dependencies = [ [[package]] name = "lutra-terminal" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-proc", "portable-pty", @@ -2734,7 +2735,7 @@ dependencies = [ [[package]] name = "lutra-testkit" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-control", "lutra-engine", @@ -2743,7 +2744,7 @@ dependencies = [ [[package]] name = "lutra-text" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "proptest", "ropey", @@ -2751,7 +2752,7 @@ dependencies = [ [[package]] name = "lutra-vcs" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-proc", "proptest", @@ -2761,7 +2762,7 @@ dependencies = [ [[package]] name = "lutra-vfs" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "ignore", "notify", @@ -6547,7 +6548,7 @@ checksum = "e450f9b2ed1dff33c94c12589a87338689467b9c4f5d8a5710bd09a847d2c8a7" [[package]] name = "xtask" -version = "0.0.0" +version = "0.1.0-alpha" dependencies = [ "lutra-proc", "png 0.18.1", diff --git a/Cargo.toml b/Cargo.toml index 25381a9..768abfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = ["crates/*", "apps/*", "xtask"] default-members = ["crates/*", "apps/*"] [workspace.package] -version = "0.0.0" +version = "0.1.0-alpha" edition = "2024" rust-version = "1.88" license = "MIT OR Apache-2.0" diff --git a/NOTICE b/NOTICE index d762ea3..2c400cb 100644 --- a/NOTICE +++ b/NOTICE @@ -17,7 +17,8 @@ Bundled components (planned; update when added): * JetBrains Mono typeface (@fontsource/jetbrains-mono) — SIL Open Font License 1.1 * CodeMirror 6 — MIT License * tree-sitter and tree-sitter-php — MIT License - * Tauri — MIT OR Apache-2.0 + * Tauri — MIT OR Apache-2.0 (the Windows setup is built from an adapted + copy of tauri-bundler's NSIS template, apps/lutra-desktop/installer/) * unicode-ident and ICU4X crates (via Tauri) — Unicode License v3 (Unicode-3.0) * notify (file watching) — Creative Commons Zero v1.0 Universal (CC0-1.0) diff --git a/apps/lutra-desktop/Cargo.toml b/apps/lutra-desktop/Cargo.toml index b12970c..2b39a55 100644 --- a/apps/lutra-desktop/Cargo.toml +++ b/apps/lutra-desktop/Cargo.toml @@ -29,6 +29,7 @@ windows = { version = "0.61.3", features = ["Win32_System_Com", "Win32_UI_Shell" xcap = "0.9.8" [dev-dependencies] +lutra-testkit.workspace = true tempfile.workspace = true [target.'cfg(windows)'.dev-dependencies] diff --git a/apps/lutra-desktop/installer/hooks.nsh b/apps/lutra-desktop/installer/hooks.nsh new file mode 100644 index 0000000..dbf508a --- /dev/null +++ b/apps/lutra-desktop/installer/hooks.nsh @@ -0,0 +1,55 @@ +; 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\.\OpenWithProgids`, +; leaving `.`'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 diff --git a/apps/lutra-desktop/installer/installer.nsi b/apps/lutra-desktop/installer/installer.nsi new file mode 100644 index 0000000..3c7e74d --- /dev/null +++ b/apps/lutra-desktop/installer/installer.nsi @@ -0,0 +1,997 @@ +Unicode true +; Lutra's NSIS installer template: tauri-bundler 2.10.2's +; `src/bundle/windows/nsis/installer.nsi` (https://github.com/tauri-apps/tauri, +; MIT OR Apache-2.0), changed only where a comment starts with "Lutra:". +; Selected by `bundle.windows.nsis.template` in `../tauri.conf.json`; compare +; it with the bundler's template when tauri-cli is updated. +ManifestDPIAware true +; Add in `dpiAwareness` `PerMonitorV2` to manifest for Windows 10 1607+ (note this should not affect lower versions since they should be able to ignore this and pick up `dpiAware` `true` set by `ManifestDPIAware true`) +; Currently undocumented on NSIS's website but is in the Docs folder of source tree, see +; https://github.com/kichik/nsis/blob/5fc0b87b819a9eec006df4967d08e522ddd651c9/Docs/src/attributes.but#L286-L300 +; https://github.com/tauri-apps/tauri/pull/10106 +ManifestDPIAwareness PerMonitorV2 + +!if "{{compression}}" == "none" + SetCompress off +!else + ; Set the compression algorithm. We default to LZMA. + SetCompressor /SOLID "{{compression}}" +!endif + +; Keep above !include to stay ahead of any plugin command +; see https://github.com/tauri-apps/tauri/pull/15422#discussion_r3289239624 +{{#if signed_plugins_path}} +!addplugindir "{{signed_plugins_path}}" +{{/if}} + +!include MUI2.nsh +!include FileFunc.nsh +!include x64.nsh +!include WordFunc.nsh +!include "utils.nsh" +!include "FileAssociation.nsh" +!include "Win\COM.nsh" +!include "Win\Propkey.nsh" +!include "Win\RestartManager.nsh" +!include "StrFunc.nsh" +${StrCase} +${StrLoc} + +{{#if installer_hooks}} +!include "{{installer_hooks}}" +{{/if}} + +!define WEBVIEW2APPGUID "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" + +!define MANUFACTURER "{{manufacturer}}" +!define PRODUCTNAME "{{product_name}}" +!define VERSION "{{version}}" +!define VERSIONWITHBUILD "{{version_with_build}}" +!define HOMEPAGE "{{homepage}}" +!define INSTALLMODE "{{install_mode}}" +!define LICENSE "{{license}}" +!define INSTALLERICON "{{installer_icon}}" +!define SIDEBARIMAGE "{{sidebar_image}}" +!define HEADERIMAGE "{{header_image}}" +!define UNINSTALLERICON "{{uninstaller_icon}}" +!define UNINSTALLERHEADERIMAGE "{{uninstaller_header_image}}" +!define MAINBINARYNAME "{{main_binary_name}}" +!define MAINBINARYSRCPATH "{{main_binary_path}}" +!define BUNDLEID "{{bundle_id}}" +!define COPYRIGHT "{{copyright}}" +!define OUTFILE "{{out_file}}" +!define ARCH "{{arch}}" +!define ADDITIONALPLUGINSPATH "{{additional_plugins_path}}" +!define ALLOWDOWNGRADES "{{allow_downgrades}}" +!define DISPLAYLANGUAGESELECTOR "{{display_language_selector}}" +!define INSTALLWEBVIEW2MODE "{{install_webview2_mode}}" +!define WEBVIEW2INSTALLERARGS "{{webview2_installer_args}}" +!define WEBVIEW2BOOTSTRAPPERPATH "{{webview2_bootstrapper_path}}" +!define WEBVIEW2INSTALLERPATH "{{webview2_installer_path}}" +!define MINIMUMWEBVIEW2VERSION "{{minimum_webview2_version}}" +!define UNINSTKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCTNAME}" +!define MANUKEY "Software\${MANUFACTURER}" +!define MANUPRODUCTKEY "${MANUKEY}\${PRODUCTNAME}" +!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}" +!define ESTIMATEDSIZE "{{estimated_size}}" +!define STARTMENUFOLDER "{{start_menu_folder}}" + +Var PassiveMode +Var UpdateMode +Var NoShortcutMode +Var WixMode +Var OldMainBinaryName + +Name "${PRODUCTNAME}" +BrandingText "${COPYRIGHT}" +OutFile "${OUTFILE}" + +; We don't actually use this value as default install path, +; it's just for nsis to append the product name folder in the directory selector +; https://nsis.sourceforge.io/Reference/InstallDir +!define PLACEHOLDER_INSTALL_DIR "placeholder\${PRODUCTNAME}" +InstallDir "${PLACEHOLDER_INSTALL_DIR}" + +VIProductVersion "${VERSIONWITHBUILD}" +VIAddVersionKey "ProductName" "${PRODUCTNAME}" +VIAddVersionKey "FileDescription" "${PRODUCTNAME}" +VIAddVersionKey "LegalCopyright" "${COPYRIGHT}" +VIAddVersionKey "FileVersion" "${VERSION}" +VIAddVersionKey "ProductVersion" "${VERSION}" + +# additional plugins +!addplugindir "${ADDITIONALPLUGINSPATH}" + +; Uninstaller signing command +!if "${UNINSTALLERSIGNCOMMAND}" != "" + !uninstfinalize '${UNINSTALLERSIGNCOMMAND}' +!endif + +; Handle install mode, `perUser`, `perMachine` or `both` +!if "${INSTALLMODE}" == "perMachine" + RequestExecutionLevel admin +!endif + +!if "${INSTALLMODE}" == "currentUser" + RequestExecutionLevel user +!endif + +!if "${INSTALLMODE}" == "both" + !define MULTIUSER_MUI + !define MULTIUSER_INSTALLMODE_INSTDIR "${PRODUCTNAME}" + !define MULTIUSER_INSTALLMODE_COMMANDLINE + !if "${ARCH}" == "x64" + !define MULTIUSER_USE_PROGRAMFILES64 + !else if "${ARCH}" == "arm64" + !define MULTIUSER_USE_PROGRAMFILES64 + !endif + !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_KEY "${UNINSTKEY}" + !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser" + !define MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME + !define MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation + !define MULTIUSER_EXECUTIONLEVEL Highest + !include MultiUser.nsh +!endif + +; Installer icon +!if "${INSTALLERICON}" != "" + !define MUI_ICON "${INSTALLERICON}" +!endif + +; Installer sidebar image +!if "${SIDEBARIMAGE}" != "" + !define MUI_WELCOMEFINISHPAGE_BITMAP "${SIDEBARIMAGE}" +!endif + +; Enable header images for installer and uninstaller pages when either image is configured. +!if "${HEADERIMAGE}" != "" + !define MUI_HEADERIMAGE +!else if "${UNINSTALLERHEADERIMAGE}" != "" + !define MUI_HEADERIMAGE +!endif + +; Installer header image +!if "${HEADERIMAGE}" != "" + !define MUI_HEADERIMAGE_BITMAP "${HEADERIMAGE}" +!endif + +; Uninstaller header image +!if "${UNINSTALLERHEADERIMAGE}" != "" + !define MUI_HEADERIMAGE_UNBITMAP "${UNINSTALLERHEADERIMAGE}" +!endif + +; Uninstaller icon +!if "${UNINSTALLERICON}" != "" + !define MUI_UNICON "${UNINSTALLERICON}" +!endif + +; Define registry key to store installer language +!define MUI_LANGDLL_REGISTRY_ROOT "HKCU" +!define MUI_LANGDLL_REGISTRY_KEY "${MANUPRODUCTKEY}" +!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language" + +; Installer pages, must be ordered as they appear +; 1. Welcome Page +!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive +!insertmacro MUI_PAGE_WELCOME + +; 2. License Page (if defined) +!if "${LICENSE}" != "" + !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive + !insertmacro MUI_PAGE_LICENSE "${LICENSE}" +!endif + +; 3. Install mode (if it is set to `both`) +!if "${INSTALLMODE}" == "both" + !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive + !insertmacro MULTIUSER_PAGE_INSTALLMODE +!endif + +; 4. Custom page to ask user if he wants to reinstall/uninstall +; only if a previous installation was detected +Var ReinstallPageCheck +Page custom PageReinstall PageLeaveReinstall +Function PageReinstall + ; Uninstall previous WiX installation if exists. + ; + ; A WiX installer stores the installation info in registry + ; using a UUID and so we have to loop through all keys under + ; `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall` + ; and check if `DisplayName` and `Publisher` keys match ${PRODUCTNAME} and ${MANUFACTURER} + ; + ; This has a potential issue that there maybe another installation that matches + ; our ${PRODUCTNAME} and ${MANUFACTURER} but wasn't installed by our WiX installer, + ; however, this should be fine since the user will have to confirm the uninstallation + ; and they can chose to abort it if doesn't make sense. + StrCpy $0 0 + wix_loop: + EnumRegKey $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" $0 + StrCmp $1 "" wix_loop_done ; Exit loop if there is no more keys to loop on + IntOp $0 $0 + 1 + ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "DisplayName" + ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "Publisher" + StrCmp "$R0$R1" "${PRODUCTNAME}${MANUFACTURER}" 0 wix_loop + ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" "UninstallString" + ${StrCase} $R1 $R0 "L" + ${StrLoc} $R0 $R1 "msiexec" ">" + StrCmp $R0 0 0 wix_loop_done + StrCpy $WixMode 1 + StrCpy $R6 "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$1" + Goto compare_version + wix_loop_done: + + ; Check if there is an existing installation, if not, abort the reinstall page + ReadRegStr $R0 SHCTX "${UNINSTKEY}" "" + ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString" + ${IfThen} "$R0$R1" == "" ${|} Abort ${|} + + ; Compare this installar version with the existing installation + ; and modify the messages presented to the user accordingly + compare_version: + StrCpy $R4 "$(older)" + ${If} $WixMode = 1 + ReadRegStr $R0 HKLM "$R6" "DisplayVersion" + ${Else} + ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion" + ${EndIf} + ${IfThen} $R0 == "" ${|} StrCpy $R4 "$(unknown)" ${|} + + nsis_tauri_utils::SemverCompare "${VERSION}" $R0 + Pop $R0 + ; Reinstalling the same version + ${If} $R0 = 0 + StrCpy $R1 "$(alreadyInstalledLong)" + StrCpy $R2 "$(addOrReinstall)" + StrCpy $R3 "$(uninstallApp)" + !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(chooseMaintenanceOption)" + ; Upgrading + ${ElseIf} $R0 = 1 + StrCpy $R1 "$(olderOrUnknownVersionInstalled)" + StrCpy $R2 "$(uninstallBeforeInstalling)" + StrCpy $R3 "$(dontUninstall)" + !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(choowHowToInstall)" + ; Downgrading + ${ElseIf} $R0 = -1 + StrCpy $R1 "$(newerVersionInstalled)" + StrCpy $R2 "$(uninstallBeforeInstalling)" + !if "${ALLOWDOWNGRADES}" == "true" + StrCpy $R3 "$(dontUninstall)" + !else + StrCpy $R3 "$(dontUninstallDowngrade)" + !endif + !insertmacro MUI_HEADER_TEXT "$(alreadyInstalled)" "$(choowHowToInstall)" + ${Else} + Abort + ${EndIf} + + ; Skip showing the page if passive + ; + ; Note that we don't call this earlier at the beginning + ; of this function because we need to populate some variables + ; related to current installed version if detected and whether + ; we are downgrading or not. + ${If} $PassiveMode = 1 + Call PageLeaveReinstall + ${Else} + nsDialogs::Create 1018 + Pop $R4 + ${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|} + + ${NSD_CreateLabel} 0 0 100% 24u $R1 + Pop $R1 + + ${NSD_CreateRadioButton} 30u 50u -30u 8u $R2 + Pop $R2 + ${NSD_OnClick} $R2 PageReinstallUpdateSelection + + ${NSD_CreateRadioButton} 30u 70u -30u 8u $R3 + Pop $R3 + ; Disable this radio button if downgrading and downgrades are disabled + !if "${ALLOWDOWNGRADES}" == "false" + ${IfThen} $R0 = -1 ${|} EnableWindow $R3 0 ${|} + !endif + ${NSD_OnClick} $R3 PageReinstallUpdateSelection + + ; Check the first radio button if this the first time + ; we enter this page or if the second button wasn't + ; selected the last time we were on this page + ${If} $ReinstallPageCheck <> 2 + SendMessage $R2 ${BM_SETCHECK} ${BST_CHECKED} 0 + ${Else} + SendMessage $R3 ${BM_SETCHECK} ${BST_CHECKED} 0 + ${EndIf} + + ${NSD_SetFocus} $R2 + nsDialogs::Show + ${EndIf} +FunctionEnd +Function PageReinstallUpdateSelection + ${NSD_GetState} $R2 $R1 + ${If} $R1 == ${BST_CHECKED} + StrCpy $ReinstallPageCheck 1 + ${Else} + StrCpy $ReinstallPageCheck 2 + ${EndIf} +FunctionEnd +Function PageLeaveReinstall + ${NSD_GetState} $R2 $R1 + + ; If migrating from Wix, always uninstall + ${If} $WixMode = 1 + Goto reinst_uninstall + ${EndIf} + + ; In update mode, always proceeds without uninstalling + ${If} $UpdateMode = 1 + Goto reinst_done + ${EndIf} + + ; $R0 holds whether same(0)/upgrading(1)/downgrading(-1) version + ; $R1 holds the radio buttons state: + ; 1 => first choice was selected + ; 0 => second choice was selected + ${If} $R0 = 0 ; Same version, proceed + ${If} $R1 = 1 ; User chose to add/reinstall + Goto reinst_done + ${Else} ; User chose to uninstall + Goto reinst_uninstall + ${EndIf} + ${ElseIf} $R0 = 1 ; Upgrading + ${If} $R1 = 1 ; User chose to uninstall + Goto reinst_uninstall + ${Else} + Goto reinst_done ; User chose NOT to uninstall + ${EndIf} + ${ElseIf} $R0 = -1 ; Downgrading + ${If} $R1 = 1 ; User chose to uninstall + Goto reinst_uninstall + ${Else} + Goto reinst_done ; User chose NOT to uninstall + ${EndIf} + ${EndIf} + + reinst_uninstall: + HideWindow + ClearErrors + + ${If} $WixMode = 1 + ReadRegStr $R1 HKLM "$R6" "UninstallString" + ExecWait '$R1' $0 + ${Else} + ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" "" + ReadRegStr $R1 SHCTX "${UNINSTKEY}" "UninstallString" + ${IfThen} $UpdateMode = 1 ${|} StrCpy $R1 "$R1 /UPDATE" ${|} ; append /UPDATE + ${IfThen} $PassiveMode = 1 ${|} StrCpy $R1 "$R1 /P" ${|} ; append /P + StrCpy $R1 "$R1 _?=$4" ; append uninstall directory + ExecWait '$R1' $0 + ${EndIf} + + BringToFront + + ${IfThen} ${Errors} ${|} StrCpy $0 2 ${|} ; ExecWait failed, set fake exit code + + ${If} $0 <> 0 + ${OrIf} ${FileExists} "$INSTDIR\${MAINBINARYNAME}.exe" + ; User cancelled wix uninstaller? return to select un/reinstall page + ${If} $WixMode = 1 + ${AndIf} $0 = 1602 + Abort + ${EndIf} + + ; User cancelled NSIS uninstaller? return to select un/reinstall page + ${If} $0 = 1 + Abort + ${EndIf} + + ; Other errors? show generic error message and return to select un/reinstall page + MessageBox MB_ICONEXCLAMATION "$(unableToUninstall)" + Abort + ${EndIf} + reinst_done: +FunctionEnd + +; 5. Choose install directory page +!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive +!insertmacro MUI_PAGE_DIRECTORY + +; 6. Start menu shortcut page +Var AppStartMenuFolder +!if "${STARTMENUFOLDER}" != "" + !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive + !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${STARTMENUFOLDER}" +!else + !define MUI_PAGE_CUSTOMFUNCTION_PRE Skip +!endif +!insertmacro MUI_PAGE_STARTMENU Application $AppStartMenuFolder + +; 7. Installation page +!insertmacro MUI_PAGE_INSTFILES + +; 8. Finish page +; +; Don't auto jump to finish page after installation page, +; because the installation page has useful info that can be used debug any issues with the installer. +!define MUI_FINISHPAGE_NOAUTOCLOSE +; Use show readme button in the finish page as a button create a desktop shortcut +!define MUI_FINISHPAGE_SHOWREADME +!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(createDesktop)" +!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateOrUpdateDesktopShortcut +; Show run app after installation. +!define MUI_FINISHPAGE_RUN +!define MUI_FINISHPAGE_RUN_FUNCTION RunMainBinary +!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive +!insertmacro MUI_PAGE_FINISH + +; Lutra: the finish page starts the app through Explorer instead of +; `nsis_tauri_utils::RunAsUser`. RunAsUser calls ShellExecute on the setup's +; UI thread, which creates the new process suspended, runs the shell's and +; the virus scanner's checks of the freshly written, unsigned exe and only +; then resumes it. On a PC where that check stalls (seen with Norton 360), +; the setup window stops responding, Windows ends it, and the app process is +; left suspended for good. `Exec` returns as soon as Explorer is started; +; Explorer runs those checks and starts the app as the signed-in user. +Function RunMainBinary + Exec '"$WINDIR\explorer.exe" "$INSTDIR\${MAINBINARYNAME}.exe"' +FunctionEnd + +; Uninstaller Pages +; 1. Confirm uninstall page +Var DeleteAppDataCheckbox +Var DeleteAppDataCheckboxState +!define /ifndef WS_EX_LAYOUTRTL 0x00400000 +!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ConfirmShow +Function un.ConfirmShow ; Add add a `Delete app data` check box + ; $1 inner dialog HWND + ; $2 window DPI + ; $3 style + ; $4 x + ; $5 y + ; $6 width + ; $7 height + FindWindow $1 "#32770" "" $HWNDPARENT ; Find inner dialog + System::Call "user32::GetDpiForWindow(p r1) i .r2" + ${If} $(^RTL) = 1 + StrCpy $3 "${__NSD_CheckBox_EXSTYLE} | ${WS_EX_LAYOUTRTL}" + IntOp $4 50 * $2 + ${Else} + StrCpy $3 "${__NSD_CheckBox_EXSTYLE}" + IntOp $4 0 * $2 + ${EndIf} + IntOp $5 100 * $2 + IntOp $6 400 * $2 + IntOp $7 25 * $2 + IntOp $4 $4 / 96 + IntOp $5 $5 / 96 + IntOp $6 $6 / 96 + IntOp $7 $7 / 96 + System::Call 'user32::CreateWindowEx(i r3, w "${__NSD_CheckBox_CLASS}", w "$(deleteAppData)", i ${__NSD_CheckBox_STYLE}, i r4, i r5, i r6, i r7, p r1, i0, i0, i0) i .s' + Pop $DeleteAppDataCheckbox + SendMessage $HWNDPARENT ${WM_GETFONT} 0 0 $1 + SendMessage $DeleteAppDataCheckbox ${WM_SETFONT} $1 1 +FunctionEnd +!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.ConfirmLeave +Function un.ConfirmLeave + SendMessage $DeleteAppDataCheckbox ${BM_GETCHECK} 0 0 $DeleteAppDataCheckboxState +FunctionEnd +!define MUI_PAGE_CUSTOMFUNCTION_PRE un.SkipIfPassive +!insertmacro MUI_UNPAGE_CONFIRM + +; 2. Uninstalling Page +!insertmacro MUI_UNPAGE_INSTFILES + +;Languages +{{#each languages}} +!insertmacro MUI_LANGUAGE "{{this}}" +{{/each}} +!insertmacro MUI_RESERVEFILE_LANGDLL +{{#each language_files}} + !include "{{this}}" +{{/each}} + +Function .onInit + ${GetOptions} $CMDLINE "/P" $PassiveMode + ${IfNot} ${Errors} + StrCpy $PassiveMode 1 + ${EndIf} + + ${GetOptions} $CMDLINE "/NS" $NoShortcutMode + ${IfNot} ${Errors} + StrCpy $NoShortcutMode 1 + ${EndIf} + + ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode + ${IfNot} ${Errors} + StrCpy $UpdateMode 1 + ${EndIf} + + !if "${DISPLAYLANGUAGESELECTOR}" == "true" + !insertmacro MUI_LANGDLL_DISPLAY + !endif + + !insertmacro SetContext + + ${If} $INSTDIR == "${PLACEHOLDER_INSTALL_DIR}" + ; Set default install location + !if "${INSTALLMODE}" == "perMachine" + ${If} ${RunningX64} + !if "${ARCH}" == "x64" + StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" + !else if "${ARCH}" == "arm64" + StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}" + !else + StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" + !endif + ${Else} + StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}" + ${EndIf} + !else if "${INSTALLMODE}" == "currentUser" + StrCpy $INSTDIR "$LOCALAPPDATA\${PRODUCTNAME}" + !endif + + Call RestorePreviousInstallLocation + ${EndIf} + + + !if "${INSTALLMODE}" == "both" + !insertmacro MULTIUSER_INIT + !endif + + ; Abort downgrades if they are disabled, in the modes that skip the reinstall page choice: + ; silent, passive and update + !if "${ALLOWDOWNGRADES}" == "false" + ${If} ${Silent} + ${OrIf} $PassiveMode = 1 + ${OrIf} $UpdateMode = 1 + ReadRegStr $R0 SHCTX "${UNINSTKEY}" "DisplayVersion" + nsis_tauri_utils::SemverCompare "${VERSION}" $R0 + Pop $R0 + ; If downgrading + ${If} $R0 = -1 + ${If} ${Silent} + System::Call 'kernel32::AttachConsole(i -1)i.r0' + ${If} $0 <> 0 + System::Call 'kernel32::GetStdHandle(i -11)i.r0' + System::call 'kernel32::SetConsoleTextAttribute(i r0, i 0x0004)' ; set red color + FileWrite $0 "$(silentDowngrades)" + ${EndIf} + ${Else} + MessageBox MB_ICONSTOP "$(silentDowngrades)" + ${EndIf} + Abort + ${EndIf} + ${EndIf} + !endif +FunctionEnd + +Section WebView2 + ; Check if Webview2 is already installed and skip this section + ${If} ${RunningX64} + ReadRegStr $4 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" + ${Else} + ReadRegStr $4 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" + ${EndIf} + ${If} $4 == "" + ReadRegStr $4 HKCU "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2APPGUID}" "pv" + ${EndIf} + + ${If} $4 == "" + ; Webview2 installation + ; + ; Skip if updating + ${If} $UpdateMode <> 1 + !if "${INSTALLWEBVIEW2MODE}" == "downloadBootstrapper" + Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" + DetailPrint "$(webview2Downloading)" + NSISdl::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Pop $0 + ${If} $0 == "success" + DetailPrint "$(webview2DownloadSuccess)" + ${Else} + DetailPrint "$(webview2DownloadError)" + Abort "$(webview2AbortError)" + ${EndIf} + StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Goto install_webview2 + !endif + + !if "${INSTALLWEBVIEW2MODE}" == "embedBootstrapper" + Delete "$TEMP\MicrosoftEdgeWebview2Setup.exe" + File "/oname=$TEMP\MicrosoftEdgeWebview2Setup.exe" "${WEBVIEW2BOOTSTRAPPERPATH}" + DetailPrint "$(installingWebview2)" + StrCpy $6 "$TEMP\MicrosoftEdgeWebview2Setup.exe" + Goto install_webview2 + !endif + + !if "${INSTALLWEBVIEW2MODE}" == "offlineInstaller" + Delete "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" + File "/oname=$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" "${WEBVIEW2INSTALLERPATH}" + DetailPrint "$(installingWebview2)" + StrCpy $6 "$TEMP\MicrosoftEdgeWebView2RuntimeInstaller.exe" + Goto install_webview2 + !endif + + Goto webview2_done + + install_webview2: + DetailPrint "$(installingWebview2)" + ; $6 holds the path to the webview2 installer + ExecWait "$6 ${WEBVIEW2INSTALLERARGS} /install" $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + DetailPrint "$(webview2InstallError)" + Abort "$(webview2AbortError)" + ${EndIf} + webview2_done: + ${EndIf} + ${Else} + !if "${MINIMUMWEBVIEW2VERSION}" != "" + ${VersionCompare} "${MINIMUMWEBVIEW2VERSION}" "$4" $R0 + ${If} $R0 = 1 + update_webview: + DetailPrint "$(installingWebview2)" + ${If} ${RunningX64} + ReadRegStr $R1 HKLM "SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate" "path" + ${Else} + ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 == "" + ReadRegStr $R1 HKCU "SOFTWARE\Microsoft\EdgeUpdate" "path" + ${EndIf} + ${If} $R1 != "" + ; Chromium updater docs: https://source.chromium.org/chromium/chromium/src/+/main:docs/updater/user_manual.md + ; Modified from "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft EdgeWebView\ModifyPath" + ExecWait `"$R1" /install appguid=${WEBVIEW2APPGUID}&needsadmin=true` $1 + ${If} $1 = 0 + DetailPrint "$(webview2InstallSuccess)" + ${Else} + MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(webview2InstallError)" IDIGNORE ignore IDRETRY update_webview + Quit + ignore: + ${EndIf} + ${EndIf} + ${EndIf} + !endif + ${EndIf} +SectionEnd + +Section Install + SetOutPath $INSTDIR + + !ifmacrodef NSIS_HOOK_PREINSTALL + !insertmacro NSIS_HOOK_PREINSTALL + !endif + + !insertmacro CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}" + + ; Copy main executable + File "${MAINBINARYSRCPATH}" + + ; Copy resources + {{#each resources_dirs}} + CreateDirectory "$INSTDIR\\{{this}}" + {{/each}} + {{#each resources}} + File /a "/oname={{this.[1]}}" "{{no-escape @key}}" + {{/each}} + + ; Copy external binaries + {{#each binaries}} + File /a "/oname={{this}}" "{{no-escape @key}}" + {{/each}} + + ; Create file associations + {{#each file_associations as |association| ~}} + {{#each association.ext as |ext| ~}} + !insertmacro APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${PRODUCTNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\"" + {{/each}} + {{/each}} + + ; Register deep links + {{#each deep_link_protocols as |protocol| ~}} + WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "URL Protocol" "" + WriteRegStr SHCTX "Software\Classes\\{{protocol}}" "" "URL:${BUNDLEID} protocol" + WriteRegStr SHCTX "Software\Classes\\{{protocol}}\DefaultIcon" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\",0" + WriteRegStr SHCTX "Software\Classes\\{{protocol}}\shell\open\command" "" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\"" + {{/each}} + + ; Create uninstaller + WriteUninstaller "$INSTDIR\uninstall.exe" + + ; Save $INSTDIR in registry for future installations + WriteRegStr SHCTX "${MANUPRODUCTKEY}" "" $INSTDIR + + !if "${INSTALLMODE}" == "both" + ; Save install mode to be selected by default for the next installation such as updating + ; or when uninstalling + WriteRegStr SHCTX "${UNINSTKEY}" $MultiUser.InstallMode 1 + !endif + + ; Remove old main binary if it doesn't match new main binary name + ReadRegStr $OldMainBinaryName SHCTX "${UNINSTKEY}" "MainBinaryName" + ${If} $OldMainBinaryName != "" + ${AndIf} $OldMainBinaryName != "${MAINBINARYNAME}.exe" + Delete "$INSTDIR\$OldMainBinaryName" + ${EndIf} + + ; Save current MAINBINARYNAME for future updates + WriteRegStr SHCTX "${UNINSTKEY}" "MainBinaryName" "${MAINBINARYNAME}.exe" + + ; Registry information for add/remove programs + WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${PRODUCTNAME}" + WriteRegStr SHCTX "${UNINSTKEY}" "DisplayIcon" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\"" + WriteRegStr SHCTX "${UNINSTKEY}" "DisplayVersion" "${VERSION}" + WriteRegStr SHCTX "${UNINSTKEY}" "Publisher" "${MANUFACTURER}" + WriteRegStr SHCTX "${UNINSTKEY}" "InstallLocation" "$\"$INSTDIR$\"" + WriteRegStr SHCTX "${UNINSTKEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\"" + WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1" + WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1" + + ${GetSize} "$INSTDIR" "/M=uninstall.exe /S=0K /G=0" $0 $1 $2 + IntOp $0 $0 + ${ESTIMATEDSIZE} + IntFmt $0 "0x%08X" $0 + WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "$0" + + !if "${HOMEPAGE}" != "" + WriteRegStr SHCTX "${UNINSTKEY}" "URLInfoAbout" "${HOMEPAGE}" + WriteRegStr SHCTX "${UNINSTKEY}" "URLUpdateInfo" "${HOMEPAGE}" + WriteRegStr SHCTX "${UNINSTKEY}" "HelpLink" "${HOMEPAGE}" + !endif + + ; Create start menu shortcut + !insertmacro MUI_STARTMENU_WRITE_BEGIN Application + Call CreateOrUpdateStartMenuShortcut + !insertmacro MUI_STARTMENU_WRITE_END + + ; Create desktop shortcut for silent and passive installers + ; because finish page will be skipped + ${If} $PassiveMode = 1 + ${OrIf} ${Silent} + Call CreateOrUpdateDesktopShortcut + ${EndIf} + + !ifmacrodef NSIS_HOOK_POSTINSTALL + !insertmacro NSIS_HOOK_POSTINSTALL + !endif + + ; Auto close this page for passive mode + ${If} $PassiveMode = 1 + SetAutoClose true + ${EndIf} +SectionEnd + +Function .onInstSuccess + ; Check for `/R` flag only in silent and passive installers because + ; GUI installer has a toggle for the user to (re)start the app + ${If} $PassiveMode = 1 + ${OrIf} ${Silent} + ${GetOptions} $CMDLINE "/R" $R0 + ${IfNot} ${Errors} + ${GetOptions} $CMDLINE "/ARGS" $R0 + nsis_tauri_utils::RunAsUser "$INSTDIR\${MAINBINARYNAME}.exe" "$R0" + ${EndIf} + ${EndIf} +FunctionEnd + +Function un.onInit + !insertmacro SetContext + + !if "${INSTALLMODE}" == "both" + !insertmacro MULTIUSER_UNINIT + !endif + + !insertmacro MUI_UNGETLANGUAGE + + ${GetOptions} $CMDLINE "/P" $PassiveMode + ${IfNot} ${Errors} + StrCpy $PassiveMode 1 + ${EndIf} + + ${GetOptions} $CMDLINE "/UPDATE" $UpdateMode + ${IfNot} ${Errors} + StrCpy $UpdateMode 1 + ${EndIf} +FunctionEnd + +Section Uninstall + + !ifmacrodef NSIS_HOOK_PREUNINSTALL + !insertmacro NSIS_HOOK_PREUNINSTALL + !endif + + !insertmacro CheckIfAppIsRunning "$INSTDIR\${MAINBINARYNAME}.exe" "${PRODUCTNAME}" + + ; Delete the app directory and its content from disk + ; Copy main executable + Delete "$INSTDIR\${MAINBINARYNAME}.exe" + + ; Delete resources + {{#each resources}} + Delete "$INSTDIR\\{{this.[1]}}" + {{/each}} + + ; Delete external binaries + {{#each binaries}} + Delete "$INSTDIR\\{{this}}" + {{/each}} + + ; Delete app associations + {{#each file_associations as |association| ~}} + {{#each association.ext as |ext| ~}} + !insertmacro APP_UNASSOCIATE "{{ext}}" "{{or association.name ext}}" + {{/each}} + {{/each}} + + ; Delete deep links + {{#each deep_link_protocols as |protocol| ~}} + ReadRegStr $R7 SHCTX "Software\Classes\\{{protocol}}\shell\open\command" "" + ${If} $R7 == "$\"$INSTDIR\${MAINBINARYNAME}.exe$\" $\"%1$\"" + DeleteRegKey SHCTX "Software\Classes\\{{protocol}}" + ${EndIf} + {{/each}} + + + ; Delete uninstaller + Delete "$INSTDIR\uninstall.exe" + + {{#each resources_ancestors}} + RMDir /REBOOTOK "$INSTDIR\\{{this}}" + {{/each}} + RMDir "$INSTDIR" + + ; Remove shortcuts if not updating + ${If} $UpdateMode <> 1 + !insertmacro DeleteAppUserModelId + + ; Remove start menu shortcut + !insertmacro MUI_STARTMENU_GETFOLDER Application $AppStartMenuFolder + !insertmacro IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + Pop $0 + ${If} $0 = 1 + !insertmacro UnpinShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" + Delete "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" + RMDir "$SMPROGRAMS\$AppStartMenuFolder" + ${EndIf} + !insertmacro IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + Pop $0 + ${If} $0 = 1 + !insertmacro UnpinShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk" + Delete "$SMPROGRAMS\${PRODUCTNAME}.lnk" + ${EndIf} + + ; Remove desktop shortcuts + !insertmacro IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + Pop $0 + ${If} $0 = 1 + !insertmacro UnpinShortcut "$DESKTOP\${PRODUCTNAME}.lnk" + Delete "$DESKTOP\${PRODUCTNAME}.lnk" + ${EndIf} + ${EndIf} + + ; Remove registry information for add/remove programs + !if "${INSTALLMODE}" == "both" + DeleteRegKey SHCTX "${UNINSTKEY}" + !else if "${INSTALLMODE}" == "perMachine" + DeleteRegKey HKLM "${UNINSTKEY}" + !else + DeleteRegKey HKCU "${UNINSTKEY}" + !endif + + ; Removes the Autostart entry for ${PRODUCTNAME} from the HKCU Run key if it exists. + ; This ensures the program does not launch automatically after uninstallation if it exists. + ; If it doesn't exist, it does nothing. + ; We do this when not updating (to preserve the registry value on updates) + ${If} $UpdateMode <> 1 + DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${PRODUCTNAME}" + ${EndIf} + + ; Delete app data if the checkbox is selected + ; and if not updating + ${If} $DeleteAppDataCheckboxState = 1 + ${AndIf} $UpdateMode <> 1 + ; Clear the install location $INSTDIR from registry + DeleteRegKey SHCTX "${MANUPRODUCTKEY}" + DeleteRegKey /ifempty SHCTX "${MANUKEY}" + + ; Clear the install language from registry + DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language" + DeleteRegKey /ifempty HKCU "${MANUPRODUCTKEY}" + DeleteRegKey /ifempty HKCU "${MANUKEY}" + + SetShellVarContext current + RmDir /r "$APPDATA\${BUNDLEID}" + RmDir /r "$LOCALAPPDATA\${BUNDLEID}" + ${EndIf} + + !ifmacrodef NSIS_HOOK_POSTUNINSTALL + !insertmacro NSIS_HOOK_POSTUNINSTALL + !endif + + ; Auto close if passive mode or updating + ${If} $PassiveMode = 1 + ${OrIf} $UpdateMode = 1 + SetAutoClose true + ${EndIf} +SectionEnd + +Function RestorePreviousInstallLocation + ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" "" + StrCmp $4 "" +2 0 + StrCpy $INSTDIR $4 +FunctionEnd + +Function Skip + Abort +FunctionEnd + +Function SkipIfPassive + ${IfThen} $PassiveMode = 1 ${|} Abort ${|} +FunctionEnd +Function un.SkipIfPassive + ${IfThen} $PassiveMode = 1 ${|} Abort ${|} +FunctionEnd + +Function CreateOrUpdateStartMenuShortcut + ; We used to use product name as MAINBINARYNAME + ; migrate old shortcuts to target the new MAINBINARYNAME + StrCpy $R0 0 + + !insertmacro IsShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" + Pop $0 + ${If} $0 = 1 + !insertmacro SetShortcutTarget "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + StrCpy $R0 1 + ${EndIf} + + !insertmacro IsShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" + Pop $0 + ${If} $0 = 1 + !insertmacro SetShortcutTarget "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + StrCpy $R0 1 + ${EndIf} + + ${If} $R0 = 1 + Return + ${EndIf} + + ; Skip creating shortcut if in update mode or no shortcut mode + ; but always create if migrating from wix + ${If} $WixMode = 0 + ${If} $UpdateMode = 1 + ${OrIf} $NoShortcutMode = 1 + Return + ${EndIf} + ${EndIf} + + !if "${STARTMENUFOLDER}" != "" + CreateDirectory "$SMPROGRAMS\$AppStartMenuFolder" + CreateShortcut "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + !insertmacro SetLnkAppUserModelId "$SMPROGRAMS\$AppStartMenuFolder\${PRODUCTNAME}.lnk" + !else + CreateShortcut "$SMPROGRAMS\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + !insertmacro SetLnkAppUserModelId "$SMPROGRAMS\${PRODUCTNAME}.lnk" + !endif +FunctionEnd + +Function CreateOrUpdateDesktopShortcut + ; We used to use product name as MAINBINARYNAME + ; migrate old shortcuts to target the new MAINBINARYNAME + !insertmacro IsShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\$OldMainBinaryName" + Pop $0 + ${If} $0 = 1 + !insertmacro SetShortcutTarget "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + Return + ${EndIf} + + ; Skip creating shortcut if in update mode or no shortcut mode + ; but always create if migrating from wix + ${If} $WixMode = 0 + ${If} $UpdateMode = 1 + ${OrIf} $NoShortcutMode = 1 + Return + ${EndIf} + ${EndIf} + + CreateShortcut "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe" + !insertmacro SetLnkAppUserModelId "$DESKTOP\${PRODUCTNAME}.lnk" +FunctionEnd diff --git a/apps/lutra-desktop/src/args.rs b/apps/lutra-desktop/src/args.rs index cd87bda..1d87874 100644 --- a/apps/lutra-desktop/src/args.rs +++ b/apps/lutra-desktop/src/args.rs @@ -10,7 +10,7 @@ pub struct Args { pub control: Option, /// Isolated data directory (`--data-dir PATH`), see [`crate::datadir`]. pub data_dir: Option, - /// Folder or file to open. + /// Folder or file to open (see [`crate::open`]). pub path: Option, /// `--help` was given. pub help: bool, @@ -21,6 +21,9 @@ pub struct Args { /// Usage text for `--help`. pub const USAGE: &str = "usage: lutra-desktop [--control PORT] [--data-dir DIR] [PATH] + PATH a folder to open as the project, or a file to open in the + project around it (its Git or Composer root, else its + folder); a running Lutra takes it over --control PORT serve the JSON control channel on 127.0.0.1:PORT; without --data-dir or LUTRA_DATA_DIR the data lives in /lutra-control/PORT @@ -143,6 +146,20 @@ mod tests { assert!(p(&["a", "b"]).is_err()); } + #[test] + fn takes_a_bare_file_path_from_open_with() { + let a = p(&[r"C:\Users\me\My Projects\shop\src\Kernel.php"]).unwrap(); + assert_eq!( + a.path, + Some(PathBuf::from( + r"C:\Users\me\My Projects\shop\src\Kernel.php" + )) + ); + assert_eq!(a.control, None); + let b = parse_os([OsString::from("/home/me/app/index.php")]).unwrap(); + assert_eq!(b.path, Some(PathBuf::from("/home/me/app/index.php"))); + } + #[test] fn reads_raw_arguments() { let a = parse_os([OsString::from("--control"), OsString::from("7937")]).unwrap(); diff --git a/apps/lutra-desktop/src/host.rs b/apps/lutra-desktop/src/host.rs index 894e54b..088831d 100644 --- a/apps/lutra-desktop/src/host.rs +++ b/apps/lutra-desktop/src/host.rs @@ -198,16 +198,27 @@ impl Host { /// # Errors /// The engine's error, e.g. when the folder does not exist. pub fn open_project(&self, path: &Path) -> Result { - let path = if path.is_absolute() { - path.to_path_buf() - } else { - std::env::current_dir() - .map(|dir| dir.join(path)) - .unwrap_or_else(|_| path.to_path_buf()) - }; + let path = crate::open::absolute(path); self.run("project.open", json!({ "path": path })) } + /// Opens the path given on the command line: a file opens in a tab + /// inside the project [`crate::open::project_root`] picks for it, + /// anything else as the project (see [`Host::open_project`]). + /// + /// # Errors + /// The engine's error, e.g. when the path does not exist. + pub fn open_path(&self, path: &Path) -> Result { + let path = crate::open::absolute(path); + if !path.is_file() { + return self.open_project(&path); + } + let root = crate::open::project_root(&path) + .ok_or_else(|| EngineError::Failed(format!("{} has no folder", path.display())))?; + self.open_project(&root)?; + self.run("file.open", json!({ "path": path })) + } + /// Sends the window the events that describe the current state (the open /// project and its buffers), then the notifications and `watchFailed` /// events published before it was ready, for a frontend that just diff --git a/apps/lutra-desktop/src/instance.rs b/apps/lutra-desktop/src/instance.rs index edcc7c9..1e9a02c 100644 --- a/apps/lutra-desktop/src/instance.rs +++ b/apps/lutra-desktop/src/instance.rs @@ -45,7 +45,9 @@ pub fn rendezvous_dir(args: &Args, isolated: Option<&Path>) -> Option { } } -/// Forwards `path` to a running instance found through `dir`. +/// Forwards `path` to a running instance found through `dir` (see +/// [`open_in`]) and brings its window to the front, also when opening +/// fails. A failed focus is ignored: the path is already open. /// /// # Returns /// `Ok(true)` if an instance took the request (this process should exit), @@ -58,17 +60,45 @@ pub fn forward(dir: &Path, path: Option<&Path>) -> Result { Ok((_, client)) => client, Err(Unavailable::Missing | Unavailable::Stale(_)) => return Ok(false), }; - if let Some(path) = path { - let path = std::path::absolute(path).map_err(|e| e.to_string())?; - let opened = if path.is_dir() { - client.open_folder(&path).map(|_| ()) - } else { - client.open_file(&path).map(|_| ()) - }; - opened.map_err(|e| format!("the running Lutra cannot open {}: {e}", path.display()))?; - } + let opened = match path { + Some(path) => { + let path = std::path::absolute(path).map_err(|e| e.to_string())?; + open_in(&mut client, &path) + .map_err(|e| format!("the running Lutra cannot open {}: {e}", path.display())) + } + None => Ok(()), + }; let _ = client.focus(); - Ok(true) + opened.map(|()| true) +} + +/// Opens `path` in the instance behind `client`: a folder as the project, +/// a file in a tab. A file the open project cannot take (it lies outside, +/// or no project is open) opens inside the project +/// [`crate::open::project_root`] picks for it; the engine refuses to close +/// a project with unsaved changes, so nothing is lost. +/// +/// # Errors +/// The engine's error for the file, or for switching the project. +fn open_in(client: &mut client::Client, path: &Path) -> Result<(), client::ClientError> { + if path.is_dir() { + return client.open_folder(path).map(|_| ()); + } + let open_file = |client: &mut client::Client| { + let text = path.to_string_lossy(); + client + .execute("file.open", serde_json::json!({ "path": text })) + .map(|_| ()) + }; + let first = match open_file(client) { + Ok(()) => return Ok(()), + Err(e) => e, + }; + let Some(root) = crate::open::project_root(path) else { + return Err(first); + }; + client.open_folder(&root)?; + open_file(client) } /// This process's claim on the rendezvous directory. @@ -160,4 +190,77 @@ mod tests { .unwrap(); assert_eq!(forward(dir.path(), None), Ok(false), "stale file"); } + + /// A running instance on a bare engine, registered in `dir`. + fn running( + dir: &Path, + ) -> ( + Arc, + lutra_control::ServerHandle, + ) { + let backend = Arc::new(lutra_testkit::EngineBackend::new()); + let token = rendezvous::new_token().unwrap(); + let server = lutra_control::start_with_token(0, backend.clone(), &token).unwrap(); + let instance = Instance { + port: server.local_addr().port(), + token, + pid: std::process::id(), + version: env!("CARGO_PKG_VERSION").into(), + }; + rendezvous::write(dir, &instance).unwrap(); + (backend, server) + } + + /// The open project's root and the open buffers' paths. + fn state(backend: &lutra_testkit::EngineBackend) -> (Option, Vec) { + use lutra_control::Backend; + let root = { + let engine = backend.engine.lock().unwrap(); + engine + .state() + .project + .as_ref() + .map(|w| w.project.root().to_path_buf()) + }; + let list = backend + .execute("buffer.list", serde_json::json!({})) + .unwrap(); + let buffers = list + .as_array() + .unwrap() + .iter() + .map(|b| PathBuf::from(b["path"].as_str().unwrap())) + .collect(); + (root, buffers) + } + + #[test] + fn a_forwarded_file_opens_in_its_project() { + let rv = tempfile::tempdir().unwrap(); + let work = tempfile::tempdir().unwrap(); + let app = work.path().join("app"); + std::fs::create_dir_all(app.join("src")).unwrap(); + std::fs::write(app.join("composer.json"), "{}").unwrap(); + let file = app.join("src").join("Kernel.php"); + std::fs::write(&file, " Result<(), String> { follow_system_background(&window); } if let Some(path) = &initial_path - && let Err(e) = setup_host.open_project(path) + && let Err(e) = setup_host.open_path(path) { setup_host.report_open_failure(path, &e); } @@ -174,16 +176,32 @@ fn run(args: &args::Args) -> Result<(), String> { }); host.start_pump() .map_err(|e| format!("cannot start watching for changes: {e}"))?; - app.run(move |_, event| { - if let tauri::RunEvent::Exit = event - && let Some(claim) = &claim - { - claim.release(); + app.run(move |_, event| match event { + tauri::RunEvent::Exit => { + if let Some(claim) = &claim { + claim.release(); + } } + #[cfg(target_os = "macos")] + tauri::RunEvent::Opened { urls } => open_urls(&host, &urls), + _ => {} }); Ok(()) } +/// macOS: opens the files Finder hands over ("Open With → Lutra", a file +/// dropped on the Dock icon), which arrive as an Apple event instead of +/// arguments. Each opens like a path on the command line; a failure is +/// shown as a notification. +#[cfg(target_os = "macos")] +fn open_urls(host: &Host, urls: &[tauri::Url]) { + for path in urls.iter().filter_map(|url| url.to_file_path().ok()) { + if let Err(e) = host.open_path(&path) { + host.report_open_failure(&path, &e); + } + } +} + /// The user's engine directories from Tauri's path resolver: the app config /// dir for settings, the app data dir for the recovery journal and the /// managed tools. Resolving creates nothing. @@ -365,4 +383,29 @@ mod tests { ); assert_eq!(token_color(&theme::DARK, "missing"), None); } + + #[test] + fn the_bundle_config_matches_the_crate_and_the_installer() { + let conf: Value = serde_json::from_str(include_str!("../tauri.conf.json")).unwrap(); + assert_eq!(conf["version"], env!("CARGO_PKG_VERSION")); + assert!( + conf["bundle"].get("fileAssociations").is_none(), + "on Windows the bundler's associations take over the default app; installer/hooks.nsh registers Open with instead" + ); + let mac: Value = serde_json::from_str(include_str!("../tauri.macos.conf.json")).unwrap(); + let assoc = &mac["bundle"]["fileAssociations"][0]; + assert_eq!(assoc["rank"], "Alternate"); + let mac_exts: Vec<&str> = assoc["ext"] + .as_array() + .unwrap() + .iter() + .map(|e| e.as_str().unwrap()) + .collect(); + let windows_exts: Vec<&str> = include_str!("../installer/hooks.nsh") + .lines() + .filter_map(|line| line.trim().strip_prefix("!insertmacro ${MACRO} \"")) + .filter_map(|rest| rest.strip_suffix('"')) + .collect(); + assert_eq!(mac_exts, windows_exts); + } } diff --git a/apps/lutra-desktop/src/open.rs b/apps/lutra-desktop/src/open.rs new file mode 100644 index 0000000..0f28a90 --- /dev/null +++ b/apps/lutra-desktop/src/open.rs @@ -0,0 +1,96 @@ +//! What a path on the command line opens. +//! +//! A folder becomes the project. A file (for example from Explorer's +//! "Open with → Lutra" on a `.php` file) opens in a tab, inside a project +//! chosen for it by [`project_root`]: the nearest folder above it that is a +//! Git work tree, else the nearest one with a `composer.json`, else the +//! file's own folder. + +use std::path::{Path, PathBuf}; + +/// Markers of a Git work tree: a `.git` folder, or a `.git` file in a +/// linked worktree or submodule. +const GIT_MARKER: &str = ".git"; + +/// Composer's project file. +const COMPOSER_MARKER: &str = "composer.json"; + +/// The project folder for `file`: the nearest ancestor holding `.git`, +/// else the nearest one holding `composer.json`, else the file's parent. +/// `None` only for a path without a parent (a bare root). +pub fn project_root(file: &Path) -> Option { + let parent = file.parent()?; + let nearest = |marker: &str| { + parent + .ancestors() + .find(|dir| dir.join(marker).exists()) + .map(Path::to_path_buf) + }; + nearest(GIT_MARKER) + .or_else(|| nearest(COMPOSER_MARKER)) + .or_else(|| Some(parent.to_path_buf())) +} + +/// `path` made absolute against the current directory; unchanged if that +/// fails, so the engine reports the original path. +pub fn absolute(path: &Path) -> PathBuf { + std::path::absolute(path).unwrap_or_else(|_| path.to_path_buf()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_git_root_wins_over_a_nested_composer_project() { + let dir = tempfile::tempdir().unwrap(); + let repo = dir.path().join("repo"); + let pkg = repo.join("packages").join("api"); + std::fs::create_dir_all(repo.join(".git")).unwrap(); + std::fs::create_dir_all(pkg.join("src")).unwrap(); + std::fs::write(pkg.join("composer.json"), "{}").unwrap(); + let file = pkg.join("src").join("Kernel.php"); + assert_eq!(project_root(&file), Some(repo)); + } + + #[test] + fn a_git_file_marks_a_worktree() { + let dir = tempfile::tempdir().unwrap(); + let tree = dir.path().join("wt"); + std::fs::create_dir_all(tree.join("src")).unwrap(); + std::fs::write(tree.join(".git"), "gitdir: elsewhere").unwrap(); + assert_eq!(project_root(&tree.join("src").join("a.php")), Some(tree)); + } + + #[test] + fn composer_marks_a_project_without_git() { + let dir = tempfile::tempdir().unwrap(); + let app = dir.path().join("app"); + std::fs::create_dir_all(app.join("public")).unwrap(); + std::fs::write(app.join("composer.json"), "{}").unwrap(); + let file = app.join("public").join("index.php"); + assert_eq!(project_root(&file), Some(app)); + } + + #[test] + fn a_loose_file_opens_in_its_folder() { + let dir = tempfile::tempdir().unwrap(); + let loose = dir.path().join("scratch"); + std::fs::create_dir_all(&loose).unwrap(); + let file = loose.join("test.php"); + if dir.path().ancestors().any(|d| d.join(".git").exists()) + || dir + .path() + .ancestors() + .any(|d| d.join("composer.json").exists()) + { + return; + } + assert_eq!(project_root(&file), Some(loose)); + } + + #[test] + fn makes_relative_paths_absolute() { + assert!(absolute(Path::new("foo.php")).is_absolute()); + } +} diff --git a/apps/lutra-desktop/tauri.conf.json b/apps/lutra-desktop/tauri.conf.json index 3225ff2..6318c2d 100644 --- a/apps/lutra-desktop/tauri.conf.json +++ b/apps/lutra-desktop/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Lutra", - "version": "0.0.0", + "version": "0.1.0-alpha", "identifier": "com.tyrveil.lutra", "build": { "devUrl": "http://localhost:5173", @@ -34,7 +34,9 @@ "installerIcon": "icons/icon.ico", "headerImage": "../../assets/installer/nsis-header.bmp", "sidebarImage": "../../assets/installer/nsis-sidebar.bmp", - "compression": "lzma" + "compression": "lzma", + "template": "installer/installer.nsi", + "installerHooks": "installer/hooks.nsh" } }, "macOS": { diff --git a/apps/lutra-desktop/tauri.macos.conf.json b/apps/lutra-desktop/tauri.macos.conf.json new file mode 100644 index 0000000..3446d11 --- /dev/null +++ b/apps/lutra-desktop/tauri.macos.conf.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://schema.tauri.app/config/2", + "bundle": { + "fileAssociations": [ + { + "ext": ["php", "phtml", "phpt", "inc"], + "contentTypes": ["public.php-script"], + "name": "PHP file", + "role": "Editor", + "rank": "Alternate" + } + ] + } +} diff --git a/docs/install.md b/docs/install.md index ea26395..8b2a182 100644 --- a/docs/install.md +++ b/docs/install.md @@ -23,15 +23,31 @@ Lutra installs for your user only: no administrator rights, no UAC prompt. It ne 1. Start `Lutra__x64-setup.exe`. 2. Windows SmartScreen says "Windows protected your PC", because the setup is not signed. Click **More info**, check that the app is `Lutra__x64-setup.exe` and the publisher is "Unknown publisher", then click **Run anyway**. If you downloaded the file with a browser, the browser may ask first whether to keep it. 3. The setup runs in English or German, following Windows. Click **Next**, keep or change the folder (default `%LOCALAPPDATA%\Lutra`), click **Install**. -4. On the last page, tick **Create desktop shortcut** if you want one, and click **Finish**. +4. On the last page, tick **Create desktop shortcut** if you want one, keep or clear **Run Lutra**, and click **Finish**. The setup closes at once; Lutra starts through Explorer a moment later. -Lutra is now in the Start menu as **Lutra**. Installing a newer setup over it updates it in place and keeps your settings. +Lutra is now in the Start menu as **Lutra** and in Settings → Apps → Installed apps. Installing a newer setup over it updates it in place and keeps your settings. -For scripts: `Lutra__x64-setup.exe /S` installs silently with both shortcuts, `/D=C:\path` (last argument) picks the folder, `/NS` skips the shortcuts. +For scripts: `Lutra__x64-setup.exe /S` installs silently with both shortcuts, `/P` shows only the progress bar, `/D=C:\path` (last argument) picks the folder, `/NS` skips the shortcuts, `/R` starts Lutra afterwards. + +### Opening PHP files from Explorer + +The setup offers Lutra in Explorer's **Open with** menu for `.php`, `.phtml`, `.phpt` and `.inc` files. It does not become the default app: double-clicking a PHP file still opens whatever opened it before. To make Lutra the default, pick **Open with → Choose another app → Lutra** and tick **Always**. + +A file opened this way opens in a tab, inside the project around it: the nearest folder above it that is a Git repository, else the nearest one with a `composer.json`, else the file's own folder. If Lutra is already running, the running window takes the file. A file outside its open project switches the project; if the open project has unsaved changes, Lutra refuses to switch and nothing is lost. The same works from a terminal: `lutra-desktop.exe C:\path\to\file.php`. + +### If the setup stops responding on the last page + +Seen once, with the 0.0.0 setup on a PC with Norton 360: after **Finish** with "Run Lutra" ticked, the setup window stopped responding, Windows closed it ("has stopped interacting with Windows", event AppHangB1), and Lutra did not open. What we found: + +- The 0.0.0 setup started Lutra with Tauri's `RunAsUser` helper, which calls ShellExecute on the setup's window thread. The new `lutra-desktop.exe` process was created **suspended** (one thread, wait reason "Suspended", no CPU time, no window) while the freshly written, unsigned exe was being checked, and the setup waited inside that call. When Windows ended the hanging setup, nothing resumed the process: it stayed in Task Manager as a `lutra-desktop.exe` without a window. +- The same kind of build installed on the same PC without a hang, by hand and from a script. The stall depends on the check of a new, unknown file and could not be reproduced on demand. Norton 360 was active; its settings were not changed. +- In that run the Installed-apps entry (`HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\Lutra`) was missing and `HKCU\Software\Lutra\Lutra` still pointed to an older test install, although the files, `uninstall.exe` and the Start-menu shortcut were written. Every later install on the same PC wrote both keys correctly; why they were missing in that one run is not known. + +Since 0.1.0-alpha the finish page starts Lutra through Explorer (`explorer.exe "\lutra-desktop.exe"`) and returns at once, so the setup no longer waits for those checks, and a slow check delays only Lutra's start. If you still find a `lutra-desktop.exe` without a window after a setup, end it in Task Manager and start Lutra from the Start menu. If Lutra is missing from Installed apps, run the setup again: it writes the entry anew. ### Uninstalling on Windows -Settings → Apps → Installed apps → **Lutra** → … → **Uninstall**, or run `uninstall.exe` in the install folder. The uninstaller removes the app and its shortcuts. Your settings, recovery journal and Phpactor stay unless you tick **Delete the application data**. +Settings → Apps → Installed apps → **Lutra** → … → **Uninstall**, or run `uninstall.exe` in the install folder. The uninstaller removes the app, its shortcuts, its Installed-apps entry and the **Open with** entries. Your settings, recovery journal and Phpactor stay unless you tick **Delete the application data**. ## macOS @@ -47,6 +63,10 @@ xattr -dr com.apple.quarantine /Applications/Lutra.app You need to do this once per installed version. +### Opening PHP files from Finder + +Lutra registers as an alternate editor for `.php`, `.phtml`, `.phpt` and `.inc` files: it appears under **Open With** without becoming the default. A file opens as on Windows, in the project around it. + ### Uninstalling on macOS Quit Lutra and drag **Lutra** from **Applications** to the Trash. Your data stays; delete the folders below to remove it. @@ -70,3 +90,4 @@ An instance started with `--control PORT` or `--data-dir DIR` keeps its files in | Date | Change | Summary | |---|---|---| | 2026-10-31 | major | B1: initial version, NSIS setup and DMG, unsigned | +| 2026-10-31 | minor | B2: finish-page hang found and fixed, Open with for PHP files, version 0.1.0-alpha | diff --git a/ui/package.json b/ui/package.json index 200d0f3..8319b09 100644 --- a/ui/package.json +++ b/ui/package.json @@ -1,7 +1,7 @@ { "name": "lutra-ui", "private": true, - "version": "0.0.0", + "version": "0.1.0-alpha", "license": "MIT OR Apache-2.0", "type": "module", "engines": { diff --git a/ui/tests/App.test.ts b/ui/tests/App.test.ts index 2afff85..8f45704 100644 --- a/ui/tests/App.test.ts +++ b/ui/tests/App.test.ts @@ -24,12 +24,12 @@ describe("App", () => { Promise.resolve( command === "engine_list_commands" ? [] - : { name: "Lutra", version: "0.0.0", slogan: "An otterly perfect IDE" }, + : { name: "Lutra", version: "0.1.0-alpha", slogan: "An otterly perfect IDE" }, ), ); const wrapper = mount(App); await flushPromises(); - expect(wrapper.get("[data-test=status-bar]").text()).toBe("Lutra 0.0.0"); + expect(wrapper.get("[data-test=status-bar]").text()).toBe("Lutra 0.1.0-alpha"); expect(wrapper.get("[data-test=main]").text()).toBe("An otterly perfect IDE"); }); diff --git a/xtask/src/bundle.rs b/xtask/src/bundle.rs index eb91a85..88d6481 100644 --- a/xtask/src/bundle.rs +++ b/xtask/src/bundle.rs @@ -54,10 +54,18 @@ pub fn bundle() -> TaskResult { args.push("--config".into()); args.push(dmg_background_override(&tiff)); } - let args: Vec<&str> = args.iter().map(String::as_str).collect(); - run(&root.join("apps").join("lutra-desktop"), &cargo, &args).map_err(|e| { - format!("{e}\n(install the Tauri CLI with `cargo install tauri-cli --locked`)") - })?; + let status = std::process::Command::new(&cargo) + .args(&args) + .current_dir(root.join("apps").join("lutra-desktop")) + .env("CARGO_TARGET_DIR", &target_dir) + .status() + .map_err(|e| format!("cannot start `{cargo}`: {e}"))?; + if !status.success() { + return Err(format!( + "`{cargo} {}` failed ({status})\n(install the Tauri CLI with `cargo install tauri-cli --locked`)", + args.join(" ") + )); + } let out = target_dir.join("release").join("bundle").join(folder); let listing = std::fs::read_dir(&out) .map_err(|e| format!("no installer folder {}: {e}", out.display()))?; @@ -74,7 +82,9 @@ pub fn bundle() -> TaskResult { } /// The Cargo target directory: `CARGO_TARGET_DIR` (relative to the -/// repository root) or `/target`. +/// repository root) or `/target`. [`bundle`] hands it to the Tauri +/// CLI as an absolute path: Cargo would read a relative one against +/// `apps/lutra-desktop`, where the CLI runs. fn target_dir(root: &Path) -> PathBuf { match std::env::var_os("CARGO_TARGET_DIR").filter(|v| !v.is_empty()) { Some(dir) => root.join(dir),