aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/core
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2026-01-18 13:34:52 +0800
committerHsiangNianian <i@jyunko.cn>2026-01-18 13:34:52 +0800
commit02520ca62ac5e508e8748b2445171be64f459b6c (patch)
treea15a95be5f2f93385df36d6336f53b3f08d07a44 /src-tauri/src/core
parent53df697ccf90cd13efc985c195dade48920cc0fa (diff)
downloadDropOut-02520ca62ac5e508e8748b2445171be64f459b6c.tar.gz
DropOut-02520ca62ac5e508e8748b2445171be64f459b6c.zip
fix(ci): improve pre-commit fmt hook configuration
- Add pass_filenames: false to fmt hook - Add -- separator for cargo fmt args - Manually format code with cargo fmt
Diffstat (limited to 'src-tauri/src/core')
-rw-r--r--src-tauri/src/core/config.rs36
-rw-r--r--src-tauri/src/core/java.rs15
-rw-r--r--src-tauri/src/core/rules.rs71
3 files changed, 99 insertions, 23 deletions
diff --git a/src-tauri/src/core/config.rs b/src-tauri/src/core/config.rs
index 4c4acad..e4b9381 100644
--- a/src-tauri/src/core/config.rs
+++ b/src-tauri/src/core/config.rs
@@ -42,6 +42,34 @@ impl Default for AssistantConfig {
}
}
+/// Feature-gated arguments configuration
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(default)]
+pub struct FeatureFlags {
+ /// Demo user: enables demo-related arguments when rules require it
+ pub demo_user: bool,
+ /// Quick Play: enable quick play arguments
+ pub quick_play_enabled: bool,
+ /// Quick Play singleplayer world path (if provided)
+ pub quick_play_path: Option<String>,
+ /// Quick Play singleplayer flag
+ pub quick_play_singleplayer: bool,
+ /// Quick Play multiplayer server address (optional)
+ pub quick_play_multiplayer_server: Option<String>,
+}
+
+impl Default for FeatureFlags {
+ fn default() -> Self {
+ Self {
+ demo_user: false,
+ quick_play_enabled: false,
+ quick_play_path: None,
+ quick_play_singleplayer: true,
+ quick_play_multiplayer_server: None,
+ }
+ }
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct LauncherConfig {
@@ -59,6 +87,11 @@ pub struct LauncherConfig {
pub log_upload_service: String, // "paste.rs" or "pastebin.com"
pub pastebin_api_key: Option<String>,
pub assistant: AssistantConfig,
+ // Storage management
+ pub use_shared_caches: bool, // Use global shared versions/libraries/assets
+ pub keep_legacy_per_instance_storage: bool, // Keep old per-instance caches (no migration)
+ // Feature-gated argument flags
+ pub feature_flags: FeatureFlags,
}
impl Default for LauncherConfig {
@@ -78,6 +111,9 @@ impl Default for LauncherConfig {
log_upload_service: "paste.rs".to_string(),
pastebin_api_key: None,
assistant: AssistantConfig::default(),
+ use_shared_caches: false,
+ keep_legacy_per_instance_storage: true,
+ feature_flags: FeatureFlags::default(),
}
}
}
diff --git a/src-tauri/src/core/java.rs b/src-tauri/src/core/java.rs
index d3e1bb9..2e3c8a7 100644
--- a/src-tauri/src/core/java.rs
+++ b/src-tauri/src/core/java.rs
@@ -855,22 +855,19 @@ fn parse_java_version(version: &str) -> u32 {
// - New format: 17.0.1, 11.0.5+10 (Java 11+)
// - Format with build: 21.0.3+13-Ubuntu-0ubuntu0.24.04.1
// - Format with underscores: 1.8.0_411
-
+
// First, strip build metadata (everything after '+')
let version_only = version.split('+').next().unwrap_or(version);
-
+
// Remove trailing junk (like "-Ubuntu-0ubuntu0.24.04.1")
- let version_only = version_only
- .split('-')
- .next()
- .unwrap_or(version_only);
-
+ let version_only = version_only.split('-').next().unwrap_or(version_only);
+
// Replace underscores with dots (1.8.0_411 -> 1.8.0.411)
let normalized = version_only.replace('_', ".");
-
+
// Split by dots
let parts: Vec<&str> = normalized.split('.').collect();
-
+
if let Some(first) = parts.first() {
if *first == "1" {
// Old format: 1.8.0 -> major is 8
diff --git a/src-tauri/src/core/rules.rs b/src-tauri/src/core/rules.rs
index 10a40b6..781515a 100644
--- a/src-tauri/src/core/rules.rs
+++ b/src-tauri/src/core/rules.rs
@@ -1,7 +1,8 @@
+use crate::core::config::FeatureFlags;
use crate::core::game_version::Rule;
use std::env;
-pub fn is_library_allowed(rules: &Option<Vec<Rule>>) -> bool {
+pub fn is_library_allowed(rules: &Option<Vec<Rule>>, features: Option<&FeatureFlags>) -> bool {
// If no rules, it's allowed by default
let Some(rules) = rules else {
return true;
@@ -39,19 +40,54 @@ pub fn is_library_allowed(rules: &Option<Vec<Rule>>) -> bool {
let mut allowed = false;
for rule in rules {
- if rule_matches(rule) {
+ if rule_matches(rule, features) {
allowed = rule.action == "allow";
}
}
allowed
}
-fn rule_matches(rule: &Rule) -> bool {
- // Feature-based rules (e.g., is_demo_user, has_quick_plays_support, is_quick_play_singleplayer)
- // are not implemented in this launcher, so we return false for any rule that has features.
- // This prevents adding arguments like --demo, --quickPlayPath, --quickPlaySingleplayer, etc.
- if rule.features.is_some() {
- return false;
+fn rule_matches(rule: &Rule, features: Option<&FeatureFlags>) -> bool {
+ // Feature-based rules: apply only if all listed features evaluate to true
+ if let Some(f) = &rule.features {
+ if let Some(map) = f.as_object() {
+ // If no feature flags provided, we cannot satisfy feature rules
+ let ctx = match features {
+ Some(ff) => ff,
+ None => return false,
+ };
+
+ for (key, val) in map.iter() {
+ let required = val.as_bool().unwrap_or(false);
+ // Map known features
+ let actual = match key.as_str() {
+ "is_demo_user" => ctx.demo_user,
+ "has_quick_plays_support" => ctx.quick_play_enabled,
+ "is_quick_play_singleplayer" => {
+ ctx.quick_play_enabled && ctx.quick_play_singleplayer
+ }
+ "is_quick_play_multiplayer" => {
+ ctx.quick_play_enabled
+ && ctx
+ .quick_play_multiplayer_server
+ .as_ref()
+ .map(|s| !s.is_empty())
+ .unwrap_or(false)
+ }
+ _ => false,
+ };
+ if required && !actual {
+ return false;
+ }
+ if !required && actual {
+ // If rule specifies feature must be false, but it's true, do not match
+ return false;
+ }
+ }
+ } else {
+ // Malformed features object
+ return false;
+ }
}
match &rule.os {
@@ -65,28 +101,35 @@ fn rule_matches(rule: &Rule) -> bool {
"windows" => env::consts::OS == "windows",
_ => false, // Unknown OS name in rule
};
-
+
if !os_match {
return false;
}
}
-
+
// Check architecture if specified
if let Some(arch) = &os_rule.arch {
let current_arch = env::consts::ARCH;
- if arch != current_arch && arch != "x86_64" {
- // "x86" is sometimes used for x86_64, but we only match exact arch
+ // Strict match: only exact architecture or known compatibility mapping
+ let compatible = match (arch.as_str(), current_arch) {
+ ("x86_64", "x86_64") => true,
+ ("x86", "x86") => true,
+ ("aarch64", "aarch64") => true,
+ // Treat "x86" not as matching x86_64 (be strict)
+ _ => arch == current_arch,
+ };
+ if !compatible {
return false;
}
}
-
+
// Check version if specified (for OS version compatibility)
if let Some(_version) = &os_rule.version {
// Version checking would require parsing OS version strings
// For now, we accept all versions (conservative approach)
// In the future, parse version and compare
}
-
+
true
}
}