From da00aa4826e846fa14ece30b57de46aee30677c9 Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 27 Jul 2026 17:09:06 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20version=20dynamique=20bas=C3=A9e=20sur?= =?UTF-8?q?=20Git=20=E2=80=94=20build.rs=20injecte=20GIT=5FHASH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - build.rs: lit git rev-parse --short HEAD, passe GIT_HASH au compilateur - main.rs: ABOUT_MSG constant au compile-time avec CARGO_PKG_VERSION + GIT_HASH - get_version() command Tauri retourne v2.0.0-abc1234 - Log + À propos (menu natif + tray) utilisent la version dynamique - rerun-if-changed sur .git/HEAD pour recompiler à chaque commit --- desktop/build.rs | 13 +++++++++++++ desktop/src/main.rs | 30 +++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/desktop/build.rs b/desktop/build.rs index d860e1e..3a4fa73 100644 --- a/desktop/build.rs +++ b/desktop/build.rs @@ -1,3 +1,16 @@ fn main() { + // Inject Git commit hash as version suffix + let git_hash = std::process::Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output() + .ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .map(|s| s.trim().to_string()) + .unwrap_or_else(|| "unknown".to_string()); + + println!("cargo:rustc-env=GIT_HASH={}", git_hash); + println!("cargo:rerun-if-changed=.git/HEAD"); + println!("cargo:rerun-if-changed=.git/refs/heads/main"); + tauri_build::build() } diff --git a/desktop/src/main.rs b/desktop/src/main.rs index 1e3ca06..1dcd1ed 100644 --- a/desktop/src/main.rs +++ b/desktop/src/main.rs @@ -238,6 +238,13 @@ fn get_backend_url() -> String { "http://127.0.0.1:17890".to_string() } +#[tauri::command] +fn get_version() -> String { + let cargo_version = env!("CARGO_PKG_VERSION"); + let git_hash = env!("GIT_HASH"); + format!("v{}-{}", cargo_version, git_hash) +} + #[tauri::command] fn get_config() -> AppConfig { load_config() @@ -413,6 +420,15 @@ fn get_window_state() -> AppConfig { load_config() } +// Build About message once at compile time +const ABOUT_MSG: &str = concat!( + "ObsiGate Desktop v", env!("CARGO_PKG_VERSION"), "-", env!("GIT_HASH"), + "\\n\\nPorte d\\'entrée native pour vos vaults Obsidian.", + "\\nConstruit avec Tauri + Rust.", + "\\n\\n© Bruno Charest — Licence MIT", + "\\nhttps://git.dracodev.net/Projets/ObsiGate" +); + // ── Entry Point ───────────────────────────────────────────────────────────── fn main() { @@ -431,7 +447,8 @@ fn main() { }) .try_init(); - info!("ObsiGate Desktop v2.0.0 starting"); + let version_str = format!("v{}-{}", env!("CARGO_PKG_VERSION"), env!("GIT_HASH")); + info!("ObsiGate Desktop {} starting", version_str); // Resolve exe directory let exe_dir = std::env::current_exe() @@ -512,6 +529,7 @@ fn main() { .manage(backend_state) .invoke_handler(tauri::generate_handler![ get_backend_url, + get_version, get_config, save_vault_path, get_vault_path, @@ -730,9 +748,8 @@ fn build_native_menu(app: &tauri::App) -> Result<(), Box> } "help_about" => { if let Some(window) = app.get_webview_window("main") { - let _ = window.eval( - r#"alert('ObsiGate Desktop v2.0.0\n\nPorte d\'entrée native pour vos vaults Obsidian.\nConstruit avec Tauri + Rust.\n\n© Bruno Charest — Licence MIT\nhttps://git.dracodev.net/Projets/ObsiGate')"# - ); + let js = format!("alert('{}')", ABOUT_MSG); + let _ = window.eval(&js); } } "edit_undo" | "edit_redo" | "edit_cut" | "edit_copy" | "edit_paste" | "edit_select_all" => { @@ -787,9 +804,8 @@ fn build_tray_menu(app: &tauri::App) -> Result<(), Box> { } "about" => { if let Some(window) = app.get_webview_window("main") { - let _ = window.eval( - r#"alert('ObsiGate Desktop v2.0.0\n\nPorte d\'entrée native pour vos vaults Obsidian.\nConstruit avec Tauri + Rust.\n\n© Bruno Charest — Licence MIT\nhttps://git.dracodev.net/Projets/ObsiGate')"# - ); + let js = format!("alert('{}')", ABOUT_MSG); + let _ = window.eval(&js); } } _ => {}