Compare commits

..

2 Commits

Author SHA1 Message Date
756ae1be58 progress status and progress communication done 2024-01-12 12:09:28 +01:00
4569d35a65 rework progressbar 2024-01-12 12:09:11 +01:00
9 changed files with 149 additions and 61 deletions

120
main.js
View File

@ -18,32 +18,44 @@ function isDev() {
function registerIPCPipes() {
ipcMain.handle("ezpplauncher:login", async (e, args) => {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
method: "POST",
body: JSON.stringify({
username: args.username,
password: args.password,
}),
headers: {
"Content-Type": "application/json",
},
});
const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000);
try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
signal: timeout.signal,
method: "POST",
body: JSON.stringify({
username: args.username,
password: args.password,
}),
headers: {
"Content-Type": "application/json",
},
});
if (fetchResult.ok) {
const result = await fetchResult.json();
if ("user" in result) {
if (args.saveCredentials) {
config.set("username", args.username);
config.set("password", args.password);
clearTimeout(timeoutId);
if (fetchResult.ok) {
const result = await fetchResult.json();
if ("user" in result) {
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) => {
@ -54,25 +66,37 @@ function registerIPCPipes() {
if (username == undefined || password == undefined) {
return { code: 200, message: "No autologin" };
}
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
method: "POST",
body: JSON.stringify({
username: username,
password: password,
}),
headers: {
"Content-Type": "application/json",
},
});
const timeout = new AbortController();
const timeoutId = setTimeout(() => timeout.abort(), 8000);
try {
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
signal: timeout.signal,
method: "POST",
body: JSON.stringify({
username: username,
password: password,
}),
headers: {
"Content-Type": "application/json",
},
});
if (fetchResult.ok) {
const result = await fetchResult.json();
return result;
clearTimeout(timeoutId);
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) => {
@ -87,6 +111,24 @@ function registerIPCPipes() {
config.remove("guest");
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() {

View File

@ -36,3 +36,19 @@ window.addEventListener("logout", async (e) => {
window.addEventListener("guest-login", async (e) => {
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,
DropdownItem,
DropdownHeader,
DropdownDivider
DropdownDivider,
} from "flowbite-svelte";
import {
ArrowRightFromBracketSolid,
ArrowRightToBracketSolid,
UserSettingsSolid
UserSettingsSolid,
} from "flowbite-svelte-icons";
import ezppLogo from "../public/favicon.png";
import {
currentPage,
currentUser,
launching,
launchStatus
launchPercentage,
launchStatus,
} from "./storage/localStore";
import { Page } from "./consts/pages";
import Login from "./pages/Login.svelte";
@ -40,9 +41,16 @@
};
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);
});
window.addEventListener("launchProgressUpdate", (e) => {
console.log((e as CustomEvent).detail);
const progress = (e as CustomEvent).detail.progress;
launchPercentage.set(progress);
});
</script>
<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 {
50% {
background-position-x: -115%;

View File

@ -2,9 +2,10 @@
import { cubicOut } from "svelte/easing";
import { tweened } from "svelte/motion";
import { twMerge, twJoin } from "tailwind-merge";
import { clamp } from "../util/mathUtil";
export let progress: string | number | undefined | null = "45";
export let precision = 0;
export let progress: number = 45;
export let precision = 2;
export let tweenDuration = 400;
export let animate = false;
export let size = "h-2.5";
@ -12,10 +13,10 @@
export let labelOutside = "";
export let easing = cubicOut;
export let color = "primary";
export let indeterminate = false;
export let labelInsideClass =
"text-primary-100 text-xs font-medium text-center p-0.5 leading-none rounded-full";
export let divClass = "w-full bg-gray-200 rounded-full dark:bg-gray-700";
export let indeterminate = progress == null;
const barColors: Record<string, string> = {
primary: "bg-primary-600",
@ -28,15 +29,14 @@
indigo: "bg-indigo-600 dark:bg-indigo-500",
};
const _progress = tweened(0, {
duration: animate && !indeterminate ? tweenDuration : 0,
let _progress = tweened(0, {
duration: tweenDuration,
easing,
});
$: {
if (!indeterminate) {
_progress.set(Number(progress));
}
progress = clamp(Number(progress), 0, 100);
_progress.set(progress);
}
</script>
@ -49,7 +49,9 @@
>{labelOutside}</span
>
<span class="text-sm font-medium text-blue-700 dark:text-white"
>{progress}%</span
>{animate
? $_progress.toFixed(precision)
: progress.toFixed(precision)}%</span
>
</div>
{/if}
@ -59,9 +61,9 @@
{#if !indeterminate}
<div
class={twJoin(labelInsideClass, barColors[color])}
style="width: {$_progress}%"
style="width: {animate ? $_progress : progress}%"
>
{$_progress.toFixed(precision)}%
{animate ? $_progress.toFixed(precision) : progress.toFixed(precision)}%
</div>
{:else}
<div
@ -75,7 +77,7 @@
{:else if !indeterminate}
<div
class={twJoin(barColors[color], size, "rounded-full")}
style="width: {$_progress}%"
style="width: {animate ? $_progress : progress}%"
/>
{:else}
<div

View File

@ -1,7 +1,12 @@
<script lang="ts">
import { Button, Checkbox } from "flowbite-svelte";
import Progressbar from "../lib/Progressbar.svelte";
import { launching, patch, launchStatus } from "./../storage/localStore";
import {
launching,
patch,
launchStatus,
launchPercentage,
} from "./../storage/localStore";
let progressbarFix = true;
setTimeout(() => {
@ -10,7 +15,8 @@
const launch = () => {
launching.set(true);
}
window.dispatchEvent(new CustomEvent("launch"));
};
</script>
<main
@ -26,7 +32,7 @@
? ''
: 'active:scale-95 '}transition-transform duration-75"
disabled={$launching}
on:click={() => launching.set(!$launching)}>Launch</Button
on:click={launch}>Launch</Button
>
<Checkbox
disabled={$launching}
@ -40,10 +46,12 @@
>
<Progressbar
animate={true}
progress={null}
progress={$launchPercentage}
indeterminate={$launchPercentage == -1}
labelInside={true}
size="h-3"
labelInsideClass="bg-primary-600 drop-shadow-xl text-gray-100 text-base font-medium text-center p-1 leading-none rounded-full"
class=""
labelInsideClass="bg-primary-600 drop-shadow-xl text-gray-100 text-base font-medium text-center p-1 leading-none rounded-full !text-[0.7rem] !leading-[0.45]"
/>
<p class="m-0 p-0 dark:text-gray-400 font-light">{$launchStatus}</p>
</div>

View File

@ -142,7 +142,9 @@
{/if}
</Button>
</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">
<Button
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",
fadeOut: "fadeOut 1s ease forwards",
},
transitionProperty: {
'width': 'width',
},
colors: {
// flowbite-svelte
primary: {