From d5b2b8012ce79eca8675c7e129e2d713d52db733 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Thu, 18 Jan 2024 14:10:47 +0100 Subject: [PATCH] fix autologin toasts --- main.js | 11 +++ preload.js | 9 ++ rollup.config.js | 6 +- src/App.svelte | 6 ++ src/pages/Login.svelte | 190 ++++++++++++++++++++++++-------------- src/pages/Settings.svelte | 23 ++++- 6 files changed, 169 insertions(+), 76 deletions(-) diff --git a/main.js b/main.js index 9aefa89..3785a98 100644 --- a/main.js +++ b/main.js @@ -137,9 +137,18 @@ function registerIPCPipes() { } }); + ipcMain.handle("ezpplauncher:autologin-active", async (e) => { + const username = config.get("username"); + const password = config.get("password"); + return username != undefined && password != undefined; + }); + ipcMain.handle("ezpplauncher:autologin", async (e) => { const hwid = getHwId(); const username = config.get("username"); + if (username == undefined) { + return { code: 200, message: "No autologin" }; + } const password = cryptUtil.decrypt(config.get("password"), hwid); const guest = config.get("guest"); if (guest) return { code: 200, message: "Login as guest", guest: true }; @@ -172,6 +181,8 @@ function registerIPCPipes() { }; } return result; + } else { + config.remove("password"); } return { code: 500, diff --git a/preload.js b/preload.js index 7e15fd6..cde3f14 100644 --- a/preload.js +++ b/preload.js @@ -22,6 +22,15 @@ window.addEventListener("login-attempt", async (e) => { ); }); +window.addEventListener("autologin-active", async (e) => { + const autologin = await ipcRenderer.invoke( + "ezpplauncher:autologin-active", + ); + window.dispatchEvent( + new CustomEvent("autologin-result", { detail: autologin }), + ); +}); + window.addEventListener("autologin-attempt", async () => { const loginResult = await ipcRenderer.invoke("ezpplauncher:autologin"); window.dispatchEvent( diff --git a/rollup.config.js b/rollup.config.js index b722fa7..e1987ea 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,7 +9,6 @@ import image from "@rollup/plugin-image"; import sveltePreprocess from "svelte-preprocess"; import typescript from "@rollup/plugin-typescript"; import progress from "rollup-plugin-progress"; -import findUnused from "rollup-plugin-unused"; const production = !process.env.ROLLUP_WATCH; @@ -48,8 +47,7 @@ export default { file: "public/build/bundle.js", }, plugins: [ - findUnused(), - progress({ clearLine: true }), + !production && progress({ clearLine: true }), svelte({ preprocess: sveltePreprocess({ sourceMap: !production }), compilerOptions: { @@ -61,7 +59,7 @@ export default { // we'll extract any component CSS out into // a separate file - better for performance css({ output: "bundle.css" }), - postcss(), + postcss({ sourceMap: "inline" }), // If you have external dependencies installed from // npm, you'll most likely need these plugins. In diff --git a/src/App.svelte b/src/App.svelte index c7ff793..4e8d051 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -38,6 +38,12 @@ window.dispatchEvent(new CustomEvent("logout")); currentUser.set(undefined); currentPage.set(Page.Login); + toast.success("Successfully logged out!", { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 2000, + }); }; window.addEventListener("launchStatusUpdate", (e) => { diff --git a/src/pages/Login.svelte b/src/pages/Login.svelte index 47bcf62..2d849be 100644 --- a/src/pages/Login.svelte +++ b/src/pages/Login.svelte @@ -15,81 +15,117 @@ const processLogin = async () => { loading = true; - window.addEventListener( - "login-result", - (e) => { - const customEvent = e as CustomEvent; - const resultData = customEvent.detail; - const wasSuccessful = "user" in resultData; + const loginPromise = new Promise((res, rej) => { + window.addEventListener( + "login-result", + (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + const wasSuccessful = "user" in resultData; - if (!wasSuccessful) { - const errorResult = resultData as Error; - toast.error(errorResult.message, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 1500, - }); - loading = false; - return; - } - const userResult = resultData.user as User; - currentUser.set(userResult); - currentPage.set(Page.Launch); - toast.success(`Welcome back, ${userResult.name}!`, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 3000, - }); - }, - { once: true } - ); - window.dispatchEvent( - new CustomEvent("login-attempt", { - detail: { username, password, saveCredentials }, - }) - ); - }; - - const tryAutoLogin = async () => { - loading = true; - await new Promise((res) => setTimeout(res, 1500)); - window.addEventListener( - "login-result", - (e) => { - const customEvent = e as CustomEvent; - const resultData = customEvent.detail; - const isGuest = "guest" in resultData; - const wasSuccessful = "user" in resultData; - if (isGuest) { + if (!wasSuccessful) { + /* const errorResult = resultData as Error; + toast.error(errorResult.message, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 1500, + }); */ + rej(); + loading = false; + return; + } + const userResult = resultData.user as User; + currentUser.set(userResult); currentPage.set(Page.Launch); - toast.success(`Logged in as Guest`, { + res(); + toast.success(`Welcome back, ${userResult.name}!`, { position: "bottom-center", className: "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", duration: 3000, }); - return; - } - if (!wasSuccessful) { - loading = false; - return; - } - const userResult = resultData.user as User; - currentUser.set(userResult); - currentPage.set(Page.Launch); - toast.success(`Welcome back, ${userResult.name}!`, { - position: "bottom-center", - className: - "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", - duration: 3000, - }); - loading = false; + }, + { once: true } + ); + window.dispatchEvent( + new CustomEvent("login-attempt", { + detail: { username, password, saveCredentials }, + }) + ); + }); + toast.promise( + loginPromise, + { + loading: "Logging in...", + success: "Successfully logged in!", + error: "Failed to login.", }, - { once: true } + { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + } + ); + }; + + const tryAutoLogin = async () => { + loading = true; + const loginPromise = new Promise((res, rej) => { + window.addEventListener( + "login-result", + (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + const isGuest = "guest" in resultData; + const wasSuccessful = "user" in resultData; + if (isGuest) { + currentPage.set(Page.Launch); + res(); + toast.success(`Logged in as Guest`, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + }); + return; + } + if (!wasSuccessful) { + loading = false; + rej(); + return; + } + const userResult = resultData.user as User; + currentUser.set(userResult); + currentPage.set(Page.Launch); + res(); + toast.success(`Welcome back, ${userResult.name}!`, { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + }); + loading = false; + }, + { once: true } + ); + window.dispatchEvent(new CustomEvent("autologin-attempt")); + }); + toast.promise( + loginPromise, + { + loading: "Logging in...", + success: "Successfully logged in!", + error: "Failed to login.", + }, + { + position: "bottom-center", + className: + "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", + duration: 3000, + } ); - window.dispatchEvent(new CustomEvent("autologin-attempt")); }; const proceedAsGuest = () => { @@ -103,10 +139,24 @@ }); }; - if (!$startup) { - startup.set(true); - tryAutoLogin(); - } + const shouldAutologin = async () => { + const shouldAutologin = await new Promise((res) => { + window.addEventListener("autologin-result", (e) => { + const customEvent = e as CustomEvent; + const resultData = customEvent.detail; + res(resultData); + }); + window.dispatchEvent(new CustomEvent("autologin-active")); + }); + return shouldAutologin; + }; + + (async () => { + if (!$startup) { + startup.set(true); + if (await shouldAutologin()) tryAutoLogin(); + } + })();
- import { Button, ButtonGroup, Input } from "flowbite-svelte"; + import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte"; import { FolderSolid } from "flowbite-svelte-icons"; import { currentPage } from "../storage/localStore"; import { Page } from "../consts/pages"; let folderPath: string = ""; + let patching: boolean = true; + let presence: boolean = true; + window.addEventListener("settings-result", (e) => { const settings: Record[] = (e as CustomEvent).detail; const osuPath = settings.find((setting) => setting.key == "osuPath"); @@ -16,11 +19,27 @@ const setFolderPath = () => { window.dispatchEvent(new CustomEvent("folder-set")); }; + + const togglePatching = () => { + patching = !patching; + }; + + const togglePresence = () => { + presence = !presence; + };
+
+ Discord Presence + Patching +