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);
|
||||
}
|
||||
}
|
||||
48
kb_app/src/main.rs
Normal file
48
kb_app/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
// file: kb_app/src/main.rs
|
||||
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
//! Binary entrypoint for the kb application.
|
||||
//!
|
||||
//! This binary remains intentionally thin and delegates its logic to `kb_lib`.
|
||||
|
||||
#![deny(unreachable_pub)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use fs2::FileExt;
|
||||
|
||||
/// Entrypoint of the kb app binary.
|
||||
#[tokio::main]
|
||||
async
|
||||
fn main() -> std::process::ExitCode
|
||||
{
|
||||
let mut lock_path = std::env::temp_dir();
|
||||
lock_path.push("com_khadhroony_solana_rust.lock");
|
||||
let lock_file = match std::fs::File::create(lock_path) {
|
||||
Ok(lock) => lock,
|
||||
Err(_err) => {
|
||||
eprintln!("Cannot create lock!");
|
||||
std::process::exit(1);
|
||||
},
|
||||
};
|
||||
// trying to aquire an exclusive lock
|
||||
if lock_file.try_lock_exclusive().is_err() {
|
||||
eprintln!("Another instance of the app is already running!");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if rustls::crypto::CryptoProvider::get_default().is_none() {
|
||||
let provider_result = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
||||
match provider_result {
|
||||
Ok(()) => {},
|
||||
Err(error) => {
|
||||
eprintln!("kb_app rustls provider init error: {:?}", error);
|
||||
return std::process::ExitCode::FAILURE;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
kb_app_lib::run();
|
||||
std::process::ExitCode::SUCCESS
|
||||
}
|
||||
9
kb_app/src/splash.rs
Normal file
9
kb_app/src/splash.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
// file: kb_app/src/splash.rs
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, ts_rs::TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/SplashOrder.ts")]
|
||||
pub struct SplashOrder {
|
||||
pub order: String,
|
||||
pub msg: Option<String>,
|
||||
pub status: Option<String>,
|
||||
}
|
||||
Reference in New Issue
Block a user