Compare commits
3 Commits
4d2ed01cc0
...
463e66bd97
Author | SHA1 | Date | |
---|---|---|---|
463e66bd97 | |||
e8c92cf7f0 | |||
6cdf71b5b6 |
59
src-tauri/Cargo.lock
generated
59
src-tauri/Cargo.lock
generated
@ -2,24 +2,6 @@
|
|||||||
# 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"
|
||||||
@ -618,6 +600,15 @@ 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"
|
||||||
@ -628,6 +619,17 @@ 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"
|
||||||
@ -855,9 +857,11 @@ 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",
|
||||||
@ -1539,6 +1543,25 @@ 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,16 +20,17 @@ 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"] }
|
reqwest = { version = "0.11.13", default-features = true, features = ["json", "blocking"] }
|
||||||
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
|
||||||
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
|
||||||
default = [ "custom-protocol" ]
|
default = ["custom-protocol"]
|
||||||
# this feature is used used for production builds where `devPath` points to the filesystem
|
# this feature is used used for production builds where `devPath` points to the filesystem
|
||||||
# DO NOT remove this
|
# DO NOT remove this
|
||||||
custom-protocol = [ "tauri/custom-protocol" ]
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
|
@ -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, Map};
|
use serde_json::{Value, json};
|
||||||
use tokio::{sync::mpsc, join};
|
use tokio::{sync::mpsc, join};
|
||||||
use urlencoding::encode;
|
use urlencoding::encode;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
107
src-tauri/src/launcher/manifest.rs
Normal file
107
src-tauri/src/launcher/manifest.rs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
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,139 +1,45 @@
|
|||||||
use std::{fmt::Display, path::{self, Path}};
|
mod manifest;
|
||||||
|
|
||||||
use anyhow::{Result, bail};
|
use std::{path::Path, fs};
|
||||||
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;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
use self::manifest::{VersionDetail, get_version_manifest, get_version_from_manifest, get_version_detail, Library, OSName};
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fn get_version_manifest(reqwest: &Client) -> Result<VersionManifestV2> {
|
#[cfg(target_os="windows")]
|
||||||
let received: VersionManifestV2 = reqwest
|
const ACTUAL_OS: OSName = OSName::Windows;
|
||||||
.get("https://piston-meta.mojang.com/mc/game/version_manifest_v2.json")
|
#[cfg(target_os="linux")]
|
||||||
.send()
|
const ACTUAL_OS: OSName = OSName::Linux;
|
||||||
.await?
|
#[cfg(target_os="macos")]
|
||||||
.json()
|
const ACTUAL_OS: OSName = OSName::MacOsX;
|
||||||
.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> {
|
||||||
authorization: GameProfile,
|
pub authorization: &'a GameProfile,
|
||||||
root_path: &'a Path,
|
pub root_path: &'a Path,
|
||||||
javaPath: String,
|
pub java_path: &'a Path,
|
||||||
version_number: String,
|
pub version_number: String,
|
||||||
version_type: VersionType,
|
pub version_type: VersionType,
|
||||||
// version_custom: String, // for a next update
|
// version_custom: String, // for a next update
|
||||||
memory_min: String,
|
pub memory_min: String,
|
||||||
memory_max: String,
|
pub memory_max: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MinecraftClient<'a> {
|
pub struct MinecraftClient<'a> {
|
||||||
opts: ClientOptions<'a>,
|
opts: &'a ClientOptions<'a>,
|
||||||
details: VersionDetail,
|
details: VersionDetail,
|
||||||
reqwest_client: Client,
|
reqwest_client: Client,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MinecraftClient<'_> {
|
impl<'a> MinecraftClient<'_> {
|
||||||
pub async fn new(opts: ClientOptions<'a>) -> Result<MinecraftClient<'a>> {
|
pub fn new(opts: &'a ClientOptions<'a>) -> Result<MinecraftClient<'a>> {
|
||||||
let reqwest_client = Client::new();
|
let reqwest_client = Client::new();
|
||||||
let details = Self::load_manifest(&reqwest_client, &opts).await?;
|
let details = Self::load_manifest(&reqwest_client, &opts)?;
|
||||||
Ok(MinecraftClient {
|
Ok(MinecraftClient {
|
||||||
opts,
|
opts,
|
||||||
reqwest_client,
|
reqwest_client,
|
||||||
@ -141,23 +47,41 @@ impl<'a> MinecraftClient<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_manifest(reqwest_client: &Client, opts: &ClientOptions<'a>) -> Result<VersionDetail> {
|
fn load_manifest(reqwest_client: &Client, opts: &ClientOptions<'a>) -> Result<VersionDetail> {
|
||||||
let manifest = get_version_manifest(&reqwest_client).await?;
|
let manifest = get_version_manifest(&reqwest_client)?;
|
||||||
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).await?;
|
let details = get_version_detail(&reqwest_client, version)?;
|
||||||
Ok(details)
|
Ok(details)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn download_assets(&self) -> Result<()> {
|
pub fn download_assets(&mut 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).await?;
|
fs::create_dir_all(self.opts.root_path)?;
|
||||||
fs::create_dir(self.opts.root_path.join("librairies")).await?;
|
fs::create_dir(self.opts.root_path.join("librairies"))?;
|
||||||
|
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(&self) -> Result<()> {
|
fn filter_non_necessary_librairies(&mut self) {
|
||||||
bail!("Not implemented yet")
|
self.details.libraries.retain(|e| { Self::should_use_library(e) });
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -175,31 +99,3 @@ 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,8 +6,14 @@
|
|||||||
pub mod authentification;
|
pub mod authentification;
|
||||||
pub mod launcher;
|
pub mod launcher;
|
||||||
|
|
||||||
use authentification::{Authentification, Prompt};
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
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]
|
||||||
@ -16,18 +22,83 @@ fn greet(name: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn login(app: tauri::AppHandle, _window: tauri::Window) -> Result<String, String> {
|
async fn login(app: tauri::AppHandle, _window: tauri::Window, state: tauri::State<'_, Mutex<CustomState>>) -> 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(format!("Hello {}", val.name)),
|
Ok(val) => {
|
||||||
|
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()
|
||||||
.invoke_handler(tauri::generate_handler![greet, login])
|
.manage(Mutex::new(CustomState(None)))
|
||||||
|
.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,18 +2,35 @@ 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()
|
||||||
this.invoke("login", {}).then(value => {
|
if(!this.greetDisabled) {
|
||||||
this.greet_message = value
|
this.greetDisabled = true
|
||||||
}).catch(err => {
|
this.invoke("login", {}).then(value => {
|
||||||
this.greet_message = "Error: " + err
|
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 => {
|
||||||
|
this.greet_message = "Error: " + err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
invoke: Object
|
invoke: Object
|
||||||
@ -23,7 +40,8 @@ export default {
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div>
|
<div>
|
||||||
<button id="greet-button" type="button" v-on:click="login">{{ button_message }}</button>
|
<button id="greet-button" :disabled="greetDisabled == 1" 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,6 +84,10 @@ 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