settings now working
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
import { Page } from "./consts/pages";
|
||||
import Login from "./pages/Login.svelte";
|
||||
import Launch from "./pages/Launch.svelte";
|
||||
import { Toaster } from "svelte-french-toast";
|
||||
import toast, { Toaster } from "svelte-french-toast";
|
||||
import type { User } from "./types/user";
|
||||
import Settings from "./pages/Settings.svelte";
|
||||
|
||||
@@ -51,6 +51,40 @@
|
||||
const progress = (e as CustomEvent).detail.progress;
|
||||
launchPercentage.set(progress);
|
||||
});
|
||||
|
||||
window.addEventListener("alert", (e) => {
|
||||
console.log((e as CustomEvent).detail);
|
||||
const toastMessage = (e as CustomEvent).detail;
|
||||
switch (toastMessage.type) {
|
||||
case "success": {
|
||||
toast.success(toastMessage.message, {
|
||||
position: "bottom-center",
|
||||
className:
|
||||
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
|
||||
duration: 1500,
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "error": {
|
||||
toast.error(toastMessage.message, {
|
||||
position: "bottom-center",
|
||||
className:
|
||||
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
|
||||
duration: 1500,
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
toast(toastMessage.message, {
|
||||
icon: "ℹ",
|
||||
position: "bottom-center",
|
||||
className:
|
||||
"dark:!bg-gray-800 border-1 dark:!border-gray-700 dark:!text-gray-100",
|
||||
duration: 1500,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<Toaster></Toaster>
|
||||
|
@@ -38,7 +38,15 @@ const get = (
|
||||
return result ? result.val ?? undefined : undefined;
|
||||
};
|
||||
|
||||
const all = () => {
|
||||
const result = db.prepare(
|
||||
`SELECT configKey key, configValue val FROM config WHERE 1`,
|
||||
).all();
|
||||
return result ?? undefined;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
all,
|
||||
get,
|
||||
set,
|
||||
remove,
|
||||
|
@@ -3,6 +3,19 @@
|
||||
import { FolderSolid } from "flowbite-svelte-icons";
|
||||
import { currentPage } from "../storage/localStore";
|
||||
import { Page } from "../consts/pages";
|
||||
|
||||
let folderPath: string = "";
|
||||
|
||||
window.addEventListener("settings-result", (e) => {
|
||||
const settings: Record<string, string>[] = (e as CustomEvent).detail;
|
||||
const osuPath = settings.find((setting) => setting.key == "osuPath");
|
||||
folderPath = osuPath ? osuPath.val : "";
|
||||
});
|
||||
window.dispatchEvent(new CustomEvent("settings-get"));
|
||||
|
||||
const setFolderPath = () => {
|
||||
window.dispatchEvent(new CustomEvent("folder-set"));
|
||||
};
|
||||
</script>
|
||||
|
||||
<main
|
||||
@@ -15,9 +28,13 @@
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="Path to your osu! installation"
|
||||
value={folderPath}
|
||||
readonly
|
||||
/>
|
||||
<Button color="light" class="dark:active:!bg-gray-900"
|
||||
<Button
|
||||
color="light"
|
||||
class="dark:active:!bg-gray-900"
|
||||
on:click={setFolderPath}
|
||||
><FolderSolid
|
||||
size="sm"
|
||||
class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none"
|
||||
|
@@ -1,33 +0,0 @@
|
||||
import axios from "axios";
|
||||
import type { Error } from "../types/error";
|
||||
import type { User } from "../types/user";
|
||||
|
||||
const loginCheckEndpoint = "https://ez-pp.farm/login/check";
|
||||
let retries = 0;
|
||||
|
||||
export const performLogin = async (
|
||||
username: string,
|
||||
password: string,
|
||||
): Promise<Error | User> => {
|
||||
const fetchResult = await fetch("https://ez-pp.farm/login/check", {
|
||||
method: "POST",
|
||||
mode: "cors",
|
||||
body: JSON.stringify({ username, password }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (fetchResult.ok) {
|
||||
const result = await fetchResult.json();
|
||||
retries = 0;
|
||||
return result.user;
|
||||
} else {
|
||||
if (retries++ >= 5) {
|
||||
console.log("Login failed after 5 retries.");
|
||||
retries = 0;
|
||||
return { code: 403, message: "Login failed." } as Error;
|
||||
}
|
||||
return await performLogin(username, password);
|
||||
}
|
||||
};
|
@@ -1,3 +1,3 @@
|
||||
export const clamp = (val: number, min: number, max: number) => {
|
||||
return val <= min ? min : val >= max ? max : val;
|
||||
return Math.max(min, Math.min(val, max));
|
||||
};
|
||||
|
40
src/util/osuUtil.js
Normal file
40
src/util/osuUtil.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const ignoredOsuEntities = [
|
||||
"osu!auth.dll",
|
||||
];
|
||||
const osuEntities = [
|
||||
"avcodec-51.dll",
|
||||
"avformat-52.dll",
|
||||
"avutil-49.dll",
|
||||
"bass.dll",
|
||||
"bass_fx.dll",
|
||||
"collection.db",
|
||||
"d3dcompiler_47.dll",
|
||||
"libEGL.dll",
|
||||
"libGLESv2.dll",
|
||||
"Microsoft.Ink.dll",
|
||||
"OpenTK.dll",
|
||||
"osu!.cfg",
|
||||
"osu!.db",
|
||||
"osu!.exe",
|
||||
"osu!auth.dll",
|
||||
"osu!gameplay.dll",
|
||||
"osu!seasonal.dll",
|
||||
"osu!ui.dll",
|
||||
"presence.db",
|
||||
"pthreadGC2.dll",
|
||||
"scores.db",
|
||||
];
|
||||
|
||||
async function isValidOsuFolder(path) {
|
||||
const allFiles = await fs.promises.readdir(path);
|
||||
let matches = 0;
|
||||
for (const file of allFiles) {
|
||||
if (osuEntities.includes(file)) matches = matches + 1;
|
||||
}
|
||||
return (Math.round((matches / osuEntities.length) * 100) >= 60);
|
||||
}
|
||||
|
||||
module.exports = { isValidOsuFolder };
|
Reference in New Issue
Block a user