Skip to content

Commit

Permalink
Merge pull request #4 from Plextora/master
Browse files Browse the repository at this point in the history
Added an "Autodetect folder" button for first run library screen
  • Loading branch information
CaptSiro authored Sep 30, 2024
2 parents 1e889fc + 92ca7eb commit 03d5c9a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/RequestAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type RequestAPI = {
"queue::shuffle": () => void,

"dir::select": () => Optional<string>,
"dir::autoGetOsuSongsDir": () => Optional<string>,
"dir::submit": (dir: string) => void,

"error::dismissed": () => void,
Expand Down
9 changes: 9 additions & 0 deletions src/main/router/dir-router.ts
Original file line number Diff line number Diff line change
@@ -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";



Expand All @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions src/renderer/src/components/scenes/DirSelectScene.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createSignal } from 'solid-js';
import '../../assets/css/scenes/dir-select.css';



export default function DirSelectScene() {
const [dir, setDir] = createSignal("")

Expand All @@ -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());
}
Expand All @@ -27,6 +34,7 @@ export default function DirSelectScene() {
{dir() === "" ? "[No folder selected]" : dir()}
</code>
<div class="row">
<button onClick={autodetectDir}>Autodetect folder</button>
<button onClick={selectDir}>Select folder</button>
<button onClick={submitDir}>Submit</button>
</div>
Expand Down

0 comments on commit 03d5c9a

Please sign in to comment.