From 92ca7ebaeb4ba7abd8b10af4f7ffde8d17fb72ec Mon Sep 17 00:00:00 2001 From: Plextora <71889427+Plextora@users.noreply.github.com> Date: Sun, 29 Sep 2024 18:00:16 -0400 Subject: [PATCH] Added an "Autodetect folder" button for first run library screen --- src/RequestAPI.d.ts | 1 + src/main/router/dir-router.ts | 9 +++++++++ .../src/components/scenes/DirSelectScene.tsx | 12 ++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/RequestAPI.d.ts b/src/RequestAPI.d.ts index 0a08c456..d67acaa4 100644 --- a/src/RequestAPI.d.ts +++ b/src/RequestAPI.d.ts @@ -36,6 +36,7 @@ export type RequestAPI = { "queue::shuffle": () => void, "dir::select": () => Optional, + "dir::autoGetOsuSongsDir": () => Optional, "dir::submit": (dir: string) => void, "error::dismissed": () => void, diff --git a/src/main/router/dir-router.ts b/src/main/router/dir-router.ts index 59420a59..5d160961 100644 --- a/src/main/router/dir-router.ts +++ b/src/main/router/dir-router.ts @@ -1,6 +1,7 @@ import { Router } from '../lib/route-pass/Router'; import { none, some } from '../lib/rust-like-utils-backend/Optional'; import { dialog } from 'electron'; +import path from "path"; @@ -19,6 +20,14 @@ Router.respond("dir::select", () => { return some(path[0]); }); +Router.respond("dir::autoGetOsuSongsDir", () => { + if (process.env.LOCALAPPDATA === undefined) { + return none(); + } + + return some(path.join(process.env.LOCALAPPDATA, "osu!", "Songs")); +}); + Router.respond("dir::submit", (_evt, dir) => { for (let i = 0; i < waitList.length; i++) { waitList[i](dir); diff --git a/src/renderer/src/components/scenes/DirSelectScene.tsx b/src/renderer/src/components/scenes/DirSelectScene.tsx index 3a97033d..a1e533b4 100644 --- a/src/renderer/src/components/scenes/DirSelectScene.tsx +++ b/src/renderer/src/components/scenes/DirSelectScene.tsx @@ -1,8 +1,6 @@ import { createSignal } from 'solid-js'; import '../../assets/css/scenes/dir-select.css'; - - export default function DirSelectScene() { const [dir, setDir] = createSignal("") @@ -15,6 +13,15 @@ export default function DirSelectScene() { setDir(opt.value); } + const autodetectDir = async () => { + const autoGetDir = await window.api.request("dir::autoGetOsuSongsDir"); + if (autoGetDir.isNone) { + return; + } + + setDir(autoGetDir.value); + } + const submitDir = async () => { await window.api.request("dir::submit", dir()); } @@ -27,6 +34,7 @@ export default function DirSelectScene() { {dir() === "" ? "[No folder selected]" : dir()}
+