This commit is contained in:
2026-04-20 20:14:40 +02:00
parent 4261291ac1
commit 176fe3db99
21 changed files with 1445 additions and 132 deletions

View File

@@ -28,7 +28,5 @@ tauri.workspace = true
tauri-plugin-tracing.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-appender.workspace = true
tracing-subscriber.workspace = true
ts-rs.workspace = true
uuid.workspace = true

View File

@@ -1,3 +1,18 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type SplashOrder = { order: string, msg: string | null, status: string | null, };
/**
* Command payload sent from Rust to the splash frontend.
*/
export type SplashOrder = {
/**
* Splash command name such as `fadein`, `fadeout`, `add_msg`, or `add_log`.
*/
order: string,
/**
* Optional message payload attached to the command.
*/
msg: string | null,
/**
* Optional status payload attached to the command.
*/
status: string | null, };

View File

@@ -7,12 +7,13 @@ import ResizeObserver from "resize-observer-polyfill";
//import { listen, type UnlistenFn } from "@tauri-apps/api/event";
//import { error } from "@fltsci/tauri-plugin-tracing";
//import { info } from "@fltsci/tauri-plugin-tracing";
import { trace } from "@fltsci/tauri-plugin-tracing";
import { trace, takeoverConsole } from "@fltsci/tauri-plugin-tracing";
(window as Window & typeof globalThis & { bootstrap?: typeof bootstrap }).bootstrap = bootstrap;
(window as Window & typeof globalThis & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver = ResizeObserver;
document.addEventListener("DOMContentLoaded", () => {
void takeoverConsole();
const sidebarToggle = document.querySelector<HTMLButtonElement>('#sidebarToggle');
if (sidebarToggle) {
// restaurer létat depuis localStorage

View File

@@ -1,7 +1,6 @@
// file: kb_app/frontend/ts/splash.ts
import { error } from "@fltsci/tauri-plugin-tracing";
import { info } from "@fltsci/tauri-plugin-tracing";
import { error, info, takeoverConsole } from "@fltsci/tauri-plugin-tracing";
import { listen } from '@tauri-apps/api/event';
import { SplashOrder } from './bindings/SplashOrder.ts';
@@ -90,7 +89,7 @@ listen("splash", (event) => {
//window.addEventListener('DOMContentLoaded', initialize);
document.addEventListener("DOMContentLoaded", () => {
void takeoverConsole();
info("window loaded");
});

View File

@@ -1,7 +1,7 @@
{
"name": "kb-app",
"private": true,
"version": "0.0.1",
"version": "0.0.2",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,136 +1,145 @@
// file: kb_app/src/lib.rs
//#![deny(unreachable_pub)]
//#![warn(missing_docs)]
//! Tauri application library for `khadhroony-bobobot`.
//!
//! This crate is intentionally thin. It loads the shared configuration,
//! initializes shared tracing from `kb_lib`, and wires the desktop shell
//! to the reusable backend logic.
#![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()
}
use tauri::Manager;
/// Runs the desktop application.
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let tracing_builder = setup_logger();
let config_path = kb_lib::KbConfig::default_path();
let config_result = kb_lib::KbConfig::load_from_path(&config_path);
let config = match config_result {
Ok(config) => config,
Err(error) => {
eprintln!(
"kb_app configuration load error from '{}': {}",
config_path.display(),
error
);
return;
}
};
let prepare_result = config.prepare_filesystem();
if let Err(error) = prepare_result {
eprintln!("kb_app filesystem preparation error: {error}");
return;
}
let tracing_guard_result = kb_lib::init_tracing(&config.logging);
let _tracing_guard = match tracing_guard_result {
Ok(guard) => guard,
Err(error) => {
eprintln!("kb_app tracing initialization error: {error}");
return;
}
};
tracing::info!(
app_name = %config.app.name,
environment = %config.app.environment,
"starting desktop application"
);
let tracing_builder = tauri_plugin_tracing::Builder::new();
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 splash_window_option = app_handle.get_webview_window("splash");
let splash_window = match splash_window_option {
Some(window) => window,
None => {
tracing::error!("splash window not found");
return;
}
};
let main_window_option = app_handle.get_webview_window("main");
let main_window = match main_window_option {
Some(window) => window,
None => {
tracing::error!("main window not found");
return;
}
};
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,
},
);
emit_splash_order(&splash_window, "add_log", Some("Start Fade-In"), 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()),
},
emit_splash_order(&splash_window, "fadein", None, None);
emit_splash_order(
&splash_window,
"add_msg",
Some("Initialisation..."),
Some("info"),
);
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()),
},
emit_splash_order(
&splash_window,
"add_msg",
Some("Loading resources..."),
Some("info"),
);
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()),
},
emit_splash_order(
&splash_window,
"add_msg",
Some("Loading complete..."),
Some("success"),
);
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
tracing::debug!("Start fadeout");
tracing::debug!("start splash 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,
},
);
emit_splash_order(&splash_window, "add_log", Some("Start Fade-out"), None);
}
let _ = splash_window.emit(
"splash",
splash::SplashOrder {
order: "fadeout".to_string(),
msg: None,
status: None,
},
);
tracing::debug!("End fadeout");
emit_splash_order(&splash_window, "fadeout", None, None);
tracing::debug!("end splash 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);
let close_result = splash_window.close();
if let Err(error) = close_result {
tracing::error!("error closing splash window: {error:?}");
}
if let Err(err) = main_window.show() {
tracing::error!("Error showing main window: {:?}", err);
let show_result = main_window.show();
if let Err(error) = show_result {
tracing::error!("error showing main window: {error:?}");
} else {
let _ = main_window.emit("setupTray", ());
let emit_result = main_window.emit("setupTray", ());
if let Err(error) = emit_result {
tracing::error!("error emitting setupTray event: {error:?}");
}
}
});
Ok(())
});
if let Err(err) = tauri_builder.run(tauri::generate_context!()) {
tracing::error!("error while running tauri application: {:?}", err);
let run_result = tauri_builder.run(tauri::generate_context!());
if let Err(error) = run_result {
tracing::error!("error while running tauri application: {error:?}");
}
}
fn emit_splash_order(
splash_window: &tauri::WebviewWindow,
order: &str,
msg: std::option::Option<&str>,
status: std::option::Option<&str>,
) {
let payload = crate::SplashOrder {
order: order.to_string(),
msg: msg.map(std::string::ToString::to_string),
status: status.map(std::string::ToString::to_string),
};
let emit_result = splash_window.emit("splash", payload);
if let Err(error) = emit_result {
tracing::error!("error emitting splash event '{order}': {error:?}");
}
}

View File

@@ -31,7 +31,6 @@ fn main() -> std::process::ExitCode
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 {
@@ -41,8 +40,7 @@ fn main() -> std::process::ExitCode
return std::process::ExitCode::FAILURE;
},
}
}
}
kb_app_lib::run();
std::process::ExitCode::SUCCESS
}

View File

@@ -1,9 +1,18 @@
// file: kb_app/src/splash.rs
//! Shared splash-screen payload types.
//!
//! These types are serialized by the Rust backend and exported to the
//! TypeScript frontend through `ts-rs`.
/// Command payload sent from Rust to the splash frontend.
#[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>,
}
/// Splash command name such as `fadein`, `fadeout`, `add_msg`, or `add_log`.
pub order: std::string::String,
/// Optional message payload attached to the command.
pub msg: std::option::Option<std::string::String>,
/// Optional status payload attached to the command.
pub status: std::option::Option<std::string::String>,
}

View File

@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "kb-bapp",
"version": "0.0.1",
"version": "0.0.2",
"identifier": "com.sasedev.kb-app",
"build": {
"beforeDevCommand": "npm run dev",