fix autologin toasts
This commit is contained in:
		
							
								
								
									
										11
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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) => { |   ipcMain.handle("ezpplauncher:autologin", async (e) => { | ||||||
|     const hwid = getHwId(); |     const hwid = getHwId(); | ||||||
|     const username = config.get("username"); |     const username = config.get("username"); | ||||||
|  |     if (username == undefined) { | ||||||
|  |       return { code: 200, message: "No autologin" }; | ||||||
|  |     } | ||||||
|     const password = cryptUtil.decrypt(config.get("password"), hwid); |     const password = cryptUtil.decrypt(config.get("password"), hwid); | ||||||
|     const guest = config.get("guest"); |     const guest = config.get("guest"); | ||||||
|     if (guest) return { code: 200, message: "Login as guest", guest: true }; |     if (guest) return { code: 200, message: "Login as guest", guest: true }; | ||||||
| @@ -172,6 +181,8 @@ function registerIPCPipes() { | |||||||
|           }; |           }; | ||||||
|         } |         } | ||||||
|         return result; |         return result; | ||||||
|  |       } else { | ||||||
|  |         config.remove("password"); | ||||||
|       } |       } | ||||||
|       return { |       return { | ||||||
|         code: 500, |         code: 500, | ||||||
|   | |||||||
| @@ -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 () => { | window.addEventListener("autologin-attempt", async () => { | ||||||
|   const loginResult = await ipcRenderer.invoke("ezpplauncher:autologin"); |   const loginResult = await ipcRenderer.invoke("ezpplauncher:autologin"); | ||||||
|   window.dispatchEvent( |   window.dispatchEvent( | ||||||
|   | |||||||
| @@ -9,7 +9,6 @@ import image from "@rollup/plugin-image"; | |||||||
| import sveltePreprocess from "svelte-preprocess"; | import sveltePreprocess from "svelte-preprocess"; | ||||||
| import typescript from "@rollup/plugin-typescript"; | import typescript from "@rollup/plugin-typescript"; | ||||||
| import progress from "rollup-plugin-progress"; | import progress from "rollup-plugin-progress"; | ||||||
| import findUnused from "rollup-plugin-unused"; |  | ||||||
|  |  | ||||||
| const production = !process.env.ROLLUP_WATCH; | const production = !process.env.ROLLUP_WATCH; | ||||||
|  |  | ||||||
| @@ -48,8 +47,7 @@ export default { | |||||||
|     file: "public/build/bundle.js", |     file: "public/build/bundle.js", | ||||||
|   }, |   }, | ||||||
|   plugins: [ |   plugins: [ | ||||||
|     findUnused(), |     !production && progress({ clearLine: true }), | ||||||
|     progress({ clearLine: true }), |  | ||||||
|     svelte({ |     svelte({ | ||||||
|       preprocess: sveltePreprocess({ sourceMap: !production }), |       preprocess: sveltePreprocess({ sourceMap: !production }), | ||||||
|       compilerOptions: { |       compilerOptions: { | ||||||
| @@ -61,7 +59,7 @@ export default { | |||||||
|     // we'll extract any component CSS out into |     // we'll extract any component CSS out into | ||||||
|     // a separate file - better for performance |     // a separate file - better for performance | ||||||
|     css({ output: "bundle.css" }), |     css({ output: "bundle.css" }), | ||||||
|     postcss(), |     postcss({ sourceMap: "inline" }), | ||||||
|  |  | ||||||
|     // If you have external dependencies installed from |     // If you have external dependencies installed from | ||||||
|     // npm, you'll most likely need these plugins. In |     // npm, you'll most likely need these plugins. In | ||||||
|   | |||||||
| @@ -38,6 +38,12 @@ | |||||||
|     window.dispatchEvent(new CustomEvent("logout")); |     window.dispatchEvent(new CustomEvent("logout")); | ||||||
|     currentUser.set(undefined); |     currentUser.set(undefined); | ||||||
|     currentPage.set(Page.Login); |     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) => { |   window.addEventListener("launchStatusUpdate", (e) => { | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ | |||||||
|  |  | ||||||
|   const processLogin = async () => { |   const processLogin = async () => { | ||||||
|     loading = true; |     loading = true; | ||||||
|  |     const loginPromise = new Promise<void>((res, rej) => { | ||||||
|       window.addEventListener( |       window.addEventListener( | ||||||
|         "login-result", |         "login-result", | ||||||
|         (e) => { |         (e) => { | ||||||
| @@ -23,19 +24,21 @@ | |||||||
|           const wasSuccessful = "user" in resultData; |           const wasSuccessful = "user" in resultData; | ||||||
|  |  | ||||||
|           if (!wasSuccessful) { |           if (!wasSuccessful) { | ||||||
|           const errorResult = resultData as Error; |             /* const errorResult = resultData as Error; | ||||||
|             toast.error(errorResult.message, { |             toast.error(errorResult.message, { | ||||||
|               position: "bottom-center", |               position: "bottom-center", | ||||||
|               className: |               className: | ||||||
|                 "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", |                 "dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100", | ||||||
|               duration: 1500, |               duration: 1500, | ||||||
|           }); |             }); */ | ||||||
|  |             rej(); | ||||||
|             loading = false; |             loading = false; | ||||||
|             return; |             return; | ||||||
|           } |           } | ||||||
|           const userResult = resultData.user as User; |           const userResult = resultData.user as User; | ||||||
|           currentUser.set(userResult); |           currentUser.set(userResult); | ||||||
|           currentPage.set(Page.Launch); |           currentPage.set(Page.Launch); | ||||||
|  |           res(); | ||||||
|           toast.success(`Welcome back, ${userResult.name}!`, { |           toast.success(`Welcome back, ${userResult.name}!`, { | ||||||
|             position: "bottom-center", |             position: "bottom-center", | ||||||
|             className: |             className: | ||||||
| @@ -50,11 +53,26 @@ | |||||||
|           detail: { username, password, saveCredentials }, |           detail: { username, password, saveCredentials }, | ||||||
|         }) |         }) | ||||||
|       ); |       ); | ||||||
|  |     }); | ||||||
|  |     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, | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const tryAutoLogin = async () => { |   const tryAutoLogin = async () => { | ||||||
|     loading = true; |     loading = true; | ||||||
|     await new Promise((res) => setTimeout(res, 1500)); |     const loginPromise = new Promise<void>((res, rej) => { | ||||||
|       window.addEventListener( |       window.addEventListener( | ||||||
|         "login-result", |         "login-result", | ||||||
|         (e) => { |         (e) => { | ||||||
| @@ -64,6 +82,7 @@ | |||||||
|           const wasSuccessful = "user" in resultData; |           const wasSuccessful = "user" in resultData; | ||||||
|           if (isGuest) { |           if (isGuest) { | ||||||
|             currentPage.set(Page.Launch); |             currentPage.set(Page.Launch); | ||||||
|  |             res(); | ||||||
|             toast.success(`Logged in as Guest`, { |             toast.success(`Logged in as Guest`, { | ||||||
|               position: "bottom-center", |               position: "bottom-center", | ||||||
|               className: |               className: | ||||||
| @@ -74,11 +93,13 @@ | |||||||
|           } |           } | ||||||
|           if (!wasSuccessful) { |           if (!wasSuccessful) { | ||||||
|             loading = false; |             loading = false; | ||||||
|  |             rej(); | ||||||
|             return; |             return; | ||||||
|           } |           } | ||||||
|           const userResult = resultData.user as User; |           const userResult = resultData.user as User; | ||||||
|           currentUser.set(userResult); |           currentUser.set(userResult); | ||||||
|           currentPage.set(Page.Launch); |           currentPage.set(Page.Launch); | ||||||
|  |           res(); | ||||||
|           toast.success(`Welcome back, ${userResult.name}!`, { |           toast.success(`Welcome back, ${userResult.name}!`, { | ||||||
|             position: "bottom-center", |             position: "bottom-center", | ||||||
|             className: |             className: | ||||||
| @@ -90,6 +111,21 @@ | |||||||
|         { once: true } |         { once: true } | ||||||
|       ); |       ); | ||||||
|       window.dispatchEvent(new CustomEvent("autologin-attempt")); |       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, | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const proceedAsGuest = () => { |   const proceedAsGuest = () => { | ||||||
| @@ -103,10 +139,24 @@ | |||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   const shouldAutologin = async () => { | ||||||
|  |     const shouldAutologin = await new Promise<boolean>((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) { |     if (!$startup) { | ||||||
|       startup.set(true); |       startup.set(true); | ||||||
|     tryAutoLogin(); |       if (await shouldAutologin()) tryAutoLogin(); | ||||||
|     } |     } | ||||||
|  |   })(); | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <main | <main | ||||||
|   | |||||||
| @@ -1,11 +1,14 @@ | |||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
|   import { Button, ButtonGroup, Input } from "flowbite-svelte"; |   import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte"; | ||||||
|   import { FolderSolid } from "flowbite-svelte-icons"; |   import { FolderSolid } from "flowbite-svelte-icons"; | ||||||
|   import { currentPage } from "../storage/localStore"; |   import { currentPage } from "../storage/localStore"; | ||||||
|   import { Page } from "../consts/pages"; |   import { Page } from "../consts/pages"; | ||||||
|  |  | ||||||
|   let folderPath: string = ""; |   let folderPath: string = ""; | ||||||
|  |  | ||||||
|  |   let patching: boolean = true; | ||||||
|  |   let presence: boolean = true; | ||||||
|  |  | ||||||
|   window.addEventListener("settings-result", (e) => { |   window.addEventListener("settings-result", (e) => { | ||||||
|     const settings: Record<string, string>[] = (e as CustomEvent).detail; |     const settings: Record<string, string>[] = (e as CustomEvent).detail; | ||||||
|     const osuPath = settings.find((setting) => setting.key == "osuPath"); |     const osuPath = settings.find((setting) => setting.key == "osuPath"); | ||||||
| @@ -16,11 +19,27 @@ | |||||||
|   const setFolderPath = () => { |   const setFolderPath = () => { | ||||||
|     window.dispatchEvent(new CustomEvent("folder-set")); |     window.dispatchEvent(new CustomEvent("folder-set")); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|  |   const togglePatching = () => { | ||||||
|  |     patching = !patching; | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   const togglePresence = () => { | ||||||
|  |     presence = !presence; | ||||||
|  |   }; | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <main | <main | ||||||
|   class="h-[265px] my-auto flex flex-col justify-center items-center p-5 animate-fadeIn opacity-0" |   class="h-[265px] flex flex-col justify-start p-3 animate-fadeIn opacity-0" | ||||||
| > | > | ||||||
|  |   <div class="flex flex-col gap-2 p-3"> | ||||||
|  |     <Toggle class="w-fit" bind:checked={presence} on:click={togglePresence} | ||||||
|  |       >Discord Presence</Toggle | ||||||
|  |     > | ||||||
|  |     <Toggle class="w-fit" bind:checked={patching} on:click={togglePatching} | ||||||
|  |       >Patching</Toggle | ||||||
|  |     > | ||||||
|  |   </div> | ||||||
|   <div |   <div | ||||||
|     class="container flex flex-col items-center justify-center gap-5 rounded-lg p-3" |     class="container flex flex-col items-center justify-center gap-5 rounded-lg p-3" | ||||||
|   > |   > | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user