fix autologin toasts
This commit is contained in:
parent
05866946a3
commit
d5b2b8012c
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,81 +15,117 @@
|
||||||
|
|
||||||
const processLogin = async () => {
|
const processLogin = async () => {
|
||||||
loading = true;
|
loading = true;
|
||||||
window.addEventListener(
|
const loginPromise = new Promise<void>((res, rej) => {
|
||||||
"login-result",
|
window.addEventListener(
|
||||||
(e) => {
|
"login-result",
|
||||||
const customEvent = e as CustomEvent;
|
(e) => {
|
||||||
const resultData = customEvent.detail;
|
const customEvent = e as CustomEvent;
|
||||||
const wasSuccessful = "user" in resultData;
|
const resultData = customEvent.detail;
|
||||||
|
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,
|
||||||
});
|
}); */
|
||||||
loading = false;
|
rej();
|
||||||
return;
|
loading = false;
|
||||||
}
|
return;
|
||||||
const userResult = resultData.user as User;
|
}
|
||||||
currentUser.set(userResult);
|
const userResult = resultData.user as User;
|
||||||
currentPage.set(Page.Launch);
|
currentUser.set(userResult);
|
||||||
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) {
|
|
||||||
currentPage.set(Page.Launch);
|
currentPage.set(Page.Launch);
|
||||||
toast.success(`Logged in as Guest`, {
|
res();
|
||||||
|
toast.success(`Welcome back, ${userResult.name}!`, {
|
||||||
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: 3000,
|
duration: 3000,
|
||||||
});
|
});
|
||||||
return;
|
},
|
||||||
}
|
{ once: true }
|
||||||
if (!wasSuccessful) {
|
);
|
||||||
loading = false;
|
window.dispatchEvent(
|
||||||
return;
|
new CustomEvent("login-attempt", {
|
||||||
}
|
detail: { username, password, saveCredentials },
|
||||||
const userResult = resultData.user as User;
|
})
|
||||||
currentUser.set(userResult);
|
);
|
||||||
currentPage.set(Page.Launch);
|
});
|
||||||
toast.success(`Welcome back, ${userResult.name}!`, {
|
toast.promise(
|
||||||
position: "bottom-center",
|
loginPromise,
|
||||||
className:
|
{
|
||||||
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
|
loading: "Logging in...",
|
||||||
duration: 3000,
|
success: "Successfully logged in!",
|
||||||
});
|
error: "Failed to login.",
|
||||||
loading = false;
|
|
||||||
},
|
},
|
||||||
{ 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<void>((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 = () => {
|
const proceedAsGuest = () => {
|
||||||
|
@ -103,10 +139,24 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!$startup) {
|
const shouldAutologin = async () => {
|
||||||
startup.set(true);
|
const shouldAutologin = await new Promise<boolean>((res) => {
|
||||||
tryAutoLogin();
|
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();
|
||||||
|
}
|
||||||
|
})();
|
||||||
</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"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user