modified: Cargo.toml

This commit is contained in:
Michael Wain 2025-03-15 03:08:57 +03:00
parent 5501f57c6e
commit aa417bd470
6 changed files with 86 additions and 45 deletions

16
Cargo.lock generated
View File

@ -9,6 +9,7 @@ dependencies = [
"base64 0.22.1",
"dirs",
"futures",
"java-locator",
"rand 0.9.0",
"serde",
"serde_json",
@ -1544,6 +1545,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "glob"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
[[package]]
name = "gloo-timers"
version = "0.3.0"
@ -2061,6 +2068,15 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "java-locator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09c46c1fe465c59b1474e665e85e1256c3893dd00927b8d55f63b09044c1e64f"
dependencies = [
"glob",
]
[[package]]
name = "javascriptcore-rs"
version = "1.1.2"

View File

@ -15,4 +15,5 @@ serde_json = "1.0"
toml = "0.8.20"
surf = { version = "2.3.2", features = ["hyper-client"] }
base64 = "0.22.1"
zip-extract = "0.2.1"
zip-extract = "0.2.1"
java-locator = "0.1.9"

View File

@ -7,8 +7,9 @@ use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize)]
pub struct LauncherConfig {
is_portable: bool,
pub user_name: String,
pub user_secret: String
user_name: String,
pub user_secret: String,
pub java_path: String
}
impl LauncherConfig {
@ -28,6 +29,14 @@ impl LauncherConfig {
p.push("config.toml");
p
}
pub fn user_name(&self) -> &str {
&self.user_name
}
pub fn set_username(&mut self, user_name: String) {
self.user_name = user_name;
}
}
pub fn get_relative_launcher_dir() -> PathBuf {

View File

@ -55,7 +55,7 @@ impl Launcher {
pub fn init_config(&mut self, user_name: String) {
self.load_config();
self.config.user_name = user_name;
self.config.set_username(user_name);
self.config.user_secret = crate::util::random_string(32);
self.save_config();
}
@ -145,7 +145,7 @@ impl Launcher {
let mut assets_dir = self.config.launcher_dir();
assets_dir.push("assets");
cmd.args(&["--username", &self.config.user_name, "--version", &instance_name, "--gameDir", game_dir.to_str().unwrap(), "--assetsDir", assets_dir.to_str().unwrap(), "--assetIndex", &config.assetIndex.id, "--uuid", "51820246d9fe372b81592602a5239ad9", "--accessToken", "51820246d9fe372b81592602a5239ad9", "--userProperties", "{}", "--userType", "mojang", "--width", "925", "--height", "530"]);
cmd.args(&["--username", self.config.user_name(), "--version", &instance_name, "--gameDir", game_dir.to_str().unwrap(), "--assetsDir", assets_dir.to_str().unwrap(), "--assetIndex", &config.assetIndex.id, "--uuid", "51820246d9fe372b81592602a5239ad9", "--accessToken", "51820246d9fe372b81592602a5239ad9", "--userProperties", "{}", "--userType", "mojang", "--width", "925", "--height", "530"]);
cmd.spawn();
}
}

View File

@ -161,6 +161,14 @@ async fn main() {
let instance_name = params.unwrap().params[0].clone();
launcher.launch_instance(instance_name).await;
}
"locate_java" => {
if let Ok(java_path) = java_locator::locate_file("java.exe") {
launcher.config.java_path = java_path.clone();
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["locate_java".to_string(), [&java_path, "java.exe"].join("\\")] }).unwrap()));
} else {
// todo: implement error notifications
}
}
_ => {}
}
}

View File

