handshakes

This commit is contained in:
DecDuck
2024-10-08 18:08:52 +11:00
parent ae4c65b7ab
commit 4bb33c8223
9 changed files with 285 additions and 43 deletions
+12 -9
View File
@@ -4,15 +4,17 @@ mod remote;
mod unpacker;
use std::{
io,
sync::{LazyLock, Mutex},
task, thread,
};
use auth::{auth_initiate, recieve_handshake};
use data::DatabaseInterface;
use futures::executor;
use log::info;
use remote::use_remote;
use serde::Serialize;
use structured_logger::{json::new_writer, Builder};
use tauri_plugin_deep_link::DeepLinkExt;
#[derive(Clone, Copy, Serialize)]
@@ -40,6 +42,10 @@ fn fetch_state<'a>(state: tauri::State<'_, Mutex<AppState>>) -> Result<AppState,
}
fn setup<'a>() -> AppState {
Builder::with_level("info")
.with_target_writer("*", new_writer(io::stdout()))
.init();
let is_set_up = data::is_set_up();
if !is_set_up {
return AppState {
@@ -60,14 +66,14 @@ pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(|| data::setup());
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let state = setup();
info!("Initialized drop client");
let mut builder = tauri::Builder::default();
#[cfg(desktop)]
{
builder = builder.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| {
println!("a new app instance was opened with {argv:?} and the deep link event was already triggered");
// when defining deep link schemes at runtime, you must also check `argv` here
// when defining deep link schemes at runtime, you must also check `argv` here
}));
}
@@ -85,20 +91,17 @@ pub fn run() {
{
use tauri_plugin_deep_link::DeepLinkExt;
app.deep_link().register_all()?;
info!("registered all pre-defined deep links");
}
let handle = app.handle().clone();
app.deep_link().on_open_url(move |event| {
info!("handling drop:// url");
let binding = event.urls();
let url = binding.get(0).unwrap();
match url.host_str().unwrap() {
"handshake" => {
executor::block_on(recieve_handshake(
handle.clone(),
url.path().to_string(),
));
}
"handshake" => recieve_handshake(handle.clone(), url.path().to_string()),
_ => (),
}
});