C2: lutra CLI in the setup with optional PATH entry, xtask bundle prints the version
- xtask bundle builds lutra-cli and adds it as a Tauri external binary through a --config override (lutra.exe next to the app on Windows, Lutra.app/Contents/MacOS/lutra on macOS); prints path, version, size. - NSIS: "Add lutra to PATH" page, unticked by default, /ADDTOPATH for silent installs. Changes HKCU\Environment Path only, keeps its type, broadcasts WM_SETTINGCHANGE, records the entry; the uninstaller removes exactly that entry. A PATH too long for NSIS strings is left alone. - lutra CLI resolves a symlinked executable before looking for the app. - localStorage: the UI never used webview storage, so there is nothing to migrate; docs corrected, ESLint now bans localStorage, sessionStorage and indexedDB, with tests. - docs/install.md: CLI, PATH, macOS link step, webview folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d8e66a4652
commit
0a4b80adec
7 changed files with 628 additions and 46 deletions
|
|
@ -28,7 +28,10 @@ const POLL: Duration = Duration::from_millis(150);
|
|||
const PROBE: Duration = Duration::from_secs(2);
|
||||
|
||||
/// The desktop binary: `LUTRA_DESKTOP` if set, else `lutra-desktop` next to
|
||||
/// this executable, else the first `lutra-desktop` on `PATH`.
|
||||
/// this executable, else the first `lutra-desktop` on `PATH`. The executable
|
||||
/// is resolved through symbolic links first, so a `lutra` linked onto
|
||||
/// `PATH` from `Lutra.app/Contents/MacOS/` still finds the app next to its
|
||||
/// target; if that fails, the unresolved path is used.
|
||||
///
|
||||
/// # Errors
|
||||
/// A message naming the places that were tried.
|
||||
|
|
@ -38,6 +41,7 @@ pub fn find_desktop() -> Result<PathBuf, String> {
|
|||
}
|
||||
let sibling = std::env::current_exe()
|
||||
.ok()
|
||||
.map(resolve_link)
|
||||
.and_then(|exe| Some(exe.parent()?.join(DESKTOP_NAME)))
|
||||
.filter(|path| path.is_file());
|
||||
if let Some(path) = sibling {
|
||||
|
|
@ -56,6 +60,16 @@ pub fn find_desktop() -> Result<PathBuf, String> {
|
|||
})
|
||||
}
|
||||
|
||||
/// `path` resolved to its final target if it is a symbolic link, else
|
||||
/// `path` itself, also when resolving fails.
|
||||
fn resolve_link(path: PathBuf) -> PathBuf {
|
||||
let is_link = std::fs::symlink_metadata(&path).is_ok_and(|m| m.file_type().is_symlink());
|
||||
if !is_link {
|
||||
return path;
|
||||
}
|
||||
std::fs::canonicalize(&path).unwrap_or(path)
|
||||
}
|
||||
|
||||
/// Starts `desktop` detached from this terminal (Windows: a detached process
|
||||
/// in a new process group; Unix: a new process group, so a Ctrl-C or
|
||||
/// hangup aimed at the terminal's foreground group does not reach it) and
|
||||
|
|
@ -111,3 +125,33 @@ pub fn start(desktop: &Path, dir: &Path) -> Result<Client, String> {
|
|||
thread::sleep(POLL);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_plain_file_stays_as_it_is() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let file = tmp.path().join("lutra");
|
||||
std::fs::write(&file, "").unwrap();
|
||||
assert_eq!(resolve_link(file.clone()), file);
|
||||
let missing = tmp.path().join("missing");
|
||||
assert_eq!(resolve_link(missing.clone()), missing);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_link_resolves_to_its_target() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let app = tmp.path().join("Lutra.app/Contents/MacOS");
|
||||
std::fs::create_dir_all(&app).unwrap();
|
||||
std::fs::write(app.join("lutra"), "").unwrap();
|
||||
let link = tmp.path().join("lutra");
|
||||
std::os::unix::fs::symlink(app.join("lutra"), &link).unwrap();
|
||||
assert_eq!(
|
||||
resolve_link(link),
|
||||
std::fs::canonicalize(app.join("lutra")).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,13 @@
|
|||
WriteRegStr SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe\shell\open\command" "" '"$INSTDIR\${MAINBINARYNAME}.exe" "%1"'
|
||||
!insertmacro LUTRA_FOR_EACH_EXT LUTRA_OPEN_WITH
|
||||
!insertmacro UPDATEFILEASSOC
|
||||
Call LutraPathApply
|
||||
!macroend
|
||||
|
||||
; Remembers the PATH entry an earlier setup added before the uninstaller
|
||||
; may delete `${MANUPRODUCTKEY}` with the application data.
|
||||
!macro NSIS_HOOK_PREUNINSTALL
|
||||
ReadRegStr $LutraPathEntry HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}"
|
||||
!macroend
|
||||
|
||||
!macro NSIS_HOOK_POSTUNINSTALL
|
||||
|
|
@ -52,4 +59,219 @@
|
|||
DeleteRegKey SHCTX "Software\Classes\${LUTRA_PROGID}"
|
||||
DeleteRegKey SHCTX "Software\Classes\Applications\${MAINBINARYNAME}.exe"
|
||||
!insertmacro UPDATEFILEASSOC
|
||||
${If} $UpdateMode <> 1
|
||||
${AndIf} $LutraPathEntry != ""
|
||||
StrCpy $R3 $LutraPathEntry
|
||||
Call un.LutraPathRemove
|
||||
DeleteRegValue HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}"
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
||||
; lutra on PATH
|
||||
;
|
||||
; The setup installs the `lutra` command-line tool (`lutra.exe`, a Tauri
|
||||
; external binary that `cargo xtask bundle` adds) next to the app. The page
|
||||
; `LUTRA_PATH_PAGE` offers "Add lutra to PATH", unticked unless an earlier
|
||||
; setup added the entry; `/ADDTOPATH` ticks it for `/S` and `/P` installs.
|
||||
;
|
||||
; Only the user's PATH changes: the value `Path` under `HKCU\Environment`,
|
||||
; written back with its type (REG_EXPAND_SZ or REG_SZ), followed by a
|
||||
; WM_SETTINGCHANGE broadcast so new terminals see it. The folder that was
|
||||
; added is recorded as `${LUTRA_PATH_RECORD}` under `HKCU\${MANUPRODUCTKEY}`.
|
||||
; The uninstaller removes exactly that entry from PATH and leaves every
|
||||
; other entry, empty ones included, as it was. An entry the user had added
|
||||
; before is never recorded, so it stays on uninstall. A PATH longer than
|
||||
; NSIS strings can hold is not touched: the setup says so and goes on.
|
||||
|
||||
!define LUTRA_PATH_RECORD "PathEntry"
|
||||
|
||||
Var LutraAddToPath
|
||||
Var LutraPathCheckbox
|
||||
Var LutraPathEntry
|
||||
|
||||
; The PATH helpers, for the installer (`UN` empty) or the uninstaller
|
||||
; (`UN` = `un.`).
|
||||
!macro LUTRA_PATH_FUNCTIONS UN
|
||||
; Reads the user's PATH.
|
||||
; Out: $R0 the value, $R1 its type (0 missing, 1 REG_SZ, 2 REG_EXPAND_SZ).
|
||||
; Sets the error flag if it cannot be read, or if it plus `$INSTDIR` would
|
||||
; not fit in an NSIS string, so it is never written back cut short.
|
||||
Function ${UN}LutraPathRead
|
||||
Push $0
|
||||
ClearErrors
|
||||
StrCpy $R0 ""
|
||||
StrCpy $R1 0
|
||||
StrCpy $R2 0
|
||||
System::Call 'advapi32::RegGetValueW(p 0x80000001, w "Environment", w "Path", i 0x1000ffff, *i .R1, p 0, *i .R2) i .r0'
|
||||
${If} $0 = 2
|
||||
StrCpy $R1 0
|
||||
${ElseIf} $0 <> 0
|
||||
SetErrors
|
||||
${ElseIf} $R1 <> 1
|
||||
${AndIf} $R1 <> 2
|
||||
SetErrors
|
||||
${Else}
|
||||
IntOp $R2 $R2 / 2
|
||||
StrLen $0 $INSTDIR
|
||||
IntOp $R2 $R2 + $0
|
||||
${If} $R2 >= ${NSIS_MAX_STRLEN}
|
||||
SetErrors
|
||||
${Else}
|
||||
ReadRegStr $R0 HKCU "Environment" "Path"
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
Pop $0
|
||||
FunctionEnd
|
||||
|
||||
; Writes $R0 back as the user's PATH with type $R1 and tells running
|
||||
; programs that the environment changed.
|
||||
Function ${UN}LutraPathWrite
|
||||
${If} $R1 = 1
|
||||
WriteRegStr HKCU "Environment" "Path" $R0
|
||||
${Else}
|
||||
WriteRegExpandStr HKCU "Environment" "Path" $R0
|
||||
${EndIf}
|
||||
SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 "STR:Environment" /TIMEOUT=5000
|
||||
FunctionEnd
|
||||
|
||||
; Splits $R0 at ";" and drops every entry equal to $R3 (ignoring case).
|
||||
; Out: $R4 the remaining entries joined by ";", $R5 1 if one was dropped.
|
||||
Function ${UN}LutraPathFilter
|
||||
Push $6
|
||||
Push $7
|
||||
Push $8
|
||||
Push $9
|
||||
StrCpy $R4 ""
|
||||
StrCpy $R5 0
|
||||
StrCpy $6 0
|
||||
StrCpy $8 ""
|
||||
StrCpy $9 0
|
||||
loop:
|
||||
StrCpy $7 $R0 1 $6
|
||||
${If} $7 == ";"
|
||||
${OrIf} $7 == ""
|
||||
${If} $8 == $R3
|
||||
StrCpy $R5 1
|
||||
${ElseIf} $9 = 0
|
||||
StrCpy $R4 $8
|
||||
StrCpy $9 1
|
||||
${Else}
|
||||
StrCpy $R4 "$R4;$8"
|
||||
${EndIf}
|
||||
StrCpy $8 ""
|
||||
StrCmp $7 "" done
|
||||
${Else}
|
||||
StrCpy $8 "$8$7"
|
||||
${EndIf}
|
||||
IntOp $6 $6 + 1
|
||||
Goto loop
|
||||
done:
|
||||
Pop $9
|
||||
Pop $8
|
||||
Pop $7
|
||||
Pop $6
|
||||
FunctionEnd
|
||||
|
||||
; Removes the entry $R3 from the user's PATH if it is there.
|
||||
Function ${UN}LutraPathRemove
|
||||
Call ${UN}LutraPathRead
|
||||
${If} ${Errors}
|
||||
DetailPrint "$(lutraPathFailed)"
|
||||
Return
|
||||
${EndIf}
|
||||
Call ${UN}LutraPathFilter
|
||||
${If} $R5 = 1
|
||||
StrCpy $R0 $R4
|
||||
Call ${UN}LutraPathWrite
|
||||
DetailPrint "$(lutraPathRemoved)"
|
||||
${EndIf}
|
||||
FunctionEnd
|
||||
!macroend
|
||||
|
||||
; The PATH page and the functions behind it; inserted after the directory
|
||||
; page, so `$INSTDIR` is final.
|
||||
!macro LUTRA_PATH_PAGE
|
||||
Page custom LutraPathPageShow LutraPathPageLeave
|
||||
|
||||
!insertmacro LUTRA_PATH_FUNCTIONS ""
|
||||
!insertmacro LUTRA_PATH_FUNCTIONS "un."
|
||||
|
||||
Function LutraPathPageShow
|
||||
${If} $PassiveMode = 1
|
||||
Abort
|
||||
${EndIf}
|
||||
!insertmacro MUI_HEADER_TEXT "$(lutraPathTitle)" "$(lutraPathSubtitle)"
|
||||
nsDialogs::Create 1018
|
||||
Pop $0
|
||||
${IfThen} $(^RTL) = 1 ${|} nsDialogs::SetRTL $(^RTL) ${|}
|
||||
${NSD_CreateLabel} 0 0 100% 48u "$(lutraPathText)"
|
||||
Pop $0
|
||||
${NSD_CreateCheckbox} 0 56u 100% 12u "$(lutraPathCheckbox)"
|
||||
Pop $LutraPathCheckbox
|
||||
${If} $LutraAddToPath = 1
|
||||
${NSD_Check} $LutraPathCheckbox
|
||||
${EndIf}
|
||||
nsDialogs::Show
|
||||
FunctionEnd
|
||||
|
||||
Function LutraPathPageLeave
|
||||
${NSD_GetState} $LutraPathCheckbox $0
|
||||
${If} $0 = ${BST_CHECKED}
|
||||
StrCpy $LutraAddToPath 1
|
||||
${Else}
|
||||
StrCpy $LutraAddToPath 0
|
||||
${EndIf}
|
||||
FunctionEnd
|
||||
|
||||
; Brings the user's PATH in line with the choice: drops an entry an
|
||||
; earlier setup added if it is no longer wanted or points elsewhere, and
|
||||
; adds `$INSTDIR` if wanted and missing, recording it.
|
||||
Function LutraPathApply
|
||||
ReadRegStr $R6 HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}"
|
||||
${If} $R6 != ""
|
||||
${If} $LutraAddToPath <> 1
|
||||
${OrIf} $R6 != $INSTDIR
|
||||
StrCpy $R3 $R6
|
||||
Call LutraPathRemove
|
||||
DeleteRegValue HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}"
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
${If} $LutraAddToPath <> 1
|
||||
Return
|
||||
${EndIf}
|
||||
Call LutraPathRead
|
||||
${If} ${Errors}
|
||||
DetailPrint "$(lutraPathFailed)"
|
||||
MessageBox MB_ICONEXCLAMATION|MB_OK "$(lutraPathFailed)" /SD IDOK
|
||||
Return
|
||||
${EndIf}
|
||||
StrCpy $R3 $INSTDIR
|
||||
Call LutraPathFilter
|
||||
${If} $R5 = 1
|
||||
Return
|
||||
${EndIf}
|
||||
StrCpy $R7 $R0 1 -1
|
||||
${If} $R0 == ""
|
||||
${OrIf} $R7 == ";"
|
||||
StrCpy $R0 "$R0$INSTDIR"
|
||||
${Else}
|
||||
StrCpy $R0 "$R0;$INSTDIR"
|
||||
${EndIf}
|
||||
${IfThen} $R1 = 0 ${|} StrCpy $R1 2 ${|}
|
||||
Call LutraPathWrite
|
||||
WriteRegStr HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}" $INSTDIR
|
||||
DetailPrint "$(lutraPathAdded)"
|
||||
FunctionEnd
|
||||
!macroend
|
||||
|
||||
; The PATH choice at start: ticked if an earlier setup added the entry or
|
||||
; `/ADDTOPATH` is given. Inserted at the end of `.onInit`.
|
||||
!macro LUTRA_PATH_INIT
|
||||
StrCpy $LutraAddToPath 0
|
||||
ReadRegStr $0 HKCU "${MANUPRODUCTKEY}" "${LUTRA_PATH_RECORD}"
|
||||
${IfThen} $0 != "" ${|} StrCpy $LutraAddToPath 1 ${|}
|
||||
${GetOptions} $CMDLINE "/ADDTOPATH" $0
|
||||
${IfNot} ${Errors}
|
||||
StrCpy $LutraAddToPath 1
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
|
|
|||
|
|
@ -394,6 +394,9 @@ FunctionEnd
|
|||
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfPassive
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
|
||||
; Lutra: the "Add lutra to PATH" page (`LUTRA_PATH_PAGE` in `hooks.nsh`).
|
||||
!insertmacro LUTRA_PATH_PAGE
|
||||
|
||||
; 6. Start menu shortcut page
|
||||
Var AppStartMenuFolder
|
||||
!if "${STARTMENUFOLDER}" != ""
|
||||
|
|
@ -488,6 +491,26 @@ FunctionEnd
|
|||
!include "{{this}}"
|
||||
{{/each}}
|
||||
|
||||
; Lutra: the texts of the "Add lutra to PATH" page and its log lines. They
|
||||
; live here, not in `hooks.nsh`, because the bundler writes this file as
|
||||
; UTF-8 with a byte order mark, which the German umlauts need.
|
||||
LangString lutraPathTitle ${LANG_ENGLISH} "Command line"
|
||||
LangString lutraPathSubtitle ${LANG_ENGLISH} "Use Lutra from a terminal."
|
||||
LangString lutraPathText ${LANG_ENGLISH} "Setup installs the lutra command next to Lutra, so that lutra file.php opens the file in Lutra. To run it as lutra in every new terminal, add the install folder to your PATH.$\r$\n$\r$\nThis changes the PATH of your user account only. The uninstaller removes the entry again."
|
||||
LangString lutraPathCheckbox ${LANG_ENGLISH} "Add lutra to PATH"
|
||||
LangString lutraPathAdded ${LANG_ENGLISH} "Added $INSTDIR to the user PATH."
|
||||
LangString lutraPathRemoved ${LANG_ENGLISH} "Removed Lutra's entry from the user PATH."
|
||||
LangString lutraPathFailed ${LANG_ENGLISH} "Cannot change the user PATH: it cannot be read or is too long. Add $INSTDIR to it by hand to use lutra in a terminal."
|
||||
!ifdef LANG_GERMAN
|
||||
LangString lutraPathTitle ${LANG_GERMAN} "Kommandozeile"
|
||||
LangString lutraPathSubtitle ${LANG_GERMAN} "Lutra aus einem Terminal verwenden."
|
||||
LangString lutraPathText ${LANG_GERMAN} "Das Setup installiert den Befehl lutra neben Lutra, damit lutra datei.php die Datei in Lutra öffnet. Damit er in jedem neuen Terminal als lutra läuft, fügen Sie den Installationsordner zu Ihrem PATH hinzu.$\r$\n$\r$\nDas ändert nur den PATH Ihres Benutzerkontos. Die Deinstallation entfernt den Eintrag wieder."
|
||||
LangString lutraPathCheckbox ${LANG_GERMAN} "lutra zum PATH hinzufügen"
|
||||
LangString lutraPathAdded ${LANG_GERMAN} "$INSTDIR zum Benutzer-PATH hinzugefügt."
|
||||
LangString lutraPathRemoved ${LANG_GERMAN} "Lutras Eintrag aus dem Benutzer-PATH entfernt."
|
||||
LangString lutraPathFailed ${LANG_GERMAN} "Der Benutzer-PATH kann nicht geändert werden: Er ist nicht lesbar oder zu lang. Fügen Sie $INSTDIR von Hand hinzu, um lutra im Terminal zu verwenden."
|
||||
!endif
|
||||
|
||||
Function .onInit
|
||||
${GetOptions} $CMDLINE "/P" $PassiveMode
|
||||
${IfNot} ${Errors}
|
||||
|
|
@ -561,6 +584,9 @@ Function .onInit
|
|||
${EndIf}
|
||||
${EndIf}
|
||||
!endif
|
||||
|
||||
; Lutra: the initial "Add lutra to PATH" choice (`hooks.nsh`).
|
||||
!insertmacro LUTRA_PATH_INIT
|
||||
FunctionEnd
|
||||
|
||||
Section WebView2
|
||||
|
|
|
|||
|
|
@ -20,8 +20,13 @@
|
|||
//! `settings.json` goes straight into the new config directory, never
|
||||
//! replacing one that is already there.
|
||||
//!
|
||||
//! The webview's own data (recent projects, window layout) lives in a
|
||||
//! folder the webview manages and is not copied.
|
||||
//! The webview's own folder (WebView2's `EBWebView` under
|
||||
//! `%LOCALAPPDATA%\<identifier>`, WKWebView's under `~/Library/WebKit/`)
|
||||
//! is not copied: it holds only the webview's caches. The frontend keeps
|
||||
//! no state in `localStorage`, `sessionStorage` or IndexedDB (the UI lint
|
||||
//! forbids them), so nothing the user set lives there. State that has to
|
||||
//! survive a restart belongs in Lutra's own files above, which this
|
||||
//! migration carries over.
|
||||
|
||||
use std::fs;
|
||||
use std::io;
|
||||
|
|
@ -300,6 +305,36 @@ mod tests {
|
|||
assert!(new.data_dir.join("recovery/p1/e1.json").is_file());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_settings_object_is_copied_too() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let old = shared(tmp.path(), rendezvous::LEGACY_APP_IDENTIFIER);
|
||||
let new = shared(tmp.path(), rendezvous::APP_IDENTIFIER);
|
||||
fs::create_dir_all(old.data_dir.join("recovery")).unwrap();
|
||||
fs::create_dir_all(old.data_dir.join("tools")).unwrap();
|
||||
fs::write(old.config_dir.join("settings.json"), "{}").unwrap();
|
||||
|
||||
let migrated = migrate(&old, &new).unwrap().unwrap();
|
||||
assert_eq!(migrated.entries, ["settings.json", "recovery", "tools"]);
|
||||
assert_eq!(
|
||||
fs::read_to_string(new.config_dir.join("settings.json")).unwrap(),
|
||||
"{}"
|
||||
);
|
||||
assert!(new.data_dir.join("recovery").is_dir());
|
||||
assert!(new.data_dir.join("tools").is_dir());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_ui_lint_keeps_state_out_of_the_webview_storage() {
|
||||
let lint = include_str!("../../../ui/eslint.config.js");
|
||||
for rule in ["no-restricted-globals", "no-restricted-properties"] {
|
||||
assert!(lint.contains(rule), "{rule} missing");
|
||||
}
|
||||
for name in ["\"localStorage\"", "\"sessionStorage\"", "\"indexedDB\""] {
|
||||
assert!(lint.contains(name), "{name} not banned");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tauri_config_uses_the_app_identifier() {
|
||||
let conf: serde_json::Value =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue