aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2026-01-14 16:44:56 +0800
committerHsiangNianian <i@jyunko.cn>2026-01-14 16:44:56 +0800
commit9193112aca842dbe4d723aa865a7a30f3bcdb691 (patch)
tree226a595587569c4a4ddb42729163060f4e04dc18 /src-tauri
parentbdbed80e0ee632a6495244b0a56f74ed6f9d639e (diff)
downloadDropOut-9193112aca842dbe4d723aa865a7a30f3bcdb691.tar.gz
DropOut-9193112aca842dbe4d723aa865a7a30f3bcdb691.zip
refactor: clean up formatting and improve readability in core modules
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/src/core/fabric.rs11
-rw-r--r--src-tauri/src/core/forge.rs13
-rw-r--r--src-tauri/src/core/manifest.rs6
-rw-r--r--src-tauri/src/core/maven.rs15
-rw-r--r--src-tauri/src/main.rs35
5 files changed, 47 insertions, 33 deletions
diff --git a/src-tauri/src/core/fabric.rs b/src-tauri/src/core/fabric.rs
index 8fc960f..fd38f41 100644
--- a/src-tauri/src/core/fabric.rs
+++ b/src-tauri/src/core/fabric.rs
@@ -89,7 +89,8 @@ pub struct InstalledFabricVersion {
///
/// # Returns
/// A list of game versions that have Fabric intermediary mappings available.
-pub async fn fetch_supported_game_versions() -> Result<Vec<FabricGameVersion>, Box<dyn Error + Send + Sync>> {
+pub async fn fetch_supported_game_versions(
+) -> Result<Vec<FabricGameVersion>, Box<dyn Error + Send + Sync>> {
let url = format!("{}/versions/game", FABRIC_META_URL);
let resp = reqwest::get(&url)
.await?
@@ -102,7 +103,8 @@ pub async fn fetch_supported_game_versions() -> Result<Vec<FabricGameVersion>, B
///
/// # Returns
/// A list of all Fabric loader versions, ordered by build number (newest first).
-pub async fn fetch_loader_versions() -> Result<Vec<FabricLoaderVersion>, Box<dyn Error + Send + Sync>> {
+pub async fn fetch_loader_versions(
+) -> Result<Vec<FabricLoaderVersion>, Box<dyn Error + Send + Sync>> {
let url = format!("{}/versions/loader", FABRIC_META_URL);
let resp = reqwest::get(&url)
.await?
@@ -145,7 +147,10 @@ pub async fn fetch_version_profile(
"{}/versions/loader/{}/{}/profile/json",
FABRIC_META_URL, game_version, loader_version
);
- let resp = reqwest::get(&url).await?.json::<serde_json::Value>().await?;
+ let resp = reqwest::get(&url)
+ .await?
+ .json::<serde_json::Value>()
+ .await?;
Ok(resp)
}
diff --git a/src-tauri/src/core/forge.rs b/src-tauri/src/core/forge.rs
index 7b951ff..0f17bcc 100644
--- a/src-tauri/src/core/forge.rs
+++ b/src-tauri/src/core/forge.rs
@@ -48,7 +48,7 @@ pub struct InstalledForgeVersion {
/// A list of Minecraft version strings that have Forge available.
pub async fn fetch_supported_game_versions() -> Result<Vec<String>, Box<dyn Error + Send + Sync>> {
let promos = fetch_promotions().await?;
-
+
let mut versions: Vec<String> = promos
.promos
.keys()
@@ -62,12 +62,12 @@ pub async fn fetch_supported_game_versions() -> Result<Vec<String>, Box<dyn Erro
}
})
.collect();
-
+
// Deduplicate and sort
versions.sort();
versions.dedup();
versions.reverse(); // Newest first
-
+
Ok(versions)
}
@@ -159,7 +159,7 @@ pub async fn install_forge(
forge_version: &str,
) -> Result<InstalledForgeVersion, Box<dyn Error + Send + Sync>> {
let version_id = generate_version_id(game_version, forge_version);
-
+
// Create basic version JSON structure
// Note: This is a simplified version. Full Forge installation requires
// downloading the installer and running processors.
@@ -206,7 +206,10 @@ fn create_forge_version_json(
vec![
create_library_entry(&forge_maven_coord, Some(FORGE_MAVEN_URL)),
create_library_entry(
- &format!("net.minecraftforge:forge:{}-{}:universal", game_version, forge_version),
+ &format!(
+ "net.minecraftforge:forge:{}-{}:universal",
+ game_version, forge_version
+ ),
Some(FORGE_MAVEN_URL),
),
],
diff --git a/src-tauri/src/core/manifest.rs b/src-tauri/src/core/manifest.rs
index 2fea811..bae87c9 100644
--- a/src-tauri/src/core/manifest.rs
+++ b/src-tauri/src/core/manifest.rs
@@ -74,7 +74,7 @@ pub async fn fetch_vanilla_version(
) -> Result<GameVersion, Box<dyn Error + Send + Sync>> {
// First, get the manifest to find the version URL
let manifest = fetch_version_manifest().await?;
-
+
let version_entry = manifest
.versions
.iter()
@@ -86,7 +86,7 @@ pub async fn fetch_vanilla_version(
.await?
.json::<GameVersion>()
.await?;
-
+
Ok(resp)
}
@@ -121,7 +121,7 @@ pub async fn load_version(
Ok(v) => v,
Err(_) => fetch_vanilla_version(&parent_id).await?,
};
-
+
// Merge child into parent
version = crate::core::version_merge::merge_versions(version, parent);
}
diff --git a/src-tauri/src/core/maven.rs b/src-tauri/src/core/maven.rs
index a930e05..8c89768 100644
--- a/src-tauri/src/core/maven.rs
+++ b/src-tauri/src/core/maven.rs
@@ -101,7 +101,10 @@ impl MavenCoordinate {
}
};
- format!("{}/{}/{}/{}", group_path, self.artifact, self.version, filename)
+ format!(
+ "{}/{}/{}/{}",
+ group_path, self.artifact, self.version, filename
+ )
}
/// Get the local file path for storing this artifact.
@@ -142,7 +145,11 @@ impl MavenCoordinate {
///
/// # Returns
/// The resolved download URL
-pub fn resolve_library_url(name: &str, explicit_url: Option<&str>, maven_url: Option<&str>) -> Option<String> {
+pub fn resolve_library_url(
+ name: &str,
+ explicit_url: Option<&str>,
+ maven_url: Option<&str>,
+) -> Option<String> {
// If there's an explicit URL, use it
if let Some(url) = explicit_url {
return Some(url.to_string());
@@ -156,7 +163,9 @@ pub fn resolve_library_url(name: &str, explicit_url: Option<&str>, maven_url: Op
// Guess the repository based on group
if coord.group.starts_with("net.fabricmc") {
FABRIC_MAVEN
- } else if coord.group.starts_with("net.minecraftforge") || coord.group.starts_with("cpw.mods") {
+ } else if coord.group.starts_with("net.minecraftforge")
+ || coord.group.starts_with("cpw.mods")
+ {
FORGE_MAVEN
} else {
MOJANG_LIBRARIES
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 2261273..ba16f7a 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -41,7 +41,7 @@ impl MsRefreshTokenState {
}
/// Check if a string contains unresolved placeholders in the form ${...}
-///
+///
/// After the replacement phase, if a string still contains ${...}, it means
/// that placeholder variable was not found in the replacements map and is
/// therefore unresolved. We should skip adding such arguments to avoid
@@ -119,11 +119,11 @@ async fn start_game(
window,
format!("Loading version details for {}...", version_id)
);
-
+
let version_details = core::manifest::load_version(&game_dir, &version_id)
.await
.map_err(|e| e.to_string())?;
-
+
emit_log!(
window,
format!(
@@ -145,7 +145,9 @@ async fn start_game(
// --- Client Jar ---
// Get downloads from version_details (may be inherited)
- let downloads = version_details.downloads.as_ref()
+ let downloads = version_details
+ .downloads
+ .as_ref()
.ok_or("Version has no downloads information")?;
let client_jar = &downloads.client;
let mut client_path = game_dir.join("versions");
@@ -222,12 +224,11 @@ async fn start_game(
} else {
// 3. Library without explicit downloads (mod loader libraries)
// Use Maven coordinate resolution
- if let Some(url) = core::maven::resolve_library_url(
- &lib.name,
- None,
- lib.url.as_deref(),
- ) {
- if let Some(lib_path) = core::maven::get_library_path(&lib.name, &libraries_dir) {
+ if let Some(url) =
+ core::maven::resolve_library_url(&lib.name, None, lib.url.as_deref())
+ {
+ if let Some(lib_path) = core::maven::get_library_path(&lib.name, &libraries_dir)
+ {
download_tasks.push(core::downloader::DownloadTask {
url,
path: lib_path,
@@ -246,7 +247,9 @@ async fn start_game(
let indexes_dir = assets_dir.join("indexes");
// Get asset index (may be inherited from parent)
- let asset_index = version_details.asset_index.as_ref()
+ let asset_index = version_details
+ .asset_index
+ .as_ref()
.ok_or("Version has no asset index information")?;
// Download Asset Index JSON
@@ -262,10 +265,7 @@ async fn start_game(
.await
.map_err(|e| e.to_string())?
} else {
- println!(
- "Downloading asset index from {}",
- asset_index.url
- );
+ println!("Downloading asset index from {}", asset_index.url);
let content = reqwest::get(&asset_index.url)
.await
.map_err(|e| e.to_string())?
@@ -426,10 +426,7 @@ async fn start_game(
replacements.insert("${version_name}", version_id.clone());
replacements.insert("${game_directory}", game_dir.to_string_lossy().to_string());
replacements.insert("${assets_root}", assets_dir.to_string_lossy().to_string());
- replacements.insert(
- "${assets_index_name}",
- asset_index.id.clone(),
- );
+ replacements.insert("${assets_index_name}", asset_index.id.clone());
replacements.insert("${auth_uuid}", account.uuid());
replacements.insert("${auth_access_token}", account.access_token());
replacements.insert("${user_type}", "mojang".to_string());