progress status and progress communication done

This commit is contained in:
HorizonCode 2024-01-12 12:09:28 +01:00
parent 4569d35a65
commit 756ae1be58
7 changed files with 122 additions and 44 deletions

120
main.js
View File

@ -18,32 +18,44 @@ function isDev() {
function registerIPCPipes() { function registerIPCPipes() {
ipcMain.handle("ezpplauncher:login", async (e, args) => { ipcMain.handle("ezpplauncher:login", async (e, args) => {
const fetchResult = await fetch("https://ez-pp.farm/login/check", { const timeout = new AbortController();
method: "POST", const timeoutId = setTimeout(() => timeout.abort(), 8000);
body: JSON.stringify({ try {
username: args.username, const fetchResult = await fetch("https://ez-pp.farm/login/check", {
password: args.password, signal: timeout.signal,
}), method: "POST",
headers: { body: JSON.stringify({
"Content-Type": "application/json", username: args.username,
}, password: args.password,
}); }),
headers: {
"Content-Type": "application/json",
},
});
if (fetchResult.ok) { clearTimeout(timeoutId);
const result = await fetchResult.json();
if ("user" in result) { if (fetchResult.ok) {
if (args.saveCredentials) { const result = await fetchResult.json();
config.set("username", args.username); if ("user" in result) {
config.set("password", args.password); if (args.saveCredentials) {
config.set("username", args.username);
config.set("password", args.password);
}
config.remove("guest");
} }
config.remove("guest"); return result;
} }
return result; return {
code: 500,
message: "Something went wrong while logging you in.",
};
} catch (err) {
return {
code: 500,
message: "Something went wrong while logging you in.",
};
} }
return {
code: 500,
message: "Something went wrong while logging you in.",
};
}); });
ipcMain.handle("ezpplauncher:autologin", async (e) => { ipcMain.handle("ezpplauncher:autologin", async (e) => {
@ -54,25 +66,37 @@ function registerIPCPipes() {
if (username == undefined || password == undefined) { if (username == undefined || password == undefined) {
return { code: 200, message: "No autologin" }; return { code: 200, message: "No autologin" };
} }
const fetchResult = await fetch("https://ez-pp.farm/login/check", { const timeout = new AbortController();
method: "POST", const timeoutId = setTimeout(() => timeout.abort(), 8000);
body: JSON.stringify({ try {
username: username, const fetchResult = await fetch("https://ez-pp.farm/login/check", {
password: password, signal: timeout.signal,
}), method: "POST",
headers: { body: JSON.stringify({
"Content-Type": "application/json", username: username,
}, password: password,
}); }),
headers: {
"Content-Type": "application/json",
},
});
if (fetchResult.ok) { clearTimeout(timeoutId);
const result = await fetchResult.json();
return result; if (fetchResult.ok) {
const result = await fetchResult.json();
return result;
}
return {
code: 500,
message: "Something went wrong while logging you in.",
};
} catch (err) {
return {
code: 500,
message: "Something went wrong while logging you in.",
};
} }
return {
code: 500,
message: "Something went wrong while logging you in.",
};
}); });
ipcMain.handle("ezpplauncher:guestlogin", (e) => { ipcMain.handle("ezpplauncher:guestlogin", (e) => {
@ -87,6 +111,24 @@ function registerIPCPipes() {
config.remove("guest"); config.remove("guest");
return true; return true;
}); });
ipcMain.handle("ezpplauncher:launch", async (e) => {
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking osu! directory...",
});
await new Promise((res) => setTimeout(res, 1500));
mainWindow.webContents.send("ezpplauncher:launchstatus", {
status: "Checking for osu! updates...",
});
mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 0,
});
await new Promise((res) => setTimeout(res, 1500));
mainWindow.webContents.send("ezpplauncher:launchprogress", {
progress: 100,
});
return true;
});
} }
function createWindow() { function createWindow() {

View File

@ -36,3 +36,19 @@ window.addEventListener("logout", async (e) => {
window.addEventListener("guest-login", async (e) => { window.addEventListener("guest-login", async (e) => {
await ipcRenderer.invoke("ezpplauncher:guestlogin"); await ipcRenderer.invoke("ezpplauncher:guestlogin");
}); });
window.addEventListener("launch", async (e) => {
await ipcRenderer.invoke("ezpplauncher:launch");
});
ipcRenderer.addListener("ezpplauncher:launchstatus", (e, args) => {
window.dispatchEvent(
new CustomEvent("launchStatusUpdate", { detail: args }),
);
});
ipcRenderer.addListener("ezpplauncher:launchprogress", (e, args) => {
window.dispatchEvent(
new CustomEvent("launchProgressUpdate", { detail: args }),
);
});

View File

@ -4,19 +4,20 @@
Dropdown, Dropdown,
DropdownItem, DropdownItem,
DropdownHeader, DropdownHeader,
DropdownDivider DropdownDivider,
} from "flowbite-svelte"; } from "flowbite-svelte";
import { import {
ArrowRightFromBracketSolid, ArrowRightFromBracketSolid,
ArrowRightToBracketSolid, ArrowRightToBracketSolid,
UserSettingsSolid UserSettingsSolid,
} from "flowbite-svelte-icons"; } from "flowbite-svelte-icons";
import ezppLogo from "../public/favicon.png"; import ezppLogo from "../public/favicon.png";
import { import {
currentPage, currentPage,
currentUser, currentUser,
launching, launching,
launchStatus launchPercentage,
launchStatus,
} from "./storage/localStore"; } from "./storage/localStore";
import { Page } from "./consts/pages"; import { Page } from "./consts/pages";
import Login from "./pages/Login.svelte"; import Login from "./pages/Login.svelte";
@ -40,9 +41,16 @@
}; };
window.addEventListener("launchStatusUpdate", (e) => { window.addEventListener("launchStatusUpdate", (e) => {
const status = (e as CustomEvent).detail; console.log((e as CustomEvent).detail);
const status = (e as CustomEvent).detail.status;
launchStatus.set(status); launchStatus.set(status);
}); });
window.addEventListener("launchProgressUpdate", (e) => {
console.log((e as CustomEvent).detail);
const progress = (e as CustomEvent).detail.progress;
launchPercentage.set(progress);
});
</script> </script>
<Toaster></Toaster> <Toaster></Toaster>

