v0.1.0-pre.045
This commit is contained in:
73
kb-app-demo-desktop/src/tauri.rs
Normal file
73
kb-app-demo-desktop/src/tauri.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
// file: kb-app-demo-desktop/src/tauri.rs
|
||||
// version: 1
|
||||
|
||||
//! Tauri runtime assembly and private command wrappers.
|
||||
|
||||
use tauri::Manager; // rust-rules: trait-import
|
||||
|
||||
/// Runs the desktop demo application.
|
||||
pub fn run() -> kb_core::Result<()> {
|
||||
let builder = tauri::Builder::default().setup(|app| {
|
||||
let splash_window = match app.get_webview_window("splash") {
|
||||
std::option::Option::Some(window) => window,
|
||||
std::option::Option::None => {
|
||||
return std::result::Result::Err(std::boxed::Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"splash window is missing",
|
||||
)));
|
||||
},
|
||||
};
|
||||
let main_window = match app.get_webview_window("main") {
|
||||
std::option::Option::Some(window) => window,
|
||||
std::option::Option::None => {
|
||||
return std::result::Result::Err(std::boxed::Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"main window is missing",
|
||||
)));
|
||||
},
|
||||
};
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let started_at = tokio::time::Instant::now();
|
||||
crate::emit_splash_order(
|
||||
&splash_window,
|
||||
"fadein",
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(crate::SPLASH_FADE_MS),
|
||||
);
|
||||
crate::emit_splash_order(
|
||||
&splash_window,
|
||||
"add_msg",
|
||||
std::option::Option::Some("Initialisation de Khadhroony Bot3..."),
|
||||
std::option::Option::Some("info"),
|
||||
std::option::Option::None,
|
||||
);
|
||||
crate::wait_until_minimum(started_at, crate::SPLASH_MINIMUM_MS).await;
|
||||
crate::emit_splash_order(
|
||||
&splash_window,
|
||||
"fadeout",
|
||||
std::option::Option::None,
|
||||
std::option::Option::None,
|
||||
std::option::Option::Some(crate::SPLASH_FADE_MS),
|
||||
);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(crate::SPLASH_CLOSE_WAIT_MS)).await;
|
||||
if let std::result::Result::Err(error) = splash_window.destroy() {
|
||||
tracing::error!(target: crate::TRACING_TARGET, "cannot destroy splash window: {error:?}");
|
||||
}
|
||||
if let std::result::Result::Err(error) = main_window.show() {
|
||||
tracing::error!(target: crate::TRACING_TARGET, "cannot show main window: {error:?}");
|
||||
}
|
||||
if let std::result::Result::Err(error) = main_window.set_focus() {
|
||||
tracing::error!(target: crate::TRACING_TARGET, "cannot focus main window: {error:?}");
|
||||
}
|
||||
});
|
||||
return std::result::Result::Ok(());
|
||||
});
|
||||
let run_result = builder.run(tauri::generate_context!());
|
||||
return match run_result {
|
||||
std::result::Result::Ok(()) => std::result::Result::Ok(()),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(kb_core::Error::tauri(format!(
|
||||
"cannot run desktop demo application: {error:?}"
|
||||
))),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user