Skip to content

Commit

Permalink
Merge branch 'tauri_v2' of https://github.com/CCBlueX/LiquidLauncher
Browse files Browse the repository at this point in the history
…into tauri_v2
  • Loading branch information
SenkJu committed Mar 23, 2024
2 parents 167404d + 342a350 commit ec4b43a
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 171 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "liquidlauncher",
"private": true,
"version": "0.2.2",
"version": "0.2.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
47 changes: 24 additions & 23 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "liquidlauncher"
version = "0.2.2"
version = "0.2.4"
description = "A LiquidBounce launcher for Minecraft, written in Rust using Tauri."
authors = ["1zuna <marco@ccbluex.net>", "superblaubeere27"]
license = "GNU General Public License v3.0"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dialog:allow-message",
"dialog:allow-open",
"dialog:allow-confirm",
"dialog:allow-ask",
"shell:allow-open",
"process:allow-exit",
"updater:default"
Expand Down
35 changes: 28 additions & 7 deletions src-tauri/src/app/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use std::{sync::{Arc, Mutex}, thread, path::PathBuf};

use anyhow::anyhow;
use tokio::fs;
use tracing::{error, info, debug};
use tauri::{Manager, Window};
Expand All @@ -38,13 +39,25 @@ struct AppState {
runner_instance: Arc<Mutex<Option<RunnerInstance>>>
}

const ERROR_MSG: &str = "Try restarting the LiquidLauncher with administrator rights.\nIf this error persists, upload your log with the button below and report it to GitHub.";

#[tauri::command]
async fn get_launcher_version() -> Result<String, String> {
Ok(LAUNCHER_VERSION.to_string())
}

#[tauri::command]
async fn check_online_status() -> Result<(), String> {
async fn check_health() -> Result<(), String> {
// Check hosts
#[cfg(windows)]
{
use crate::utils::check_hosts_file;

info!("Checking hosts file...");
check_hosts_file().await
.map_err(|e| format!("{}", e))?;
}

info!("Checking online status");
HTTP_CLIENT.get("https://api.liquidbounce.net/")
.send().await
Expand Down Expand Up @@ -118,7 +131,7 @@ async fn login_microsoft(window: tauri::Window) -> Result<MinecraftAccount, Stri
debug!("enter code {} on {} to sign-in", code, uri);

let _ = window.emit("microsoft_code", code);
}).await.map_err(|e| e.to_string())?;
}).await.map_err(|e| format!("{}", e))?;

Ok(account)
}
Expand Down Expand Up @@ -191,14 +204,22 @@ async fn delete_custom_mod(branch: &str, mc_version: &str, mod_name: &str) -> Re
Ok(())
}

pub fn log(window: &Arc<std::sync::Mutex<Window>>, msg: &str) {
info!("{}", msg);

if let Ok(k) = window.lock() {
let _ = k.emit("process-output", msg);
}
}

fn handle_stdout(window: &Arc<std::sync::Mutex<Window>>, data: &[u8]) -> anyhow::Result<()> {
let data = String::from_utf8(data.to_vec())?;
if data.is_empty() {
return Ok(()); // ignore empty lines
}

info!("{}", data);
window.lock().unwrap().emit("process-output", data)?;
window.lock().map_err(|_| anyhow!("Window lock is poisoned"))?.emit("process-output", data)?;
Ok(())
}

Expand All @@ -209,12 +230,12 @@ fn handle_stderr(window: &Arc<std::sync::Mutex<Window>>, data: &[u8]) -> anyhow:
}

error!("{}", data);
window.lock().unwrap().emit("process-output", data)?;
window.lock().map_err(|_| anyhow!("Window lock is poisoned"))?.emit("process-output", data)?;
Ok(())
}

fn handle_progress(window: &Arc<std::sync::Mutex<Window>>, progress_update: ProgressUpdate) -> anyhow::Result<()> {
window.lock().unwrap().emit("progress-update", progress_update)?;
window.lock().map_err(|_| anyhow!("Window lock is poisoned"))?.emit("progress-update", progress_update)?;
Ok(())
}

Expand Down Expand Up @@ -289,7 +310,7 @@ async fn run_client(build_id: u32, account_data: MinecraftAccount, options: Laun
}

let message = format!("An error occourd:\n\n{:?}", e);
window_mutex.lock().unwrap().emit("client-error", format!("{}\n\nIf this error persists, upload your log with the button below and report it to GitHub.", message)).unwrap();
window_mutex.lock().unwrap().emit("client-error", format!("{}\n\n{}", message, ERROR_MSG)).unwrap();
handle_stderr(&window_mutex, message.as_bytes()).unwrap();
};

Expand Down Expand Up @@ -386,7 +407,7 @@ pub fn gui_main() {
runner_instance: Arc::new(Mutex::new(None))
})
.invoke_handler(tauri::generate_handler![
check_online_status,
check_health,
get_options,
store_options,
request_branches,
Expand Down
Loading

0 comments on commit ec4b43a

Please sign in to comment.