View File

@ -54,6 +54,10 @@ html .cet-titlebar .cet-control-icon svg {
} }
} }
.animatedProgress div {
transition: width 0.35s cubic-bezier(0.65, -0.02, 0.31, 1.01);
}
@keyframes progress-loading { @keyframes progress-loading {
50% { 50% {
background-position-x: -115%; background-position-x: -115%;

View File

@ -142,7 +142,9 @@
{/if} {/if}
</Button> </Button>
</Input> </Input>
<Checkbox bind:checked={saveCredentials}>Save credentials</Checkbox> <Checkbox bind:checked={saveCredentials} disabled={loading}
>Save credentials</Checkbox
>
<div class="flex flex-col justify-center items-center gap-5 mt-1"> <div class="flex flex-col justify-center items-center gap-5 mt-1">
<Button <Button
class="dark:active:!bg-gray-900 active:scale-95 transition-transform duration-75" class="dark:active:!bg-gray-900 active:scale-95 transition-transform duration-75"

3
src/util/mathUtil.ts Normal file
View File

@ -0,0 +1,3 @@
export const clamp = (val: number, min: number, max: number) => {
return val <= min ? min : val >= max ? max : val;
};

View File

@ -21,6 +21,9 @@ const config = {
fadeIn: "fadeIn 1s ease forwards", fadeIn: "fadeIn 1s ease forwards",
fadeOut: "fadeOut 1s ease forwards", fadeOut: "fadeOut 1s ease forwards",
}, },
transitionProperty: {
'width': 'width',
},
colors: { colors: {
// flowbite-svelte // flowbite-svelte
primary: { primary: {