another stage of client authentication

This commit is contained in:
DecDuck
2024-10-08 16:13:28 +11:00
parent 22b1aeec9f
commit ae4c65b7ab
22 changed files with 802 additions and 83 deletions

View File

@ -4,10 +4,10 @@ use std::{
};
use serde::{Deserialize, Serialize};
use tauri::Error;
use tauri::{App, AppHandle, Emitter, Error, EventLoopMessage, Wry};
use url::Url;
use crate::{data::DatabaseInterface, AppState, AppStatus, User, DB};
use crate::{AppStatus, User, DB};
#[derive(Serialize)]
struct InitiateRequestBody {
@ -15,6 +15,13 @@ struct InitiateRequestBody {
platform: String,
}
pub async fn recieve_handshake(app: AppHandle, path: String) {
// Tell the app we're connecting
app.emit("auth/connecting", ()).unwrap();
// TODO
}
#[tauri::command]
pub async fn auth_initiate<'a>() -> Result<(), String> {
let base_url = {

View File

@ -19,7 +19,8 @@ pub struct Database {
pub base_url: String,
}
pub type DatabaseInterface = rustbreak::Database<Database, rustbreak::backend::PathBackend, Bincode>;
pub type DatabaseInterface =
rustbreak::Database<Database, rustbreak::backend::PathBackend, Bincode>;
pub fn setup() -> DatabaseInterface {
let db_path = BaseDirs::new().unwrap().data_dir().join("drop");

View File

@ -4,14 +4,16 @@ mod remote;
mod unpacker;
use std::{
borrow::Borrow,
sync::{LazyLock, Mutex},
task, thread,
};
use auth::auth_initiate;
use auth::{auth_initiate, recieve_handshake};
use data::DatabaseInterface;
use futures::executor;
use remote::use_remote;
use serde::Serialize;
use tauri_plugin_deep_link::DeepLinkExt;
#[derive(Clone, Copy, Serialize)]
pub enum AppStatus {
@ -59,7 +61,18 @@ pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(|| data::setup());
pub fn run() {
let state = setup();
tauri::Builder::default()
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
}));
}
builder
.plugin(tauri_plugin_deep_link::init())
.manage(Mutex::new(state))
.invoke_handler(tauri::generate_handler![
fetch_state,
@ -67,6 +80,30 @@ pub fn run() {
use_remote
])
.plugin(tauri_plugin_shell::init())
.setup(|app| {
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
{
use tauri_plugin_deep_link::DeepLinkExt;
app.deep_link().register_all()?;
}
let handle = app.handle().clone();
app.deep_link().on_open_url(move |event| {
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(),
));
}
_ => (),
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -4,4 +4,3 @@
fn main() {
drop_app_lib::run()
}