diff --git a/src/lib/main/MainScreen.svelte b/src/lib/main/MainScreen.svelte
index 6e595b7..21f36a9 100644
--- a/src/lib/main/MainScreen.svelte
+++ b/src/lib/main/MainScreen.svelte
@@ -31,26 +31,44 @@
const dispatch = createEventDispatcher();
+ let defaultDataFolder = "";
+
+ let settingsShown = false;
+ let versionSelectShown = false;
+ let clientLogShown = false;
+
+ let clientRunning = false;
+
let versionInfo = {
- bannerUrl: "https://liquidbounce.net/LiquidLauncher/img/b73.jpg",
+ bannerUrl: "img/banner.png", // TODO: placeholder image
title: "Loading...",
date: "Loading...",
description: "Loading...",
};
- let settingsShown = false;
- let versionSelectShown = false;
- let clientLogShown = false;
+ let progressBar = {
+ max: 0,
+ value: 0,
+ text: ""
+ };
+
+ let recommendedMods = [];
+ let customMods = [];
+ let branches = [];
+ let builds = [];
+ let currentBuild = {};
- let log = [];
+ let launcherVersion = "";
- let progressBarMax = 0;
- let progressBarProgress = 0;
- let progressBarLabel = "";
+ let additionalModsTitle = "";
+ $: {
+ additionalModsTitle = `Additional mods for ${currentBuild.branch} ${currentBuild.mcVersion}`;
+ }
- let launcherVersion = "";
+ let log = [];
- invoke("get_launcher_version").then(res => (launcherVersion = res));
+ invoke("get_launcher_version")
+ .then(res => (launcherVersion = res));
listen("process-output", event => {
log = [...log, event.payload];
@@ -60,25 +78,21 @@
let progressUpdate = event.payload;
switch (progressUpdate.type) {
- case "max": {
- progressBarMax = progressUpdate.value;
- break;
- }
- case "progress": {
- progressBarProgress = progressUpdate.value;
- break;
- }
- case "label": {
- progressBarLabel = progressUpdate.value;
- break;
- }
+ case "max": {
+ progressBar.max = progressUpdate.value;
+ break;
}
+ case "progress": {
+ progressBar.value = progressUpdate.value;
+ break;
+ }
+ case "label": {
+ progressBar.text = progressUpdate.value;
+ break;
+ }
+ }
});
- let branches = [];
-
- let builds = [];
-
function getBuild() {
if (options.preferredBuild === -1) { // -1 = latest
// The find() method returns a value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
@@ -88,89 +102,97 @@
return builds.find((build) => build.buildId === options.preferredBuild);
}
- let lbVersion = "";
- let mcVersion = "";
- let branch = "";
-
- let additionalModsTitle = "";
+ function hideSettings() {
+ settingsShown = false;
+ options.store();
+ }
- $: {
- additionalModsTitle = `Additional mods for ${branch} ${mcVersion}`;
+ function hideVersionSelection() {
+ versionSelectShown = false;
+ options.store();
}
- let mods = [];
- let customMods = [];
+ function updateModStates() {
+ const branchOptions = {
+ modStates: {},
+ customModStates: {}
+ };
+
+ for (const mod of recommendedMods) {
+ branchOptions.modStates[mod.name] = mod.enabled;
+ }
+
+ for (const mod of customMods) {
+ branchOptions.customModStates[mod.name] = mod.enabled;
+ }
+
+ options.branchOptions[options.preferredBranch] = branchOptions;
+ options.store();
+ }
/// Request builds from API server
- function requestBuilds() {
- invoke("request_builds", { branch: options.preferredBranch })
- .then(result => {
- builds = result;
-
- // Format date for user readability
- builds.forEach(build => {
- let date = new Date(build.date);
- build.date = date.toLocaleString();
- build.dateDay = date.toLocaleDateString();
- });
-
- updateData();
- })
- .catch(e => console.error(e));
+ async function requestBuilds() {
+ const requestedBuilds = await invoke("request_builds", { branch: options.preferredBranch });
+ requestedBuilds.forEach(build => {
+ const date = new Date(build.date);
+ build.date = date.toLocaleString();
+ build.dateDay = date.toLocaleDateString();
+ });
+
+ builds = requestedBuilds;
+
+ await updateData();
}
/// Update build data
- function updateData() {
- let b = getBuild();
- console.debug("Updating build data", b);
-
- branch = b.branch;
- lbVersion = b.lbVersion;
- mcVersion = b.mcVersion;
+ async function updateData() {
+ currentBuild = getBuild();
// Update changelog
- invoke("fetch_changelog", { buildId: b.buildId })
- .then(result => {
- console.log("Fetched changelog data", result);
- versionInfo = {
- bannerUrl: "https://liquidbounce.net/LiquidLauncher/img/b73.jpg",
- title: "LiquidBounce " + b.lbVersion + " for Minecraft " + b.mcVersion,
- date: b.dateDay,
- description: result.changelog,
- };
- })
- .catch(e => console.error(e));
-
- requestMods(b.branch, b.mcVersion, b.subsystem);
+ const changelog = await invoke("fetch_changelog", { buildId: currentBuild.buildId });
+ versionInfo = {
+ bannerUrl: "img/banner.png",
+ title: `LiquidBounce ${currentBuild.lbVersion} for Minecraft ${currentBuild.mcVersion}`,
+ date: currentBuild.dateDay,
+ description: changelog.changelog
+ };
+
+ requestMods();
}
/// Request mods from API server
- function requestMods(branch, mcVersion, subsystem) {
+ async function requestMods() {
+ const { branch, mcVersion, subsystem } = currentBuild;
const branchOptions = options.branchOptions[branch];
- invoke("request_mods", { branch, mcVersion, subsystem })
- .then(result => {
- mods = result;
-
- if (branchOptions) {
- mods.forEach(mod => {
- mod.enabled = branchOptions.modStates[mod.name] ?? mod.enabled;
- });
- }
- })
- .catch(e => console.error(e));
-
- invoke("get_custom_mods", { branch, mcVersion })
- .then(result => {
- customMods = result;
-
- if (branchOptions) {
- customMods.forEach(mod => {
- mod.enabled = branchOptions.customModStates[mod.name] ?? mod.enabled;
- });
- }
- })
- .catch(e => console.error(e));
+ recommendedMods = await invoke("request_mods", { branch, mcVersion, subsystem });
+ customMods = await invoke("get_custom_mods", { branch, mcVersion });
+
+ if (branchOptions) {
+ recommendedMods = recommendedMods.map(mod => {
+ return { ...mod, enabled: branchOptions.modStates[mod.name] ?? mod.enabled };
+ });
+
+ customMods = customMods.map(mod => {
+ return { ...mod, enabled: branchOptions.customModStates[mod.name] ?? mod.enabled };
+ });
+ }
+ }
+
+ async function runClient() {
+ console.log("Client started");
+ log = [];
+ clientRunning = true;
+
+ let build = getBuild();
+ console.debug("Running build", build);
+
+ console.log([...recommendedMods, ...customMods])
+ await invoke("run_client", { buildId: build.buildId, accountData: options.currentAccount, options: options, mods: [...recommendedMods, ...customMods] });
+ }
+
+ async function terminateClient() {
+ await invoke("terminate");
}
// Request branches from API server
@@ -190,68 +212,17 @@
})
.catch(e => console.error(e));
- function hideSettings() {
- settingsShown = false;
- options.store();
- }
-
- function hideVersionSelection() {
- versionSelectShown = false;
- options.store();
- }
-
- let clientRunning = false;
-
- async function runClient() {
- console.log("Client started");
- log = [];
- clientRunning = true;
-
- let build = getBuild();
- console.debug("Running build", build);
-
- console.log([...mods, ...customMods])
- await invoke("run_client", { buildId: build.buildId, accountData: options.currentAccount, options: options, mods: [...mods, ...customMods] });
- }
-
listen("client-exited", () => {
clientRunning = false;
});
listen("client-error", (e) => {
const message = e.payload;
-
- console.error(message);
clientLogShown = true;
alert(message);
});
- function updateModStates() {
- const branchOptions = options.branchOptions[options.preferredBranch] ?? {
- modStates: {},
- customModStates: {}
- };
-
- branchOptions.modStates = mods.reduce(function(map, mod) {
- map[mod.name] = mod.enabled;
- return map;
- }, {});
-
- branchOptions.customModStates = customMods.reduce(function(map, mod) {
- map[mod.name] = mod.enabled;
- return map;
- }, {});
-
- console.log("Updated mod states", branchOptions);
- options.branchOptions[options.preferredBranch] = branchOptions;
- options.store();
- }
-
- async function terminateClient() {
- await invoke("terminate");
- }
-
function clearData() {
invoke("clear_data", { options }).then(() => {
alert("Data cleared.");
@@ -261,24 +232,23 @@
});
}
- let dataFolderPath;
invoke("default_data_folder_path").then(result => {
- dataFolderPath = result;
+ defaultDataFolder = result;
}).catch(e => {
alert("Failed to get data folder: " + e);
- console.error(e)
+ console.error(e);
});
async function handleCustomModDelete(e) {
- const { branch, mcVersion, subsystem } = getBuild();
+ const { branch, mcVersion } = currentBuild;
await invoke("delete_custom_mod", { branch, mcVersion, modName: `${e.detail.name}.jar` });
- requestMods(branch, mcVersion, subsystem);
+ requestMods();
}
async function handleInstallMod(e) {
- const { branch, mcVersion, subsystem } = getBuild();
+ const { branch, mcVersion } = currentBuild;
const selected = await dialogOpen({
directory: false,
@@ -289,7 +259,7 @@
if (selected) {
await invoke("install_custom_mod", { branch, mcVersion, path: selected });
- requestMods(branch, mcVersion, subsystem);
+ requestMods();
}
}
@@ -301,7 +271,7 @@
{#if settingsShown}
-
+
@@ -317,7 +287,7 @@
e.release || options.showNightlyBuilds).map(e => ({ value: e.buildId, text: e.lbVersion + " git-" + e.commitId.substring(0, 7) + " - " + e.date }))]} bind:value={options.preferredBuild} on:change={updateData} />
- {#each mods as m}
+ {#each recommendedMods as m}
{/each}
@@ -340,7 +310,7 @@
{#if !clientRunning}
{:else}
-
+
{/if}
settingsShown = true} />
@@ -348,7 +318,7 @@
- versionSelectShown = true} on:showClientLog={() => clientLogShown = true} on:launch={runClient} on:terminate={terminateClient} running={clientRunning} />
+ versionSelectShown = true} on:showClientLog={() => clientLogShown = true} on:launch={runClient} on:terminate={terminateClient} running={clientRunning} />
diff --git a/src/lib/main/news/News.svelte b/src/lib/main/news/News.svelte
index b97172d..ee7b6a8 100644
--- a/src/lib/main/news/News.svelte
+++ b/src/lib/main/news/News.svelte
@@ -8,7 +8,7 @@
export let url;
export let description;
- function handleClick() {
+ function handleShowNews(e) {
invoke("open_url", { url: url });
}
@@ -23,7 +23,7 @@
{new Date(date).toLocaleDateString()}