feat: show launcher if different version was installed

This commit is contained in:
llama 2025-10-05 08:05:02 +08:00
parent 1f9d943c8d
commit b9219a8621
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3
2 changed files with 20 additions and 1 deletions

View file

@ -7,4 +7,7 @@ fn main() {
.manifest_required()
.unwrap();
}
println!("cargo:rerun-if-changed=../../out/buildhash");
let buildhash = std::fs::read_to_string("../../out/buildhash").unwrap_or_default();
println!("cargo:rustc-env=BUILDHASH={buildhash}");
}

View file

@ -152,7 +152,9 @@ fn run() -> Result<()> {
let sync_time = file_timestamp_secs(&state.sync_complete_marker);
state.pyproject_modified_by_user = pyproject_time > sync_time;
let pyproject_has_changed = state.pyproject_modified_by_user;
if !launcher_requested && !pyproject_has_changed {
let different_launcher = diff_launcher_was_installed(&state)?;
if !launcher_requested && !pyproject_has_changed && !different_launcher {
// If no launcher request and venv is already up to date, launch Anki normally
let args: Vec<String> = std::env::args().skip(1).collect();
let cmd = build_python_command(&state, &args)?;
@ -1107,6 +1109,20 @@ fn show_mirror_submenu(state: &State) -> Result<()> {
Ok(())
}
fn diff_launcher_was_installed(state: &State) -> Result<bool> {
let launcher_version = option_env!("BUILDHASH").unwrap_or("dev").trim();
let launcher_version_path = state.uv_install_root.join("launcher-version");
if let Ok(content) = read_file(&launcher_version_path) {
if let Ok(version_str) = String::from_utf8(content) {
if version_str.trim() == launcher_version {
return Ok(false);
}
}
}
write_file(launcher_version_path, launcher_version)?;
Ok(true)
}
#[cfg(test)]
mod tests {
use super::*;