start work on interpulse

This commit is contained in:
Pauline 2024-03-27 11:03:21 +01:00
parent 022936d35c
commit ec8c20dc29
No known key found for this signature in database
GPG key ID: 722BB181973296AE
8 changed files with 126 additions and 5 deletions

View file

@ -22,6 +22,8 @@ tauri-plugin-stronghold = { git = "https://github.com/tauri-apps/plugins-workspa
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
interpulse = { version = "0.1" }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = [
"chrono",
@ -59,6 +61,9 @@ tokio-stream = { version = "0.1", features = [ "fs" ] }
async-recursion = { version = "1.1" }
notify = { version = "6.1", default-features = false, features = [ "serde" ] }
notify-debouncer-mini = { version = "0.4", default-features = false }
regex = { version = "1.10" }
sysinfo = { version = "0.30" }
sys-info = { version = "0.9" }
[profile.dev]
# Make compilation faster on macOS

View file

@ -18,6 +18,8 @@ cli = [ "dep:indicatif" ]
tauri = { workspace = true, optional = true }
indicatif = { workspace = true, optional = true }
interpulse = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-error = { workspace = true }
@ -41,6 +43,9 @@ sha1 = { workspace = true }
discord-rich-presence = { workspace = true }
notify = { workspace = true }
notify-debouncer-mini = { workspace = true }
regex = { workspace = true }
sysinfo = { workspace = true }
sys-info = { workspace = true }
[target.'cfg(windows)'.dependencies]
winreg = { workspace = true }

View file

@ -31,6 +31,10 @@ pub enum ErrorKind {
#[error("failed to parse uuids: {0}")]
UUIDError(#[from] uuid::Error),
/// Wrapper around [`interpulse::Error`] to handle interpulse errors.
#[error("metadata error: {0}")]
MetadataError(#[from] interpulse::Error),
/// Wrapper around [`serde_json::Error`] to handle Serde JSON parsing errors.
#[error("failed to manage serialization of json: {0}")]
SerdeError(#[from] serde_json::Error),

View file

@ -1,4 +1,7 @@
use serde::{Deserialize, Serialize};
use core::fmt;
use std::{collections::HashMap, marker::PhantomData};
use serde::{de::{self, SeqAccess, Visitor}, Deserialize, Deserializer, Serialize};
use serde_json::Value;
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -6,16 +9,17 @@ use serde_json::Value;
pub struct MinecraftManifest {
pub asset_index: AssetIndex,
pub downloads: Downloads,
#[serde(rename = "id")]
pub version: String,
pub java_version: JavaVersion,
pub libraries: Vec<Library>,
pub logging: Logging,
pub main_class: String,
pub arguments: Arguments,
pub release_time: String,
#[serde(rename = "id")]
pub version: String,
#[serde(rename = "type")]
pub release_type: ReleaseType,
#[serde(skip_serializing_if = "Option::is_none")]
pub minecraft_arguments
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

View file

@ -1,4 +1,4 @@
#![warn(unused_import_braces)]
#![warn(unused_import_braces, missing_debug_implementations)]
#![deny(unused_must_use)]
pub mod auth;

View file

@ -1,3 +1,4 @@
pub mod dirs;
pub mod file;
pub mod http;
pub mod platform;

View file

@ -0,0 +1,100 @@
use interpulse::api::minecraft::{Os, OsRule};
use regex::Regex;
pub trait OsExt {
/// Get the OS of the current system
fn native() -> Self;
/// Gets the OS + Arch of the current system
fn native_arch(java_arch: &str) -> Self;
}
impl OsExt for Os {
fn native_arch(java_arch: &str) -> Self {
if std::env::consts::OS == "windows" {
if java_arch == "aarch64" {
Os::WindowsArm64
} else {
Os::Windows
}
} else if std::env::consts::OS == "linux" {
if java_arch == "aarch64" {
Os::LinuxArm64
} else if java_arch == "arm" {
Os::LinuxArm32
} else {
Os::Linux
}
} else if std::env::consts::OS == "macos" {
if java_arch == "aarch64" {
Os::OsxArm64
} else {
Os::Osx
}
} else {
Os::Unknown
}
}
fn native() -> Self {
match std::env::consts::OS {
"windows" => Self::Windows,
"macos" => Self::Osx,
"linux" => Self::Linux,
_ => Self::Unknown,
}
}
}
// Bit width
#[cfg(target_pointer_width = "64")]
pub const ARCH_WIDTH: &str = "64";
#[cfg(target_pointer_width = "32")]
pub const ARCH_WIDTH: &str = "32";
// Platform rule handling
pub fn os_rule(
rule: &OsRule,
java_arch: &str,
// Minecraft updated over 1.18.2 (supports MacOS Natively)
minecraft_updated: bool,
) -> bool {
let mut rule_match = true;
if let Some(ref arch) = rule.arch {
rule_match &= !matches!(arch.as_str(), "x86" | "arm");
}
if let Some(name) = &rule.name {
if minecraft_updated
&& (name != &Os::LinuxArm64 || name != &Os::LinuxArm32)
{
rule_match &=
&Os::native() == name || &Os::native_arch(java_arch) == name;
} else {
rule_match &= &Os::native_arch(java_arch) == name;
}
}
if let Some(version) = &rule.version {
if let Ok(regex) = Regex::new(version.as_str()) {
rule_match &=
regex.is_match(&sys_info::os_release().unwrap_or_default());
}
}
rule_match
}
pub fn classpath_separator(java_arch: &str) -> &'static str {
match Os::native_arch(java_arch) {
Os::Osx
| Os::OsxArm64
| Os::Linux
| Os::LinuxArm32
| Os::LinuxArm64
| Os::Unknown => ":",
Os::Windows | Os::WindowsArm64 => ";",
}
}

View file

@ -16,6 +16,8 @@ tauri-build = { workspace = true }
[dependencies]
onelauncher = { path = "../onelauncher", features = [ "tauri" ] }
interpulse = { workspace = true, features = [ "bincode" ] }
tauri = { workspace = true }
tauri-plugin-shell = { workspace = true }
tauri-plugin-window-state = { workspace = true }