mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
feat: add offline widget & remove openssl in favour of droplet-rs
This commit is contained in:
@ -25,7 +25,10 @@ use download_manager::commands::{
|
||||
};
|
||||
use download_manager::download_manager::DownloadManager;
|
||||
use download_manager::download_manager_builder::DownloadManagerBuilder;
|
||||
use games::collections::commands::{add_game_to_collection, create_collection, delete_collection, delete_game_in_collection, fetch_collection, fetch_collections};
|
||||
use games::collections::commands::{
|
||||
add_game_to_collection, create_collection, delete_collection, delete_game_in_collection,
|
||||
fetch_collection, fetch_collections,
|
||||
};
|
||||
use games::commands::{
|
||||
fetch_game, fetch_game_status, fetch_game_verion_options, fetch_library, uninstall_game,
|
||||
};
|
||||
@ -43,7 +46,8 @@ use process::commands::{kill_game, launch_game};
|
||||
use process::process_manager::ProcessManager;
|
||||
use remote::auth::{self, recieve_handshake};
|
||||
use remote::commands::{
|
||||
auth_initiate, fetch_drop_object, gen_drop_url, manual_recieve_handshake, retry_connect, sign_out, use_remote
|
||||
auth_initiate, fetch_drop_object, gen_drop_url, manual_recieve_handshake, retry_connect,
|
||||
sign_out, use_remote,
|
||||
};
|
||||
use remote::fetch_object::{fetch_object, fetch_object_offline};
|
||||
use remote::requests::make_request;
|
||||
@ -84,6 +88,7 @@ pub struct User {
|
||||
profile_picture: String,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AppState<'a> {
|
||||
@ -370,7 +375,13 @@ pub fn run() {
|
||||
})
|
||||
.register_asynchronous_uri_scheme_protocol("object", move |ctx, request, responder| {
|
||||
let state: tauri::State<'_, Mutex<AppState>> = ctx.app_handle().state();
|
||||
offline!(state, fetch_object, fetch_object_offline, request, responder);
|
||||
offline!(
|
||||
state,
|
||||
fetch_object,
|
||||
fetch_object_offline,
|
||||
request,
|
||||
responder
|
||||
);
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
use std::{env, sync::Mutex};
|
||||
|
||||
use chrono::Utc;
|
||||
use droplet_rs::ssl::sign_nonce;
|
||||
use log::{debug, error, warn};
|
||||
use openssl::{ec::EcKey, hash::MessageDigest, pkey::PKey, sign::Signer};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use tauri::{AppHandle, Emitter, Manager};
|
||||
use url::Url;
|
||||
|
||||
@ -39,20 +40,6 @@ struct HandshakeResponse {
|
||||
id: String,
|
||||
}
|
||||
|
||||
// TODO: Change return value on Err
|
||||
pub fn sign_nonce(private_key: String, nonce: String) -> Result<String, ()> {
|
||||
let client_private_key = EcKey::private_key_from_pem(private_key.as_bytes()).unwrap();
|
||||
let pkey_private_key = PKey::from_ec_key(client_private_key).unwrap();
|
||||
|
||||
let mut signer = Signer::new(MessageDigest::sha256(), &pkey_private_key).unwrap();
|
||||
signer.update(nonce.as_bytes()).unwrap();
|
||||
let signature = signer.sign_to_vec().unwrap();
|
||||
|
||||
let hex_signature = hex::encode(signature);
|
||||
|
||||
Ok(hex_signature)
|
||||
}
|
||||
|
||||
pub fn generate_authorization_header() -> String {
|
||||
let certs = {
|
||||
let db = borrow_db_checked();
|
||||
@ -133,6 +120,23 @@ fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), RemoteAc
|
||||
let mut app_state_handle = app_state.lock().unwrap();
|
||||
app_state_handle.status = AppStatus::SignedIn;
|
||||
app_state_handle.user = Some(fetch_user()?);
|
||||
|
||||
// Setup capabilities
|
||||
let endpoint = base_url.join("/api/v1/client/capability")?;
|
||||
let header = generate_authorization_header();
|
||||
let body = json!({
|
||||
"capability": "cloudSaves",
|
||||
"configuration": {}
|
||||
});
|
||||
let response = client
|
||||
.post(endpoint)
|
||||
.header("Authorization", header)
|
||||
.json(&body)
|
||||
.send()?;
|
||||
|
||||
if response.status().is_success() {
|
||||
debug!("registered client for 'cloudSaves' capability")
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user