Compare commits
No commits in common. "463e66bd9775b3ec460562c5746e3781aaf71cbf" and "4d2ed01cc05ad9e9646a55ec7ffb423c5aff26de" have entirely different histories.
463e66bd97
...
4d2ed01cc0
59
src-tauri/Cargo.lock
generated
59
src-tauri/Cargo.lock
generated
@ -2,6 +2,24 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "Launcher-tauri"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"log4rs",
|
||||||
|
"rand 0.8.5",
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tauri",
|
||||||
|
"tauri-build",
|
||||||
|
"tokio",
|
||||||
|
"urlencoding",
|
||||||
|
"uuid 1.3.1",
|
||||||
|
"warp",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler"
|
name = "adler"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@ -600,15 +618,6 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "directories"
|
|
||||||
version = "5.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "74be3be809c18e089de43bdc504652bb2bc473fca8756131f8689db8cf079ba9"
|
|
||||||
dependencies = [
|
|
||||||
"dirs-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-next"
|
name = "dirs-next"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -619,17 +628,6 @@ dependencies = [
|
|||||||
"dirs-sys-next",
|
"dirs-sys-next",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dirs-sys"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"redox_users",
|
|
||||||
"windows-sys 0.45.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-sys-next"
|
name = "dirs-sys-next"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@ -857,11 +855,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
|
||||||
"futures-macro",
|
"futures-macro",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"memchr",
|
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"slab",
|
"slab",
|
||||||
@ -1543,25 +1539,6 @@ dependencies = [
|
|||||||
"selectors",
|
"selectors",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "launcher-tauri"
|
|
||||||
version = "0.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"directories",
|
|
||||||
"log4rs",
|
|
||||||
"rand 0.8.5",
|
|
||||||
"reqwest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"tauri",
|
|
||||||
"tauri-build",
|
|
||||||
"tokio",
|
|
||||||
"urlencoding",
|
|
||||||
"uuid 1.3.1",
|
|
||||||
"warp",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "launcher-tauri"
|
name = "Launcher-tauri"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
description = "A Tauri App"
|
description = "A Tauri App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
@ -20,12 +20,11 @@ tauri = {version = "1.2", features = ["api-all"] }
|
|||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
uuid = "1.2.2"
|
uuid = "1.2.2"
|
||||||
log4rs = "1.2.0"
|
log4rs = "1.2.0"
|
||||||
reqwest = { version = "0.11.13", default-features = true, features = ["json", "blocking"] }
|
reqwest = { version = "0.11.13", default-features = true, features = ["json"] }
|
||||||
urlencoding = "2.1.2"
|
urlencoding = "2.1.2"
|
||||||
warp = "0.3.3"
|
warp = "0.3.3"
|
||||||
anyhow = "1.0.66"
|
anyhow = "1.0.66"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
directories = "5.0.0"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
@ -2,7 +2,7 @@ use std::{fmt, net::TcpListener, sync::Arc};
|
|||||||
|
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use reqwest::{header::{CONTENT_TYPE, CONNECTION, ACCEPT, AUTHORIZATION}, Client};
|
use reqwest::{header::{CONTENT_TYPE, CONNECTION, ACCEPT, AUTHORIZATION}, Client};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json, Map};
|
||||||
use tokio::{sync::mpsc, join};
|
use tokio::{sync::mpsc, join};
|
||||||
use urlencoding::encode;
|
use urlencoding::encode;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
use anyhow::{Result, bail};
|
|
||||||
use reqwest::blocking::Client;
|
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
use serde_json::{Value, Map};
|
|
||||||
|
|
||||||
use super::VersionType;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct VersionManifestV2 {
|
|
||||||
latest: Value,
|
|
||||||
versions: Vec<Version>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct Version {
|
|
||||||
id: String,
|
|
||||||
#[serde(rename(serialize = "type", deserialize = "type"))]
|
|
||||||
v_type: VersionType,
|
|
||||||
url: String,
|
|
||||||
sha1: String
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub fn get_version_manifest(reqwest: &Client) -> Result<VersionManifestV2> {
|
|
||||||
let received: VersionManifestV2 = reqwest
|
|
||||||
.get("https://piston-meta.mojang.com/mc/game/version_manifest_v2.json")
|
|
||||||
.send()?
|
|
||||||
.json()?;
|
|
||||||
Ok(received)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_version_from_manifest<'a>(manifest: &'a VersionManifestV2, game_version: String, version_type: &VersionType) -> Result<&'a Version> {
|
|
||||||
for i in manifest.versions.iter().enumerate() {
|
|
||||||
let id = i.1.id.clone();
|
|
||||||
let v_type = i.1.v_type;
|
|
||||||
if id == game_version && &v_type == version_type {
|
|
||||||
return Ok(i.1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bail!("Version not Found")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct VersionDetail {
|
|
||||||
arguments: Map<String, Value>,
|
|
||||||
#[serde(rename(serialize = "assetIndex", deserialize = "assetIndex"))]
|
|
||||||
asset_index: Map<String, Value>,
|
|
||||||
assets: String,
|
|
||||||
downloads: Map<String, Value>,
|
|
||||||
id: String,
|
|
||||||
#[serde(rename(serialize = "javaVersion", deserialize = "javaVersion"))]
|
|
||||||
java_version: Map<String, Value>,
|
|
||||||
pub libraries: Vec<Library>,
|
|
||||||
logging: Map<String, Value>,
|
|
||||||
#[serde(rename(serialize = "mainClass", deserialize = "mainClass"))]
|
|
||||||
main_class: String,
|
|
||||||
#[serde(rename(serialize = "type", deserialize = "type"))]
|
|
||||||
v_type: VersionType
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct Library {
|
|
||||||
pub downloads: LibraryDownload,
|
|
||||||
pub name: String,
|
|
||||||
pub rules: Vec<LibraryRule>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct LibraryDownload {
|
|
||||||
artifact: LibraryArtifact
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct LibraryRule {
|
|
||||||
pub action: String,
|
|
||||||
pub os: LibraryOSRule
|
|
||||||
}
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct LibraryOSRule {
|
|
||||||
pub name: OSName,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq)]
|
|
||||||
pub enum OSName {
|
|
||||||
#[serde(rename(serialize = "osx", deserialize = "osx"))]
|
|
||||||
MacOsX,
|
|
||||||
#[serde(rename(serialize = "linux", deserialize = "linux"))]
|
|
||||||
Linux,
|
|
||||||
#[serde(rename(serialize = "windows", deserialize = "windows"))]
|
|
||||||
Windows
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct LibraryArtifact {
|
|
||||||
path: String,
|
|
||||||
sha1: String,
|
|
||||||
size: i64,
|
|
||||||
url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_version_detail(reqwest: &Client, version : &Version) -> Result<VersionDetail> {
|
|
||||||
let received: VersionDetail = reqwest
|
|
||||||
.get(version.url.clone())
|
|
||||||
.send()?
|
|
||||||
.json()?;
|
|
||||||
Ok(received)
|
|
||||||
}
|
|
@ -1,45 +1,139 @@
|
|||||||
mod manifest;
|
use std::{fmt::Display, path::{self, Path}};
|
||||||
|
|
||||||
use std::{path::Path, fs};
|
use anyhow::{Result, bail};
|
||||||
|
use reqwest::Client;
|
||||||
use anyhow::Result;
|
|
||||||
use reqwest::blocking::Client;
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use serde_json::{Value, Map};
|
||||||
|
use tokio::fs;
|
||||||
|
|
||||||
use crate::authentification::GameProfile;
|
use crate::authentification::GameProfile;
|
||||||
|
|
||||||
use self::manifest::{VersionDetail, get_version_manifest, get_version_from_manifest, get_version_detail, Library, OSName};
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct VersionManifestV2 {
|
||||||
|
latest: Value,
|
||||||
|
versions: Vec<Version>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
struct Version {
|
||||||
|
id: String,
|
||||||
|
#[serde(rename(serialize = "type", deserialize = "type"))]
|
||||||
|
v_type: VersionType,
|
||||||
|
url: String,
|
||||||
|
sha1: String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_os="windows")]
|
async fn get_version_manifest(reqwest: &Client) -> Result<VersionManifestV2> {
|
||||||
const ACTUAL_OS: OSName = OSName::Windows;
|
let received: VersionManifestV2 = reqwest
|
||||||
#[cfg(target_os="linux")]
|
.get("https://piston-meta.mojang.com/mc/game/version_manifest_v2.json")
|
||||||
const ACTUAL_OS: OSName = OSName::Linux;
|
.send()
|
||||||
#[cfg(target_os="macos")]
|
.await?
|
||||||
const ACTUAL_OS: OSName = OSName::MacOsX;
|
.json()
|
||||||
|
.await?;
|
||||||
|
Ok(received)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_version_from_manifest<'a>(manifest: &'a VersionManifestV2, game_version: String, version_type: &VersionType) -> Result<&'a Version> {
|
||||||
|
for i in manifest.versions.iter().enumerate() {
|
||||||
|
let id = i.1.id.clone();
|
||||||
|
let v_type = i.1.v_type;
|
||||||
|
if id == game_version && &v_type == version_type {
|
||||||
|
return Ok(i.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bail!("Version not Found")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct VersionDetail {
|
||||||
|
arguments: Map<String, Value>,
|
||||||
|
#[serde(rename(serialize = "assetIndex", deserialize = "assetIndex"))]
|
||||||
|
asset_index: Map<String, Value>,
|
||||||
|
assets: String,
|
||||||
|
downloads: Map<String, Value>,
|
||||||
|
id: String,
|
||||||
|
#[serde(rename(serialize = "javaVersion", deserialize = "javaVersion"))]
|
||||||
|
java_version: Map<String, Value>,
|
||||||
|
libraries: Vec<Library>,
|
||||||
|
logging: Map<String, Value>,
|
||||||
|
#[serde(rename(serialize = "mainClass", deserialize = "mainClass"))]
|
||||||
|
main_class: String,
|
||||||
|
#[serde(rename(serialize = "type", deserialize = "type"))]
|
||||||
|
v_type: VersionType
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct Library {
|
||||||
|
downloads: LibraryDownload,
|
||||||
|
name: String,
|
||||||
|
rules: Vec<LibraryRule>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct LibraryRule {
|
||||||
|
action: String,
|
||||||
|
os: LibraryOSRule
|
||||||
|
}
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct LibraryOSRule {
|
||||||
|
name: OSName,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
enum OSName {
|
||||||
|
#[serde(rename(serialize = "osx", deserialize = "osx"))]
|
||||||
|
MacOsX,
|
||||||
|
#[serde(rename(serialize = "linux", deserialize = "linux"))]
|
||||||
|
Linux,
|
||||||
|
#[serde(rename(serialize = "windows", deserialize = "windows"))]
|
||||||
|
Windows
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct LibraryDownload {
|
||||||
|
artifact: LibraryArtifact
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
struct LibraryArtifact {
|
||||||
|
path: String,
|
||||||
|
sha1: String,
|
||||||
|
size: i64,
|
||||||
|
url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_version_detail(reqwest: &Client, version : &Version) -> Result<VersionDetail> {
|
||||||
|
let received: VersionDetail = reqwest
|
||||||
|
.get(version.url.clone())
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.json()
|
||||||
|
.await?;
|
||||||
|
Ok(received)
|
||||||
|
}
|
||||||
pub struct ClientOptions<'a> {
|
pub struct ClientOptions<'a> {
|
||||||
pub authorization: &'a GameProfile,
|
authorization: GameProfile,
|
||||||
pub root_path: &'a Path,
|
root_path: &'a Path,
|
||||||
pub java_path: &'a Path,
|
javaPath: String,
|
||||||
pub version_number: String,
|
version_number: String,
|
||||||
pub version_type: VersionType,
|
version_type: VersionType,
|
||||||
// version_custom: String, // for a next update
|
// version_custom: String, // for a next update
|
||||||
pub memory_min: String,
|
memory_min: String,
|
||||||
pub memory_max: String,
|
memory_max: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MinecraftClient<'a> {
|
pub struct MinecraftClient<'a> {
|
||||||
opts: &'a ClientOptions<'a>,
|
opts: ClientOptions<'a>,
|
||||||
details: VersionDetail,
|
details: VersionDetail,
|
||||||
reqwest_client: Client,
|
reqwest_client: Client,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MinecraftClient<'_> {
|
impl<'a> MinecraftClient<'_> {
|
||||||
pub fn new(opts: &'a ClientOptions<'a>) -> Result<MinecraftClient<'a>> {
|
pub async fn new(opts: ClientOptions<'a>) -> Result<MinecraftClient<'a>> {
|
||||||
let reqwest_client = Client::new();
|
let reqwest_client = Client::new();
|
||||||
let details = Self::load_manifest(&reqwest_client, &opts)?;
|
let details = Self::load_manifest(&reqwest_client, &opts).await?;
|
||||||
Ok(MinecraftClient {
|
Ok(MinecraftClient {
|
||||||
opts,
|
opts,
|
||||||
reqwest_client,
|
reqwest_client,
|
||||||
@ -47,41 +141,23 @@ impl<'a> MinecraftClient<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_manifest(reqwest_client: &Client, opts: &ClientOptions<'a>) -> Result<VersionDetail> {
|
async fn load_manifest(reqwest_client: &Client, opts: &ClientOptions<'a>) -> Result<VersionDetail> {
|
||||||
let manifest = get_version_manifest(&reqwest_client)?;
|
let manifest = get_version_manifest(&reqwest_client).await?;
|
||||||
let version = get_version_from_manifest(&manifest, opts.version_number.clone(), &opts.version_type)?;
|
let version = get_version_from_manifest(&manifest, opts.version_number.clone(), &opts.version_type)?;
|
||||||
let details = get_version_detail(&reqwest_client, version)?;
|
let details = get_version_detail(&reqwest_client, version).await?;
|
||||||
Ok(details)
|
Ok(details)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn download_assets(&mut self) -> Result<()> {
|
pub async fn download_assets(&self) -> Result<()> {
|
||||||
// create root folder if it doesn't exist
|
// create root folder if it doesn't exist
|
||||||
fs::create_dir_all(self.opts.root_path)?;
|
fs::create_dir_all(self.opts.root_path).await?;
|
||||||
fs::create_dir(self.opts.root_path.join("librairies"))?;
|
fs::create_dir(self.opts.root_path.join("librairies")).await?;
|
||||||
self.filter_non_necessary_librairies();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
/// Filter non necessary librairies for the current OS
|
/// Filter non necessary librairies for the current OS
|
||||||
fn filter_non_necessary_librairies(&mut self) {
|
fn filter_non_necessary_librairies(&self) -> Result<()> {
|
||||||
self.details.libraries.retain(|e| { Self::should_use_library(e) });
|
bail!("Not implemented yet")
|
||||||
}
|
|
||||||
|
|
||||||
fn should_use_library(library: &Library) -> bool {
|
|
||||||
if library.rules.is_empty() {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
for i in library.rules.iter().enumerate() {
|
|
||||||
let op = if i.1.action == "allow" {
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
if i.1.os.name == ACTUAL_OS {
|
|
||||||
return op;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -99,3 +175,31 @@ pub enum VersionType {
|
|||||||
#[serde(alias = "old_beta")]
|
#[serde(alias = "old_beta")]
|
||||||
OldBeta,
|
OldBeta,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> TryInto<&'a VersionType> for &str {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_into(self) -> std::result::Result<&'a VersionType, Self::Error> {
|
||||||
|
match self {
|
||||||
|
"release" => Ok(&VersionType::Release),
|
||||||
|
"snapshot" => Ok(&VersionType::Snapshot),
|
||||||
|
"old_alpha" => Ok(&VersionType::OldAlpha),
|
||||||
|
"old_beta" => Ok(&VersionType::OldBeta),
|
||||||
|
_ => Err(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for VersionType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let str = match self {
|
||||||
|
Self::Release => "release",
|
||||||
|
Self::Snapshot => "snapshot",
|
||||||
|
Self::OldAlpha => "old_alpha",
|
||||||
|
Self::OldBeta => "old_beta",
|
||||||
|
};
|
||||||
|
write!(f, "{}", str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,14 +6,8 @@
|
|||||||
pub mod authentification;
|
pub mod authentification;
|
||||||
pub mod launcher;
|
pub mod launcher;
|
||||||
|
|
||||||
use std::sync::Mutex;
|
use authentification::{Authentification, Prompt};
|
||||||
|
|
||||||
use authentification::{Authentification, Prompt, GameProfile};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use directories::BaseDirs;
|
|
||||||
use launcher::{MinecraftClient, ClientOptions};
|
|
||||||
|
|
||||||
struct CustomState (Option<GameProfile>);
|
|
||||||
|
|
||||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@ -22,83 +16,18 @@ fn greet(name: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn login(app: tauri::AppHandle, _window: tauri::Window, state: tauri::State<'_, Mutex<CustomState>>) -> Result<String, String> {
|
async fn login(app: tauri::AppHandle, _window: tauri::Window) -> Result<String, String> {
|
||||||
let result = Authentification::login(Prompt::SelectAccount, app).await;
|
let result = Authentification::login(Prompt::SelectAccount, app).await;
|
||||||
match result {
|
match result {
|
||||||
Ok(val) => {
|
Ok(val) => Ok(format!("Hello {}", val.name)),
|
||||||
let name = val.name.clone();
|
|
||||||
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())
|
Err(err) => Err(err.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
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) => {
|
|
||||||
match &game_profile.0 {
|
|
||||||
Some(game_profile) => {
|
|
||||||
let java_path = root_path.join("java");
|
|
||||||
let opts = ClientOptions {
|
|
||||||
authorization: game_profile,
|
|
||||||
root_path,
|
|
||||||
java_path: &java_path.as_path(),
|
|
||||||
version_number: "1.19.4".to_string(),
|
|
||||||
version_type: launcher::VersionType::Release,
|
|
||||||
memory_min: "2G".to_string(),
|
|
||||||
memory_max: "4G".to_string(),
|
|
||||||
};
|
|
||||||
let client = MinecraftClient::new(&opts);
|
|
||||||
match client {
|
|
||||||
Ok(mut client) => {
|
|
||||||
match client.download_assets() {
|
|
||||||
Ok(_) => {
|
|
||||||
Ok("Content downloaded".to_string())
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
Err(err.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
Err(err.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
Err("You're not connected".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
Err(err.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Err("Cannot download files".to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.manage(Mutex::new(CustomState(None)))
|
.invoke_handler(tauri::generate_handler![greet, login])
|
||||||
.invoke_handler(tauri::generate_handler![greet, login, download])
|
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
@ -2,36 +2,19 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
button_message: "Login to minecraft",
|
button_message: "Login to minecraft",
|
||||||
greet_message: "",
|
greet_message: ""
|
||||||
greetDisabled: 0,
|
|
||||||
hideDownloadButton: true,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
login (e) {
|
login (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if(!this.greetDisabled) {
|
|
||||||
this.greetDisabled = true
|
|
||||||
this.invoke("login", {}).then(value => {
|
this.invoke("login", {}).then(value => {
|
||||||
this.greet_message = value
|
this.greet_message = value
|
||||||
this.hideDownloadButton = false
|
|
||||||
}).catch(err => {
|
|
||||||
this.greet_message = "Error: " + err
|
|
||||||
this.greetDisabled = false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
download (e) {
|
|
||||||
e.preventDefault()
|
|
||||||
if(!this.hideDownloadButton) {
|
|
||||||
this.invoke("download", {}).then(value => {
|
|
||||||
this.greet_message = value
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.greet_message = "Error: " + err
|
this.greet_message = "Error: " + err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
props: {
|
props: {
|
||||||
invoke: Object
|
invoke: Object
|
||||||
},
|
},
|
||||||
@ -40,8 +23,7 @@ export default {
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div>
|
<div>
|
||||||
<button id="greet-button" :disabled="greetDisabled == 1" type="button" v-on:click="login">{{ button_message }}</button>
|
<button id="greet-button" type="button" v-on:click="login">{{ button_message }}</button>
|
||||||
<button id="download-button" :class="{hide: hideDownloadButton }" v-on:click="download">Download game</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -84,10 +84,6 @@ button {
|
|||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hide {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
:root {
|
:root {
|
||||||
color: #f6f6f6;
|
color: #f6f6f6;
|
||||||
|
Reference in New Issue
Block a user