0.0.1
This commit is contained in:
136
kb_app/src/lib.rs
Normal file
136
kb_app/src/lib.rs
Normal file
@@ -0,0 +1,136 @@
|
||||
// file: kb_app/src/lib.rs
|
||||
|
||||
//#![deny(unreachable_pub)]
|
||||
//#![warn(missing_docs)]
|
||||
|
||||
mod splash;
|
||||
|
||||
pub use crate::splash::SplashOrder;
|
||||
use tauri::Emitter;
|
||||
use tauri::{Manager};
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
|
||||
fn setup_logger() -> tauri_plugin_tracing::Builder {
|
||||
let log_dir = std::env::temp_dir().join("kb_app");
|
||||
match std::fs::create_dir_all(&log_dir) {
|
||||
Ok(_) => {},
|
||||
Err(err) => {
|
||||
eprintln!("failed to create log directory: {:?}", err);
|
||||
},
|
||||
}
|
||||
let file_appender = tracing_appender::rolling::daily(&log_dir, "app");
|
||||
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
|
||||
std::mem::forget(guard);
|
||||
let targets = tracing_subscriber::filter::Targets::new()
|
||||
.with_default(tracing::Level::DEBUG)
|
||||
.with_target("hyper", tracing::Level::WARN)
|
||||
.with_target("reqwest", tracing::Level::WARN)
|
||||
.with_target("tao", tracing::Level::WARN)
|
||||
.with_target("wry", tracing::Level::WARN);
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::fmt::layer().with_ansi(true))
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer()
|
||||
.with_writer(tauri_plugin_tracing::StripAnsiWriter::new(non_blocking))
|
||||
.with_ansi(false),
|
||||
)
|
||||
.with(targets)
|
||||
.init();
|
||||
tauri_plugin_tracing::Builder::new()
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let tracing_builder = setup_logger();
|
||||
let mut tauri_builder = tauri::Builder::default();
|
||||
tauri_builder = tauri_builder.plugin(tracing_builder.build::<tauri::Wry>());
|
||||
tauri_builder = tauri_builder.setup(|app| {
|
||||
let app_handle = app.handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let splash_window = app_handle.get_webview_window("splash").unwrap();
|
||||
let main_window = app_handle.get_webview_window("main").unwrap();
|
||||
//main_window.set_title(&app_name).unwrap();
|
||||
let is_debug = cfg!(debug_assertions);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
if is_debug {
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "add_log".to_string(),
|
||||
msg: Some("Start Fade-In".to_string()),
|
||||
status: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "fadein".to_string(),
|
||||
msg: None,
|
||||
status: None,
|
||||
},
|
||||
);
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "add_msg".to_string(),
|
||||
msg: Some("Initialisation...".to_string()),
|
||||
status: Some("info".to_string()),
|
||||
},
|
||||
);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "add_msg".to_string(),
|
||||
msg: Some("Loading resources...".to_string()),
|
||||
status: Some("info".to_string()),
|
||||
},
|
||||
);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "add_msg".to_string(),
|
||||
msg: Some("Loading complete...".to_string()),
|
||||
status: Some("success".to_string()),
|
||||
},
|
||||
);
|
||||
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
||||
tracing::debug!("Start fadeout");
|
||||
if is_debug {
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "add_log".to_string(),
|
||||
msg: Some("Start Fade-out".to_string()),
|
||||
status: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
let _ = splash_window.emit(
|
||||
"splash",
|
||||
splash::SplashOrder {
|
||||
order: "fadeout".to_string(),
|
||||
msg: None,
|
||||
status: None,
|
||||
},
|
||||
);
|
||||
tracing::debug!("End fadeout");
|
||||
tokio::time::sleep(std::time::Duration::from_millis(3100)).await;
|
||||
if let Err(err) = splash_window.close() {
|
||||
tracing::error!("Error closing splash window: {:?}", err);
|
||||
}
|
||||
if let Err(err) = main_window.show() {
|
||||
tracing::error!("Error showing main window: {:?}", err);
|
||||
} else {
|
||||
let _ = main_window.emit("setupTray", ());
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
});
|
||||
if let Err(err) = tauri_builder.run(tauri::generate_context!()) {
|
||||
tracing::error!("error while running tauri application: {:?}", err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user