fix(app): installer removes only its own files and stops on failed steps

- installer.sh lists every packaged file for the uninstaller, and folders
  are removed only when empty, so a chosen folder keeps other files.
- A virtual monitor driver removal that fails stops the uninstall with
  everything kept (silent exit code 4); the elevated half exits 2 when
  there is no driver of ours to remove, which the uninstaller accepts.
- WebView2 is installed before any file is copied; when it is still
  missing the installer asks to retry, or silently stops with code 3
  without installing or starting anything.
- The installer holds Global\JarvisBotSetup while it runs; jarvis.exe
  started meanwhile shows a message and exits before any window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-14 11:26:28 +09:00
parent 5ce832f51a
commit 1ae2521d58
7 changed files with 192 additions and 33 deletions

View File

@@ -124,12 +124,22 @@ pub async fn run_elevated(_action: &str) -> Result<(), String> {
Err("가상 모니터는 Windows에서만 씁니다".into())
}
/// The elevated half's exit code when removing finds no driver of this app's (none, or another
/// program's copy): the uninstaller goes on. 0 is done, 1 failed (the uninstaller stops).
pub const NOTHING_TO_REMOVE: i32 = 2;
/// `jarvis.exe --display-driver install|uninstall --result FILE`: the elevated half of
/// `run_elevated`; the outcome (empty, or why it failed) goes to FILE. `None` without the option.
pub fn elevated_main(args: &[String]) -> Option<i32> {
let i = args.iter().position(|a| a == "--display-driver")?;
let action = args.get(i + 1).map(String::as_str).unwrap_or("");
let result = args.iter().position(|a| a == "--result").and_then(|j| args.get(j + 1)).map(PathBuf::from);
if action == "uninstall" && !owns_driver() {
if let Some(f) = &result {
let _ = std::fs::write(f, "");
}
return Some(NOTHING_TO_REMOVE);
}
let outcome = match (action, driver_dir()) {
(_, None) => Err("앱 폴더를 찾지 못했습니다".to_owned()),
("install", Some(d)) => install(&d),
@@ -142,6 +152,14 @@ pub fn elevated_main(args: &[String]) -> Option<i32> {
Some(if outcome.is_ok() { 0 } else { 1 })
}
/// Whether this app's driver (or something it left) is on the PC.
fn owns_driver() -> bool {
#[cfg(windows)]
return win::ours();
#[cfg(not(windows))]
false
}
#[cfg(not(windows))]
fn install(_driver: &Path) -> Result<(), String> {
Err("가상 모니터는 Windows에서만 씁니다".into())
@@ -249,7 +267,7 @@ mod win {
(r == ERROR_SUCCESS).then(|| text(&buf))
}
fn ours() -> bool {
pub(super) fn ours() -> bool {
match (vdd_path(), config_dir()) {
(Some(p), Some(c)) => p.trim_end_matches('\\').eq_ignore_ascii_case(c.to_string_lossy().trim_end_matches('\\')),
_ => false,
@@ -558,6 +576,7 @@ mod win {
let _ = std::fs::remove_file(&result);
match code {
0 => Ok(()),
c if c as i32 == super::NOTHING_TO_REMOVE && action == "uninstall" => Ok(()),
_ if !why.is_empty() => Err(why),
c => Err(format!("드라이버 작업이 실패했습니다 (종료 코드 {c})")),
}
@@ -653,4 +672,17 @@ mod tests {
fn only_the_display_driver_option_runs_the_elevated_half() {
assert_eq!(elevated_main(&["jarvis".into(), "--location".into(), "x".into()]), None);
}
#[test]
fn removing_a_driver_this_app_does_not_own_says_there_is_nothing_to_remove() {
// The uninstaller goes on with code 2, and stops on a failure (code 1).
let result = std::env::temp_dir().join(format!("jarvis-vdd-test-{}.txt", std::process::id()));
let args: Vec<String> = ["jarvis", "--display-driver", "uninstall", "--result", result.to_str().unwrap()]
.map(String::from).into();
assert_eq!(elevated_main(&args), Some(NOTHING_TO_REMOVE));
assert_eq!(std::fs::read_to_string(&result).unwrap(), "");
let _ = std::fs::remove_file(&result);
let bad: Vec<String> = ["jarvis", "--display-driver", "nope"].map(String::from).into();
assert_eq!(elevated_main(&bad), Some(1));
}
}