drop no longer freaks out if server is unavailable on startup

This commit is contained in:
DecDuck
2024-11-03 16:16:26 +11:00
parent 57a5737b6c
commit df88395d98
6 changed files with 211 additions and 81 deletions

View File

@ -4,6 +4,7 @@ mod library;
mod remote;
mod unpacker;
use crate::db::DatabaseImpls;
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
use db::{DatabaseInterface, DATA_ROOT_DIR};
use env_logger::Env;
@ -13,20 +14,22 @@ use log::info;
use remote::{gen_drop_url, use_remote};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap, sync::{LazyLock, Mutex}
collections::HashMap,
sync::{LazyLock, Mutex},
};
use tauri_plugin_deep_link::DeepLinkExt;
use crate::db::DatabaseImpls;
#[derive(Clone, Copy, Serialize)]
pub enum AppStatus {
NotConfigured,
ServerError,
SignedOut,
SignedIn,
SignedInNeedsReauth,
ServerUnavailable,
}
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all="camelCase")]
#[serde(rename_all = "camelCase")]
pub struct User {
id: String,
username: String,
@ -36,7 +39,7 @@ pub struct User {
}
#[derive(Clone, Serialize)]
#[serde(rename_all="camelCase")]
#[serde(rename_all = "camelCase")]
pub struct AppState {
status: AppStatus,
user: Option<User>,
@ -63,10 +66,10 @@ fn setup() -> AppState {
};
}
let auth_result = auth::setup().unwrap();
let (app_status, user) = auth::setup().unwrap();
AppState {
status: auth_result.0,
user: auth_result.1,
status: app_status,
user: user,
games: HashMap::new(),
}
}
@ -130,7 +133,9 @@ pub fn run() {
info!("handling drop:// url");
let binding = event.urls();
let url = binding.first().unwrap();
if url.host_str().unwrap() == "handshake" { recieve_handshake(handle.clone(), url.path().to_string()) }
if url.host_str().unwrap() == "handshake" {
recieve_handshake(handle.clone(), url.path().to_string())
}
});
Ok(())