EZPPLauncher/src/pages/Settings.svelte

93 lines
3.0 KiB
Svelte
Raw Normal View History

2024-01-11 14:56:02 +00:00
<script lang="ts">
2024-01-19 14:04:58 +00:00
import { Button, ButtonGroup, Input, Toggle } from "flowbite-svelte";
import { FileSearchSolid, FolderSolid } from "flowbite-svelte-icons";
2024-04-15 11:07:40 +00:00
import { patch, presence, logging } from "./../storage/localStore";
2024-01-12 13:19:00 +00:00
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");
2024-01-19 14:04:58 +00:00
const settingPatch = settings.find((setting) => setting.key == "patch");
const settingPresence = settings.find(
(setting) => setting.key == "presence"
);
2024-04-15 11:07:40 +00:00
const settingLogging = settings.find((setting) => setting.key == "logging");
2024-01-19 14:04:58 +00:00
patch.set(settingPatch ? settingPatch.val == "true" : true);
presence.set(settingPresence ? settingPresence.val == "true" : true);
2024-04-15 11:07:40 +00:00
logging.set(settingLogging ? settingLogging.val == "true" : false);
2024-01-12 13:19:00 +00:00
folderPath = osuPath ? osuPath.val : "";
});
window.dispatchEvent(new CustomEvent("settings-get"));
const setFolderPath = () => {
window.dispatchEvent(new CustomEvent("folder-set"));
};
2024-01-18 13:10:47 +00:00
const detectFolderPath = () => {
window.dispatchEvent(new CustomEvent("folder-auto"));
};
2024-01-18 13:10:47 +00:00
const togglePatching = () => {
2024-01-18 18:47:56 +00:00
patch.set(!$patch);
2024-01-19 14:04:58 +00:00
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { patch: $patch } })
);
2024-01-18 13:10:47 +00:00
};
const togglePresence = () => {
2024-01-18 18:47:56 +00:00
presence.set(!$presence);
2024-01-19 14:04:58 +00:00
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { presence: $presence } })
);
2024-01-18 13:10:47 +00:00
};
2024-04-15 11:07:40 +00:00
const toggleLogging = () => {
logging.set(!$logging);
window.dispatchEvent(
new CustomEvent("setting-update", { detail: { logging: $logging } })
);
};
2024-01-11 14:56:02 +00:00
</script>
<main
2024-01-18 13:10:47 +00:00
class="h-[265px] flex flex-col justify-start p-3 animate-fadeIn opacity-0"
2024-01-11 14:56:02 +00:00
>
<div
class="container flex flex-col items-center justify-center gap-5 rounded-lg p-3"
>
<ButtonGroup class="w-full">
2024-01-11 15:09:38 +00:00
<Input
type="text"
id="oip"
2024-01-11 15:09:38 +00:00
placeholder="Path to your osu! installation"
2024-01-12 13:19:00 +00:00
value={folderPath}
2024-01-11 15:09:38 +00:00
readonly
/>
2024-01-25 09:23:03 +00:00
<Button color="light" on:click={detectFolderPath}>
<FileSearchSolid
2024-01-11 14:56:02 +00:00
size="sm"
class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none"
/>
</Button>
2024-01-25 09:23:03 +00:00
<Button color="light" class="active:!rounded-lg" on:click={setFolderPath}>
<FolderSolid
size="sm"
class="dark:text-gray-300 text-gray-500 outline-none border-none select-none pointer-events-none"
/>
</Button>
</ButtonGroup>
2024-01-11 14:56:02 +00:00
</div>
2024-04-15 11:07:40 +00:00
<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={$patch} on:click={togglePatching}
>Patching</Toggle
>
<Toggle class="w-fit" bind:checked={$logging} on:click={toggleLogging}
>Debug Logging</Toggle
>
</div>
2024-01-11 14:56:02 +00:00
</main>