feat: 添加设置窗口标题功能,更新命令处理逻辑
This commit is contained in:
@@ -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())
|
||||||
|
}
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
mod commands;
|
||||||
#[tauri::command]
|
|
||||||
fn greet(name: &str) -> String {
|
|
||||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
@@ -10,7 +6,7 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
.plugin(tauri_plugin_opener::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!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user