From 9aa972bdeca57fd911e4a64c1ef1ce47d89602e7 Mon Sep 17 00:00:00 2001 From: Vixalie Date: Fri, 27 Mar 2026 21:53:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=A0=87=E9=A2=98=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=91=BD=E4=BB=A4=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands.rs | 14 ++++++++++++++ src-tauri/src/lib.rs | 8 ++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src-tauri/src/commands.rs diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs new file mode 100644 index 0000000..ce26ca0 --- /dev/null +++ b/src-tauri/src/commands.rs @@ -0,0 +1,14 @@ +use tauri::{AppHandle, WebviewWindow}; + +#[tauri::command] +pub fn set_window_title( + app_handle: AppHandle, + window: WebviewWindow, + title: Option, +) -> Result<(), String> { + let app_name = app_handle.package_info().name.clone(); + let new_title = title + .map(|t| format!("{} - {}", t, app_name)) + .unwrap_or(app_name); + window.set_title(&new_title).map_err(|e| e.to_string()) +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ca79d93..c03b2be 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,8 +1,4 @@ -// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ -#[tauri::command] -fn greet(name: &str) -> String { - format!("Hello, {}! You've been greeted from Rust!", name) -} +mod commands; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -10,7 +6,7 @@ pub fn run() { .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_opener::init()) - .invoke_handler(tauri::generate_handler![greet]) + .invoke_handler(tauri::generate_handler![commands::set_window_title]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }