mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-10 04:22:13 +10:00
Clippy refactoring
This commit is contained in:
@ -1,8 +1,5 @@
|
||||
use core::time;
|
||||
use std::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
env,
|
||||
fmt::format,
|
||||
sync::Mutex, time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@ -11,12 +8,11 @@ use openssl::{
|
||||
ec::EcKey,
|
||||
hash::MessageDigest,
|
||||
pkey::PKey,
|
||||
sign::{self, Signer},
|
||||
sign::{Signer},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::{http::response, App, AppHandle, Emitter, EventLoopMessage, Manager, Wry};
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{db::DatabaseAuth, AppState, AppStatus, User, DB};
|
||||
|
||||
@ -62,7 +58,7 @@ pub fn sign_nonce(private_key: String, nonce: String) -> Result<String, ()> {
|
||||
|
||||
let hex_signature = hex::encode(signature);
|
||||
|
||||
return Ok(hex_signature);
|
||||
Ok(hex_signature)
|
||||
}
|
||||
|
||||
pub fn generate_authorization_header() -> String {
|
||||
@ -79,7 +75,7 @@ pub fn generate_authorization_header() -> String {
|
||||
|
||||
let signature = sign_nonce(certs.private, nonce.clone()).unwrap();
|
||||
|
||||
return format!("Nonce {} {} {}", certs.client_id, nonce, signature);
|
||||
format!("Nonce {} {} {}", certs.client_id, nonce, signature)
|
||||
}
|
||||
|
||||
pub fn fetch_user() -> Result<User, ()> {
|
||||
@ -105,7 +101,7 @@ pub fn fetch_user() -> Result<User, ()> {
|
||||
|
||||
let user = response.json::<User>().unwrap();
|
||||
|
||||
return Ok(user);
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub fn recieve_handshake(app: AppHandle, path: String) {
|
||||
@ -166,7 +162,7 @@ pub async fn auth_initiate<'a>() -> Result<(), String> {
|
||||
|
||||
let endpoint = base_url.join("/api/v1/client/auth/initiate").unwrap();
|
||||
let body = InitiateRequestBody {
|
||||
name: format!("Drop Desktop Client"),
|
||||
name: "Drop Desktop Client".to_string(),
|
||||
platform: env::consts::OS.to_string(),
|
||||
};
|
||||
|
||||
@ -186,9 +182,9 @@ pub async fn auth_initiate<'a>() -> Result<(), String> {
|
||||
let complete_redir_url = base_url.join(&redir_url).unwrap();
|
||||
|
||||
info!("opening web browser to continue authentication");
|
||||
webbrowser::open(&complete_redir_url.to_string()).unwrap();
|
||||
webbrowser::open(complete_redir_url.as_ref()).unwrap();
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn setup() -> Result<(AppStatus, Option<User>), ()> {
|
||||
@ -205,5 +201,5 @@ pub fn setup() -> Result<(AppStatus, Option<User>), ()> {
|
||||
|
||||
drop(data);
|
||||
|
||||
return Ok((AppStatus::SignedOut, None));
|
||||
Ok((AppStatus::SignedOut, None))
|
||||
}
|
||||
|
||||
@ -50,12 +50,13 @@ pub fn setup() -> DatabaseInterface {
|
||||
apps_base_dir: apps_base_dir.to_str().unwrap().to_string(),
|
||||
},
|
||||
};
|
||||
#[allow(clippy::let_and_return)]
|
||||
let db = match fs::exists(db_path.clone()).unwrap() {
|
||||
true => PathDatabase::load_from_path(db_path).expect("Database loading failed"),
|
||||
false => PathDatabase::create_at_path(db_path, default).unwrap(),
|
||||
};
|
||||
|
||||
return db;
|
||||
db
|
||||
}
|
||||
|
||||
pub fn is_set_up() -> bool {
|
||||
|
||||
@ -3,19 +3,13 @@ mod db;
|
||||
mod remote;
|
||||
mod unpacker;
|
||||
|
||||
use std::{
|
||||
io,
|
||||
sync::{LazyLock, Mutex},
|
||||
task, thread,
|
||||
};
|
||||
use env_logger;
|
||||
use std::sync::{LazyLock, Mutex};
|
||||
use env_logger::Env;
|
||||
use auth::{auth_initiate, recieve_handshake};
|
||||
use db::{DatabaseInterface, DATA_ROOT_DIR};
|
||||
use log::info;
|
||||
use remote::{gen_drop_url, use_remote};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use structured_logger::{json::new_writer, Builder};
|
||||
use tauri_plugin_deep_link::DeepLinkExt;
|
||||
|
||||
#[derive(Clone, Copy, Serialize)]
|
||||
@ -61,13 +55,13 @@ fn setup() -> AppState {
|
||||
}
|
||||
|
||||
let auth_result = auth::setup().unwrap();
|
||||
return AppState {
|
||||
AppState {
|
||||
status: auth_result.0,
|
||||
user: auth_result.1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(|| db::setup());
|
||||
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(db::setup);
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
@ -103,7 +97,7 @@ pub fn run() {
|
||||
|
||||
let handle = app.handle().clone();
|
||||
|
||||
let main_window = tauri::WebviewWindowBuilder::new(
|
||||
let _main_window = tauri::WebviewWindowBuilder::new(
|
||||
&handle,
|
||||
"main", // BTW this is not the name of the window, just the label. Keep this 'main', there are permissions & configs that depend on it
|
||||
tauri::WebviewUrl::App("index.html".into()),
|
||||
@ -119,7 +113,7 @@ pub fn run() {
|
||||
app.deep_link().on_open_url(move |event| {
|
||||
info!("handling drop:// url");
|
||||
let binding = event.urls();
|
||||
let url = binding.get(0).unwrap();
|
||||
let url = binding.first().unwrap();
|
||||
if url.host_str().unwrap() == "handshake" {
|
||||
recieve_handshake(handle.clone(), url.path().to_string())
|
||||
}
|
||||
|
||||
@ -1,12 +1,7 @@
|
||||
use std::{
|
||||
borrow::{Borrow, BorrowMut},
|
||||
sync::Mutex,
|
||||
};
|
||||
use std::sync::Mutex;
|
||||
|
||||
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};
|
||||
@ -60,11 +55,11 @@ pub async fn use_remote<'a>(
|
||||
|
||||
DB.save().unwrap();
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn gen_drop_url(app: tauri::AppHandle, path: String) -> Result<String, String> {
|
||||
pub fn gen_drop_url(path: String) -> Result<String, String> {
|
||||
let base_url = {
|
||||
let handle = DB.borrow_data().unwrap();
|
||||
|
||||
@ -77,5 +72,5 @@ pub fn gen_drop_url(app: tauri::AppHandle, path: String) -> Result<String, Strin
|
||||
|
||||
let url = base_url.join(&path).unwrap();
|
||||
|
||||
return Ok(url.to_string());
|
||||
Ok(url.to_string())
|
||||
}
|
||||
|
||||
@ -64,5 +64,5 @@ pub async fn unpack() -> Result<(), Error> {
|
||||
}
|
||||
});
|
||||
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user