feat(app): update the app from the project's Gitea releases
- update.rs finds the newest app-v<version> release above the running version (v1 tags, drafts, prereleases, incomplete releases and files on another server are skipped), downloads Jarvis-Setup-<version>.exe into cache/updates checked against its .sha256, and hands it over. - update_install hashes the file again, stops what runs, starts the installer with /S /RUN as administrator and the window quits; a declined administrator prompt keeps the app with the services stopped. - New 업데이트 screen; the app checks once when the main screens open. - tauri.conf.json no longer sets its own version, so the program file carries the Cargo.toml version the update compares. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,9 @@ pub struct AdminApi {
|
||||
hub: Arc<LogHub>,
|
||||
/// The virtual monitor's driver is being installed or removed: no service start meanwhile.
|
||||
driver_busy: Mutex<bool>,
|
||||
updater: Mutex<Option<Arc<crate::update::Updater>>>,
|
||||
/// Starts a downloaded installer (`update::launch_installer`; a fake in tests).
|
||||
launcher: fn(&Path) -> Result<(), String>,
|
||||
}
|
||||
|
||||
fn arg<'a>(args: &'a Value, key: &str) -> Result<&'a Value, String> {
|
||||
@@ -53,7 +56,8 @@ impl AdminApi {
|
||||
hub.set_secrets(Secrets::new(&d.secrets_file()).values());
|
||||
}
|
||||
Self { location_file: location_file.to_path_buf(), dir: Mutex::new(dir), controller: Mutex::new(None), installer: Mutex::new(None),
|
||||
syncer: Mutex::new(None), hub, driver_busy: Mutex::new(false) }
|
||||
syncer: Mutex::new(None), hub, driver_busy: Mutex::new(false), updater: Mutex::new(None),
|
||||
launcher: crate::update::launch_installer }
|
||||
}
|
||||
|
||||
fn dir(&self) -> Result<DataDir, String> {
|
||||
@@ -129,6 +133,24 @@ impl AdminApi {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Updates for this data folder (installers go to its `cache/updates`).
|
||||
fn updater(&self) -> Result<Arc<crate::update::Updater>, String> {
|
||||
let dir = self.dir()?;
|
||||
let mut u = self.updater.lock().unwrap();
|
||||
Ok(u.get_or_insert_with(|| crate::update::Updater::new(crate::update::source(), APP_VERSION,
|
||||
dir.path().join("cache").join("updates"))).clone())
|
||||
}
|
||||
|
||||
/// Install the downloaded update: stop what runs (as when the window closes), then start the
|
||||
/// installer, which waits for this app to close. `{"exit": true}`: the shell quits now.
|
||||
async fn install_update(&self) -> Result<Value, String> {
|
||||
let path = self.updater()?.ready_installer()?;
|
||||
self.shutdown().await.map_err(|e| format!("실행 중인 것을 멈추지 못해 업데이트를 설치하지 않았습니다: {e}"))?;
|
||||
(self.launcher)(&path).map_err(|e| format!("{e}. 서비스는 정지된 상태입니다"))?;
|
||||
crate::info_log!("app", "update installer started: the app closes");
|
||||
Ok(json!({"exit": true}))
|
||||
}
|
||||
|
||||
fn controller(&self) -> Result<Arc<Controller>, String> {
|
||||
let dir = self.dir()?;
|
||||
let mut c = self.controller.lock().unwrap();
|
||||
@@ -208,6 +230,7 @@ impl AdminApi {
|
||||
*self.dir.lock().unwrap() = Some(dir);
|
||||
*self.controller.lock().unwrap() = None;
|
||||
*self.installer.lock().unwrap() = None;
|
||||
*self.updater.lock().unwrap() = None;
|
||||
crate::info_log!("admin", "data folder chosen");
|
||||
Ok(json!({"dataDir": path.to_string_lossy()}))
|
||||
}
|
||||
@@ -351,6 +374,14 @@ impl AdminApi {
|
||||
}
|
||||
"service_stop" => self.controller()?.stop().await.map(|_| json!({"ok": true})),
|
||||
"dashboard" => Ok(self.controller()?.snapshot().await),
|
||||
"update_status" => Ok(self.updater()?.status()),
|
||||
"update_check" => self.updater()?.check().await,
|
||||
"update_download" => {
|
||||
let u = self.updater()?;
|
||||
u.download()?;
|
||||
Ok(u.status())
|
||||
}
|
||||
"update_install" => self.install_update().await,
|
||||
"logs_query" => {
|
||||
let tab = args.get("tab").and_then(Value::as_str).filter(|t| !t.is_empty() && *t != "all");
|
||||
let level = level_of(args.get("level").and_then(Value::as_str).unwrap_or("debug"));
|
||||
@@ -387,7 +418,7 @@ mod tests {
|
||||
let base = temp_dir(tag);
|
||||
let loc = base.join("cfg").join("location.json");
|
||||
(AdminApi { location_file: loc, dir: Mutex::new(None), controller: Mutex::new(None), installer: Mutex::new(None), syncer: Mutex::new(None),
|
||||
hub: LogHub::new(None), driver_busy: Mutex::new(false) },
|
||||
hub: LogHub::new(None), driver_busy: Mutex::new(false), updater: Mutex::new(None), launcher: refused_launch },
|
||||
base)
|
||||
}
|
||||
|
||||
@@ -524,6 +555,39 @@ mod tests {
|
||||
assert!(a.call("service_stop", json!({})).await.is_err());
|
||||
}
|
||||
|
||||
static LAUNCHED: Mutex<Option<PathBuf>> = Mutex::new(None);
|
||||
fn fake_launch(p: &Path) -> Result<(), String> {
|
||||
*LAUNCHED.lock().unwrap() = Some(p.to_path_buf());
|
||||
Ok(())
|
||||
}
|
||||
fn refused_launch(_: &Path) -> Result<(), String> {
|
||||
Err("관리자 권한을 받지 못해 업데이트를 설치하지 않았습니다".into())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_update_is_installed_only_once_downloaded_and_checked_after_stopping_what_runs() {
|
||||
let (mut a, base) = api("apiupd");
|
||||
a.call("folder_choose", json!({"path": base.join("d").to_string_lossy()})).await.unwrap();
|
||||
a.call("dashboard", json!({})).await.unwrap();
|
||||
assert!(a.call("update_install", json!({})).await.unwrap_err().contains("먼저 받아"));
|
||||
let installer = b"setup".to_vec();
|
||||
let sum = format!("{:x}", <sha2::Sha256 as sha2::Digest>::digest(&installer));
|
||||
let src = format!("{}/releases", crate::update::tests::gitea("9.0.0", installer, sum).await);
|
||||
*a.updater.lock().unwrap() = Some(crate::update::Updater::new(src, APP_VERSION, base.join("d/cache/updates")));
|
||||
assert_eq!(a.call("update_check", json!({})).await.unwrap()["latest"]["version"], json!("9.0.0"));
|
||||
a.call("update_download", json!({})).await.unwrap();
|
||||
for _ in 0..200 {
|
||||
if a.call("update_status", json!({})).await.unwrap()["phase"] != json!("downloading") { break }
|
||||
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
|
||||
}
|
||||
a.launcher = refused_launch;
|
||||
assert!(a.call("update_install", json!({})).await.unwrap_err().contains("서비스는 정지된 상태"));
|
||||
a.launcher = fake_launch;
|
||||
assert_eq!(a.call("update_install", json!({})).await.unwrap(), json!({"exit": true}));
|
||||
assert_eq!(LAUNCHED.lock().unwrap().clone(), Some(base.join("d/cache/updates/Jarvis-Setup-9.0.0.exe")));
|
||||
assert_eq!(a.call("dashboard", json!({})).await.unwrap()["state"], json!("stopped"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn closing_the_app_while_starting_waits_until_everything_is_stopped() {
|
||||
let (a, base) = api("api5");
|
||||
|
||||
Reference in New Issue
Block a user