@ -242,56 +242,51 @@
<!-- Tabs -->
<div class="mt-4 flex justify-around text-gray-600">
<button class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-rocket"></i> Launcher</button>
<button class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-gamepad"></i> Minecraft</button>
<button class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-mug-hot"></i> Java</button>
<button class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-cube"></i> Versions</button>
</div>
<!-- Sections -->
<div id="launcher" class="settings-tab mt-4">
<div id="launcher" class="settings-tab mt-4 hidden">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-rocket"></i> Launcher Settings</h3>
<label class="block mt-3 text-gray-600">Auto-update:</label>
<select class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-green-500">
<option>Enabled</option>
<option>Disabled</option>
</select>
<label class="block mt-3 text-gray-600">UI Theme:</label>
<select class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-green-500">
<option>Light</option>
<option>Dark</option>
</select>
<div class="mt-4 flex justify-between items-center">
<label class="inline-flex items-center cursor-pointer">
<input type="checkbox" value="" class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 dark:peer-focus:ring-green-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600 dark:peer-checked:bg-green-600"></div>
<span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Show beta versions</span>
</label>
</div>
<div class="mt-4 flex justify-between items-center">
<label class="inline-flex items-center cursor-pointer">
<input type="checkbox" value="" class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 dark:peer-focus:ring-green-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600 dark:peer-checked:bg-green-600"></div>
<span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Show alpha versions</span>
</label>
</div>
<div class="mt-4 flex justify-between items-center">
<label class="inline-flex items-center cursor-pointer">
<input type="checkbox" value="" class="sr-only peer">
<div class="relative w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-green-300 dark:peer-focus:ring-green-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-green-600 dark:peer-checked:bg-green-600"></div>
<span class="ms-3 text-sm font-medium text-gray-900 dark:text-gray-300">Show snapshots</span>
</label>
</div>
</div>
<div id="minecraft" class="settings-tab mt-4 hidden">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-gamepad"></i> Minecraft Settings</h3>
<label class="block mt-3 text-gray-600">Game Directory:</label>
<input type="text" placeholder="/path/to/minecraft" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-green-500">
<label class="block mt-3 text-gray-600">RAM Allocation:</label>
<input type="range" min="1024" max="16384" step="512" class="w-full">
<label class="block mt-3 text-gray-600">Enable Mods:</label>
<input type="checkbox" class="ml-2">
</div>
<div id="java" class="settings-tab mt-4 hidden">
<div id="java" class="settings-tab mt-4">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-mug-hot"></i> Java Settings</h3>
<label class="block mt-3 text-gray-600">Java Path:</label>
<input type="text" placeholder="/path/to/java" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-green-500">
<label class="block mt-3 text-gray-600">Custom JVM Arguments:</label>
<textarea class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-green-500" rows="2">-Xmx4G -Xms2G</textarea>
<div class="mt-4 flex items-center border border-gray-300 rounded-lg overflow-hidden">
<input id="java-path" type="text" placeholder="Enter Java Path"
class="flex-1 px-4 py-2 focus:outline-none">
<button onclick="locateJava()"
class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 font-bold transition">
Auto
</button>
</div>
<label for="number-input" class="block mb-2 text-sm font-medium text-gray-800 dark:text-white">Allocate memory (MB):</label>
<input type="number" id="number-input" min="1024" step="1" aria-describedby="helper-text-explanation" class="bg-white border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-green-500 focus:border-green-500 block w-full p-2.5" placeholder="1024" required />
</div>
<div id="versions" class="settings-tab mt-4 hidden">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-cube"></i> Version Settings</h3>
<label class="block mt-3 text-gray-600">Show Experimental Versions:</label>
<input type="checkbox" class="ml-2">
<label class="block mt-3 text-gray-600">Show Snapshots:</label>
<input type="checkbox" class="ml-2">
</div>
<button
class="w-full mt-6 bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition">
@ -402,10 +397,22 @@
showInstancesSection();
} else if( params[i] == "set_instances_list" ) {
setInstancesList(params.slice(i+1));
break;
} else if( params[i] == "locate_java" ) {
setJavaPath(params[i+1]);
break;
}
}
}
function setJavaPath(javaPath) {
$("#java-path").val(javaPath);
}
function locateJava() {
$.post({url: "locate_java" }, processParams);
}
function setInstancesList(params) {
$("#instances-section").html("");
for( let i = 0; i < params.length; i+=3 ) {