53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use crate::services::cursor::channel_cursor_positions;
|
|
|
|
static APP_HANDLE: std::sync::OnceLock<tauri::AppHandle<tauri::Wry>> = std::sync::OnceLock::new();
|
|
|
|
mod app;
|
|
mod core;
|
|
mod services;
|
|
|
|
/// Tauri app handle
|
|
pub fn get_app_handle<'a>() -> &'a tauri::AppHandle<tauri::Wry> {
|
|
APP_HANDLE
|
|
.get()
|
|
.expect("get_app_handle called but app is still not initialized")
|
|
}
|
|
|
|
fn setup_fdoll() -> Result<(), tauri::Error> {
|
|
core::state::init_fdoll_state();
|
|
tokio::spawn(async move { app::start_fdoll().await });
|
|
Ok(())
|
|
}
|
|
|
|
fn register_app_events(event: tauri::RunEvent) {
|
|
match event {
|
|
tauri::RunEvent::ExitRequested { api, code, .. } => {
|
|
if code.is_none() {
|
|
api.prevent_exit();
|
|
} else {
|
|
println!("exit code: {:?}", code);
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
pub fn run() {
|
|
tauri::Builder::default()
|
|
.plugin(tauri_plugin_opener::init())
|
|
.plugin(tauri_plugin_positioner::init())
|
|
.plugin(tauri_plugin_opener::init())
|
|
.invoke_handler(tauri::generate_handler![channel_cursor_positions])
|
|
.setup(|app| {
|
|
APP_HANDLE
|
|
.set(app.handle().to_owned())
|
|
.expect("Failed to init app handle.");
|
|
setup_fdoll().expect("Failed to setup app.");
|
|
Ok(())
|
|
})
|
|
.build(tauri::generate_context!())
|
|
.expect("error while running tauri application")
|
|
.run(|_, event| register_app_events(event));
|
|
}
|