diff --git a/main.js b/main.js
index da5d1b8..0536b6c 100644
--- a/main.js
+++ b/main.js
@@ -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() {
diff --git a/preload.js b/preload.js
index 87bed75..0c862fb 100644
--- a/preload.js
+++ b/preload.js
@@ -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 }),
+ );
+});
diff --git a/src/App.svelte b/src/App.svelte
index 62716a0..0ba0886 100644
--- a/src/App.svelte
+++ b/src/App.svelte
@@ -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);
+ });