Fix some issues

This commit is contained in:
Quentin Legot 2023-04-22 01:51:05 +02:00
parent 6cdf71b5b6
commit e8c92cf7f0
2 changed files with 47 additions and 25 deletions

View File

@ -6,7 +6,7 @@
pub mod authentification;
pub mod launcher;
use std::sync::{Mutex, Arc};
use std::sync::Mutex;
use authentification::{Authentification, Prompt, GameProfile};
use anyhow::Result;
@ -27,24 +27,33 @@ async fn login(app: tauri::AppHandle, _window: tauri::Window, state: tauri::Stat
match result {
Ok(val) => {
let name = val.name.clone();
state.lock().unwrap().0.replace(val);
match state.lock() {
Ok(mut game_profile) => {
game_profile.0 = Some(val);
Ok(format!("Hello {}", name))
},
Err(err) => {
Err(err.to_string())
}
}
},
Err(err) => Err(err.to_string())
}
}
#[tauri::command]
async fn download(app: tauri::AppHandle, _window: tauri::Window, state: tauri::State<'_, Mutex<CustomState>>) -> Result<String, String> {
async fn download(state: tauri::State<'_, Mutex<CustomState>>) -> Result<String, String> {
if let Some(base_dir) = BaseDirs::new() {
let data_folder = base_dir.data_dir().join(".altarik");
let root_path = data_folder.as_path();
match state.lock() {
Ok(game_profile) => {
let game_profile = game_profile.0.as_ref().unwrap();
match &game_profile.0 {
Some(game_profile) => {
let java_path = root_path.join("java");
let opts = ClientOptions {
authorization: &game_profile,
authorization: game_profile,
root_path,
java_path: &java_path.as_path(),
version_number: "1.19.4".to_string(),
@ -69,6 +78,12 @@ async fn download(app: tauri::AppHandle, _window: tauri::Window, state: tauri::S
}
}
},
None => {
Err("You're not connected".to_string())
}
}
},
Err(err) => {
Err(err.to_string())
}
@ -82,7 +97,7 @@ async fn download(app: tauri::AppHandle, _window: tauri::Window, state: tauri::S
#[tokio::main]
async fn main() {
tauri::Builder::default()
.manage(Arc::new(CustomState(None)))
.manage(Mutex::new(CustomState(None)))
.invoke_handler(tauri::generate_handler![greet, login, download])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View File

@ -22,7 +22,14 @@ export default {
}
},
download (e) {
e.preventDefault()
if(!this.hideDownloadButton) {
this.invoke("download", {}).then(value => {
this.greet_message = value
}).catch(err => {
this.greet_message = "Error: " + err
})
}
},
},
props: {