feat: 添加设置窗口标题功能,更新命令处理逻辑

This commit is contained in:
Vixalie
2026-03-27 21:53:44 +08:00
parent 0320d5cf38
commit 9aa972bdec
2 changed files with 16 additions and 6 deletions

14
src-tauri/src/commands.rs Normal file
View File

@@ -0,0 +1,14 @@
use tauri::{AppHandle, WebviewWindow};
#[tauri::command]
pub fn set_window_title(
app_handle: AppHandle,
window: WebviewWindow,
title: Option<String>,
) -> 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())
}

View File

@@ -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");
}