sovereignty over app lifecycle
This commit is contained in:
@@ -1,8 +1,50 @@
|
||||
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_global_shortcut::Builder::new().build())
|
||||
.invoke_handler(tauri::generate_handler![])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
.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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user