Settings update

modified:   src/launcher.rs
	modified:   src/main.rs
	modified:   src/www/portable.html
This commit is contained in:
Michael Wain 2025-03-17 15:15:12 +03:00
parent 9ad5537385
commit 882a7639a2
3 changed files with 65 additions and 20 deletions

View File

@ -12,7 +12,7 @@ use crate::minecraft::session::SignUpResponse;
use crate::minecraft::versions::Version;
use crate::{config::LauncherConfig, minecraft::versions::VersionConfig, util};
const JAVA_ARGS: [&str; 23] = ["-Xms1024M",
const JAVA_ARGS: [&str; 22] = ["-Xms512M",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+DisableExplicitGC",
"-XX:MaxGCPauseMillis=200",
@ -28,7 +28,7 @@ const JAVA_ARGS: [&str; 23] = ["-Xms1024M",
"-XX:G1MixedGCCountTarget=4",
"-XX:G1MixedGCLiveThresholdPercent=90",
"-XX:G1RSetUpdatingPauseTimePercent=5",
"-XX:+UseStringDeduplication", "-Xmx1024M", "-Dfile.encoding=UTF-8", "-Dfml.ignoreInvalidMinecraftCertificates=true", "-Dfml.ignorePatchDiscrepancies=true", "-Djava.net.useSystemProxies=true", "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"];
"-XX:+UseStringDeduplication", "-Dfile.encoding=UTF-8", "-Dfml.ignoreInvalidMinecraftCertificates=true", "-Dfml.ignorePatchDiscrepancies=true", "-Djava.net.useSystemProxies=true", "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump"];
#[derive(Default)]
pub struct Launcher {
@ -145,11 +145,13 @@ impl Launcher {
client_jar.push(&instance_name);
client_jar.push("client.jar");
let mut cmd = Command::new("java");
let mut cmd = Command::new(&self.config.java_path);
for arg in JAVA_ARGS {
cmd.arg(arg.to_string());
}
cmd.arg(["-Xmx", &self.config.ram_amount.to_string(), "M"].concat());
let mut natives_path = self.config.launcher_dir();
natives_path.push("instances");

View File

@ -186,6 +186,15 @@ async fn main() {
"fetch_settings" => {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["fetch_settings_response".to_string(), launcher.config.show_alpha.to_string(), launcher.config.show_beta.to_string(), launcher.config.show_snapshots.to_string(), launcher.config.java_path.clone(), launcher.config.ram_amount.to_string()] }).unwrap()));
}
"update_settings" => {
let params = &params.unwrap().params;
launcher.config.java_path = params[3].clone();
launcher.config.ram_amount = params[4].parse().unwrap();
launcher.config.show_alpha = params[0].parse().unwrap();
launcher.config.show_beta = params[1].parse().unwrap();
launcher.config.show_snapshots = params[2].parse().unwrap();
launcher.save_config();
}
_ => {}
}
}

View File

@ -194,7 +194,7 @@
</div>
<div id="installation-section" class="xsection bg-white shadow-lg rounded-xl p-6 w-96 text-center">
<h1 class="text-2xl font-semibold text-gray-700">Welcome to Minecraft Launcher</h1>
<h1 class="text-2xl font-semibold text-gray-700">Welcome to XCraft</h1>
<p class="mt-2 text-gray-600">Choose how you want to set up Minecraft.</p>
<!-- Portable Mode -->
@ -258,18 +258,15 @@
</div>
<div id="settings-section" class="xsection bg-white shadow-lg rounded-xl p-6 w-96 text-center hidden">
<h2 class="text-2xl font-semibold text-gray-700">Launcher Settings</h2>
<!-- Tabs -->
<h2 class="text-2xl font-semibold text-gray-700">XCraft Settings</h2>
<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-mug-hot"></i> Java</button>
<button onClick="setSettingsTab('launcher')" class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-rocket"></i></br>Launcher</button>
<button onClick="setSettingsTab('appearance')" class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-palette"></i></br>Appearance</button>
<button onClick="setSettingsTab('java')" class="py-2 px-4 focus:text-green-500"><i class="fa-solid fa-mug-hot"></i></br>Java</button>
</div>
<!-- Sections -->
<div id="launcher-settings" class="settings-tab mt-4">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-rocket"></i> Launcher Settings</h3>
<div class="mt-4 flex justify-between items-center">
<label class="inline-flex items-center cursor-pointer">
<input id="show-beta" type="checkbox" value="" class="sr-only peer">
@ -293,8 +290,19 @@
</div>
</div>
<div id="appearance-settings" class="settings-tab mt-4 hidden">
<div class="mt-4 flex items-center border border-gray-300 rounded-lg overflow-hidden">
<input type="file" id="bg-picker" class="hidden" accept=".jpg, .jpeg, .png" onchange="bgSelected(event)">
<input id="background-path" type="text" placeholder="Custom background name"
class="flex-1 px-4 py-2 focus:outline-none">
<button onclick="$('#bg-picker').click()"
class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 font-bold transition">
Set
</button>
</div>
</div>
<div id="java-settings" class="settings-tab mt-4 hidden">
<h3 class="text-lg font-semibold text-gray-700"><i class="fa-solid fa-mug-hot"></i> Java Settings</h3>
<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">
@ -307,14 +315,12 @@
<input type="number" id="ram-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" value="1024" required />
</div>
<button
onClick="saveSettings()" class="w-full mt-6 bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded transition">
<i class="fa-solid fa-floppy-disk"></i> Save
</button>
<p class="mt-4 text-sm text-gray-500">Minecraft Launcher v1.0</p>
<p class="mt-4 text-sm text-gray-500">alterdekim</p>
</div>
<div id="appearance-section" class="xsection bg-white shadow-lg rounded-xl p-6 w-96 text-center hidden">
@ -415,7 +421,6 @@
<script type="text/javascript">
function processParams(r) {
console.log("got", r);
let params = JSON.parse(r).params;
for( let i = 0; i < params.length; i++ ) {
if( params[i].startsWith("show_") ) {
@ -452,6 +457,28 @@
}
}
function bgSelected(event) {
let file = event.target.files[0];
if(file) {
let allowedTypes = ["image/jpeg", "image/png"];
if (allowedTypes.includes(file.type)) {
$("#background-path").val(file.name);
} else {
showPopup("This format is not allowed!");
}
}
}
function saveSettings() {
let show_alpha = $("#show-alpha").prop('checked');
let show_beta = $("#show-beta").prop('checked');
let show_snapshots = $("#show-snapshots").prop('checked');
let java_path = $("#java-path").val();
let ram_input = $("#ram-input").val();
$.post({url: "update_settings", data: JSON.stringify({ params: [show_alpha+"", show_beta+"", show_snapshots+"", java_path, ram_input+""] }) }, processParams);
showPopup("Saved!");
}
function setSettings(params) {
$("#show-alpha").prop('checked', (params[0] === 'true'));
$("#show-beta").prop('checked', (params[1] === 'true'));
@ -549,11 +576,18 @@
}
function runPortable() {
console.log($.get("portable", processParams));
$.get("portable", processParams);
}
function installMinecraft() {
console.log($.get("installation", processParams));
$.get("installation", processParams);
}
function setSettingsTab(tab_name) {
$(".settings-tab").each(function(i, d) {
$(d).addClass('hidden');
});
$("#"+tab_name+"-settings").removeClass('hidden');
}
function showSection(obj, section) {