creddy/src-tauri/src/main.rs

54 lines
1.5 KiB
Rust
Raw Normal View History

2022-08-14 20:27:41 +00:00
#![cfg_attr(
2022-12-14 05:50:34 +00:00
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
2022-08-14 20:27:41 +00:00
)]
use tauri::Manager;
mod config;
2022-11-29 00:16:33 +00:00
mod errors;
2022-12-04 05:47:09 +00:00
mod clientinfo;
2022-11-29 00:16:33 +00:00
mod ipc;
mod state;
mod server;
2022-12-21 22:49:01 +00:00
mod tray;
2022-08-14 20:27:41 +00:00
use state::AppState;
2022-08-14 20:27:41 +00:00
fn main() {
2022-12-14 05:50:34 +00:00
let initial_state = match state::AppState::new() {
Ok(state) => state,
Err(e) => {eprintln!("{}", e); return;}
};
tauri::Builder::default()
.manage(initial_state)
2022-12-21 22:49:01 +00:00
.system_tray(tray::create())
.on_system_tray_event(tray::handle_event)
2022-12-14 05:50:34 +00:00
.invoke_handler(tauri::generate_handler![
ipc::unlock,
ipc::respond,
ipc::get_session_status,
ipc::save_credentials,
])
.setup(|app| {
let state = app.state::<AppState>();
let config = state.config.read().unwrap();
let addr = std::net::SocketAddrV4::new(config.listen_addr, config.listen_port);
2022-12-14 05:50:34 +00:00
tauri::async_runtime::spawn(server::serve(addr, app.handle()));
Ok(())
})
2022-12-21 22:49:01 +00:00
.build(tauri::generate_context!())
.expect("error while running tauri application")
.run(|app, run_event| match run_event {
tauri::RunEvent::WindowEvent { label, event, .. } => match event {
tauri::WindowEvent::CloseRequested { api, .. } => {
let _ = app.get_window(&label).map(|w| w.hide());
api.prevent_close();
}
_ => ()
}
_ => ()
})
2022-11-29 00:16:33 +00:00
}