client now fetches user information from Drop server

This commit is contained in:
DecDuck
2024-10-09 16:52:24 +11:00
parent ac1c3b609a
commit 0c0cfebc1e
11 changed files with 113 additions and 39 deletions

View File

@ -185,7 +185,6 @@ pub fn setup() -> Result<(AppStatus, Option<User>), Error> {
let user_result = fetch_user();
if user_result.is_err() {
return Ok((AppStatus::SignedInNeedsReauth, None));
}
return Ok((AppStatus::SignedIn, Some(user_result.unwrap())))
}

View File

@ -12,7 +12,7 @@ use std::{
use auth::{auth_initiate, recieve_handshake};
use data::DatabaseInterface;
use log::info;
use remote::use_remote;
use remote::{gen_drop_url, open_url, use_remote};
use serde::{Deserialize, Serialize};
use structured_logger::{json::new_writer, Builder};
use tauri_plugin_deep_link::DeepLinkExt;
@ -24,10 +24,16 @@ pub enum AppStatus {
SignedIn,
SignedInNeedsReauth,
}
#[derive(Clone, Copy, Serialize, Deserialize)]
pub struct User {}
#[derive(Clone, Serialize, Deserialize)]
pub struct User {
id: String,
username: String,
admin: bool,
displayName: String,
profilePicture: String,
}
#[derive(Clone, Copy, Serialize)]
#[derive(Clone, Serialize)]
pub struct AppState {
status: AppStatus,
user: Option<User>,
@ -83,7 +89,9 @@ pub fn run() {
.invoke_handler(tauri::generate_handler![
fetch_state,
auth_initiate,
use_remote
use_remote,
gen_drop_url,
open_url,
])
.plugin(tauri_plugin_shell::init())
.setup(|app| {

View File

@ -4,7 +4,9 @@ use std::{
};
use log::{info, warn};
use openssl::x509::store::HashDir;
use serde::Deserialize;
use tauri::async_runtime::handle;
use url::Url;
use crate::{AppState, AppStatus, DB};
@ -59,3 +61,26 @@ pub async fn use_remote<'a>(
return Ok(());
}
#[tauri::command]
pub fn open_url(path: String) -> Result<(), String> {
webbrowser::open(&path).unwrap();
Ok(())
}
#[tauri::command]
pub fn gen_drop_url(app: tauri::AppHandle, path: String) -> Result<String, String> {
let base_url = {
let handle = DB.borrow_data().unwrap();
if handle.base_url.is_empty() {
return Ok("".to_string());
};
Url::parse(&handle.base_url).unwrap()
};
let url = base_url.join(&path).unwrap();
return Ok(url.to_string());
}

View File

@ -1,6 +1,6 @@
{
"$schema": "https://schema.tauri.app/config/2.0.0",
"productName": "drop",
"productName": "Drop Desktop Client",
"version": "0.1.0",
"identifier": "dev.drop.app",
"build": {