feat(command):增加前后端交互模块。

This commit is contained in:
徐涛
2023-03-08 09:17:36 +08:00
parent 91a5a2d1f4
commit be5675cd5c
2 changed files with 37 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
use tauri::{App, AppHandle, Runtime, Window};
/// 用于持有应用实例,可存放不同的应用实例。
pub enum AppHold<'a, R: Runtime> {
Instance(&'a App<R>),
Handle(&'a AppHandle<R>),
}
/// 根据提供的应用实例和窗体实例设定窗体的标题。
pub fn update_window_title_with_app<R: Runtime>(
app: AppHold<R>,
window: &Window<R>,
ext: Option<String>,
) -> anyhow::Result<()> {
let app_name = match app {
AppHold::Instance(app) => app.package_info().name.clone(),
AppHold::Handle(app) => app.package_info().name.clone(),
};
if let Some(ext) = ext {
window.set_title(&format!("{} - {}", app_name, ext))?;
} else {
window.set_title(&app_name)?;
}
Ok(())
}