Skip to content

Commit 75c4091

Browse files
authored
Merge pull request #111 from xDalete/master
Bug fixes + Delete song data option
2 parents 50a1389 + 7b6facd commit 75c4091

File tree

24 files changed

+152
-91
lines changed

24 files changed

+152
-91
lines changed

src/main/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
2-
import { Router } from "@main/lib/route-pass/Router";
32
import createMenu from "@main/lib/window/menu";
43
import trackBounds, { getBounds, wasMaximized } from "@main/lib/window/resizer";
54
import { main } from "@main/main";
@@ -60,14 +59,6 @@ async function createWindow() {
6059
window.focus();
6160
});
6261

63-
window.on("maximize", () => {
64-
Router.dispatch(window, "window::maximizeChange", true);
65-
});
66-
67-
window.on("unmaximize", () => {
68-
Router.dispatch(window, "window::maximizeChange", false);
69-
});
70-
7162
if (wasMaximized()) {
7263
window.maximize();
7364
}
@@ -76,7 +67,6 @@ async function createWindow() {
7667

7768
window.on("ready-to-show", async () => {
7869
window.show();
79-
await Router.dispatch(window, "changeScene", "main");
8070
});
8171

8272
// HMR for renderer base on electron-vite cli.

src/main/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function main(window: BrowserWindow) {
2323
if (osuSongsDir.isNone) {
2424
await configureOsuDir(window);
2525
} else {
26-
//todo check for updates in song files
26+
//TODO: check for updates in song files
2727
}
2828

2929
const songsArray = Object.values(Storage.getTable("songs").getStruct());

src/main/router/discord-router.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Client, SetActivity } from "@xhayper/discord-rpc";
33

44
const client = new Client({ clientId: "1292942523425099826" });
55

6-
client.on("ready", () => client.user?.setActivity(defaultPresence));
6+
client.on("ready", () =>
7+
client.user?.setActivity(defaultPresence).catch(catchDiscordActivityError),
8+
);
79

8-
client.login();
10+
client.login().catch(catchDiscordActivityError);
911

1012
const defaultPresence: SetActivity = {
1113
details: "Idle",
@@ -44,7 +46,7 @@ Router.respond("discord::play", async (_evt, song, length, position) => {
4446
});
4547
}
4648

47-
client.user?.setActivity(presence);
49+
client.user?.setActivity(presence).catch(catchDiscordActivityError);
4850
});
4951

5052
Router.respond("discord::pause", async (_evt, song) => {
@@ -73,5 +75,9 @@ Router.respond("discord::pause", async (_evt, song) => {
7375
});
7476
}
7577

76-
client.user?.setActivity(presence);
78+
client.user?.setActivity(presence).catch(catchDiscordActivityError);
7779
});
80+
81+
function catchDiscordActivityError(err: unknown) {
82+
console.error("Discord activity error:\n", err);
83+
}

src/main/router/queue-router.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let lastPayload: QueueCreatePayload | undefined;
2929
Router.respond("queue::create", async (_evt, payload) => {
3030
if (comparePayload(payload, lastPayload)) {
3131
// Payload is practically same. Find start song and play queue from there
32-
const newIndex = queue.findIndex((s) => s.path === payload.startSong);
32+
const newIndex = queue.findIndex((s) => s.osuFile === payload.startSong);
3333

3434
if (newIndex === -1 || newIndex === index) {
3535
return;
@@ -58,7 +58,7 @@ Router.respond("queue::create", async (_evt, payload) => {
5858
}
5959

6060
// Set playing index
61-
const songIndex = queue.findIndex((s) => s.path === payload.startSong);
61+
const songIndex = queue.findIndex((s) => s.osuFile === payload.startSong);
6262

6363
if (songIndex !== -1) {
6464
index = songIndex;
@@ -72,7 +72,7 @@ Router.respond("queue::create", async (_evt, payload) => {
7272

7373
function getIndexes(view: QueueView): SongIndex[] {
7474
if (view.playlists !== undefined) {
75-
//todo implement multi playlist playback
75+
//TODO: implement multi playlist playback
7676
return [];
7777
}
7878

@@ -86,7 +86,7 @@ function getIndexes(view: QueueView): SongIndex[] {
8686
}
8787

8888
if (view.playlist) {
89-
//todo get playlist
89+
//TODO: get playlist
9090
return [];
9191
}
9292

@@ -167,11 +167,11 @@ Router.respond("queue::shuffle", async () => {
167167
return;
168168
}
169169

170-
const current = queue[index].path;
170+
const current = queue[index].osuFile;
171171
shuffle(queue);
172172

173173
for (let i = 0; i < queue.length; i++) {
174-
if (queue[i].path !== current) {
174+
if (queue[i].osuFile !== current) {
175175
continue;
176176
}
177177

@@ -193,7 +193,7 @@ Router.respond("queue::shuffle", async () => {
193193

194194
Router.respond("queue::place", (_evt, what, after) => {
195195
// Find index of subject
196-
const whatIndex = queue.findIndex((s) => s.path === what);
196+
const whatIndex = queue.findIndex((s) => s.osuFile === what);
197197

198198
if (whatIndex === -1) {
199199
return;
@@ -220,7 +220,7 @@ Router.respond("queue::place", (_evt, what, after) => {
220220
return;
221221
}
222222

223-
const afterIndex = queue.findIndex((s) => s.path === after);
223+
const afterIndex = queue.findIndex((s) => s.osuFile === after);
224224

225225
if (afterIndex === -1) {
226226
// After index was not found... put subject back
@@ -249,7 +249,7 @@ Router.respond("queue::place", (_evt, what, after) => {
249249

250250
Router.respond("queue::play", async (_evt, song) => {
251251
// Point currently playing index to given song
252-
const newIndex = queue.findIndex((s) => s.path === song);
252+
const newIndex = queue.findIndex((s) => s.osuFile === song);
253253

254254
if (newIndex === -1 || newIndex === index) {
255255
return;
@@ -264,7 +264,7 @@ Router.respond("queue::playNext", async (_evt, song) => {
264264
return;
265265
}
266266

267-
const songIndex = queue.findIndex((s) => s.path === song);
267+
const songIndex = queue.findIndex((s) => s.osuFile === song);
268268

269269
if (songIndex === index) {
270270
return;
@@ -297,7 +297,7 @@ Router.respond("queue::removeSong", async (_evt, what) => {
297297
return;
298298
}
299299

300-
const whatIndex = queue.findIndex((s) => s.path === what);
300+
const whatIndex = queue.findIndex((s) => s.osuFile === what);
301301

302302
if (whatIndex === -1) {
303303
return;

src/main/router/resource-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Router.respond("resource::getPath", (_evt, path) => {
1717
return fail("Could not provide absolute path because osu! Songs folder is undefined.");
1818
}
1919

20-
// todo User may have spaces in osuDir if they are not using default path. Ensure that the whole path is valid URL
20+
//TODO: User may have spaces in osuDir if they are not using default path. Ensure that the whole path is valid URL
2121
return ok(pathToFileURL(path).href);
2222
});
2323

src/main/router/settings-router.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Router } from "@main/lib/route-pass/Router";
22
import { Storage } from "@main/lib/storage/Storage";
3+
import { app } from "electron";
34
import os from "os";
45

56
Router.respond("settings::get", (_evt, key) => {
@@ -10,6 +11,19 @@ Router.respond("settings::write", (_evt, key, value) => {
1011
Storage.getTable("settings").write(key, value);
1112
});
1213

14+
Router.respond("settings::DeleteSongData", () => {
15+
Storage.getTable("settings").delete("osuSongsDir");
16+
Storage.removeTable("songs");
17+
Storage.removeTable("audio");
18+
Storage.removeTable("images");
19+
Storage.removeTable("system");
20+
});
21+
1322
Router.respond("os::platform", () => {
1423
return os.platform();
1524
});
25+
26+
Router.respond("app::restart", () => {
27+
app.relaunch();
28+
app.quit();
29+
});

src/renderer/src/components/button/Button.tsx

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
import { cva, type VariantProps } from "class-variance-authority";
22
import { Component, JSX, splitProps } from "solid-js";
33

4-
const buttonStyles = cva(["rounded-lg transition-colors duration-200 ease font-medium"], {
5-
variants: {
6-
variant: {
7-
primary: "bg-text text-thick-material hover:bg-text/80",
8-
secondary: "bg-surface text-text hover:bg-surface/40 border-stroke border border-solid",
9-
outlined: "bg-transparent border-stroke text-text hover:bg-surface border border-solid",
10-
ghost: "border-transparent hover:bg-surface",
11-
link: "bg-transparent text-text hover:underline text-decoration-2 underline-offset-2",
4+
const buttonStyles = cva(
5+
["rounded-lg transition-colors duration-200 ease font-medium cursor-pointer"],
6+
{
7+
variants: {
8+
variant: {
9+
primary: "bg-text text-thick-material hover:bg-text/80",
10+
secondary: "bg-surface text-text hover:bg-surface/40 border-stroke border border-solid",
11+
outlined: "bg-transparent border-stroke text-text hover:bg-surface border border-solid",
12+
ghost: "border-transparent hover:bg-surface",
13+
link: "bg-transparent text-text hover:underline text-decoration-2 underline-offset-2",
14+
"danger-outlined":
15+
"bg-transparent text-danger border border-solid border-danger hover:text-text hover:bg-danger",
16+
},
17+
size: {
18+
medium: "px-4 py-2",
19+
large: "px-7 py-2.5",
20+
icon: "grid place-items-center aspect-square size-9 p-1 -m-2",
21+
square: "grid place-items-center aspect-square h-10",
22+
},
23+
disabled: {
24+
true: "opacity-50 !cursor-default",
25+
false: "",
26+
},
1227
},
13-
size: {
14-
medium: "px-4 py-2",
15-
large: "px-7 py-2.5",
16-
icon: "grid place-items-center aspect-square size-9 p-1 -m-2",
17-
square: "grid place-items-center aspect-square h-10",
28+
defaultVariants: {
29+
variant: "primary",
30+
size: "medium",
1831
},
1932
},
20-
defaultVariants: {
21-
variant: "primary",
22-
size: "medium",
23-
},
24-
});
33+
);
2534

2635
type ButtonProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<typeof buttonStyles>;
2736

@@ -30,7 +39,12 @@ const Button: Component<ButtonProps> = (props) => {
3039

3140
return (
3241
<button
33-
class={buttonStyles({ variant: local.variant, size: local.size, class: local.class })}
42+
class={buttonStyles({
43+
variant: local.variant,
44+
size: local.size,
45+
class: local.class,
46+
disabled: props.disabled,
47+
})}
3448
{...others}
3549
>
3650
{local.children}

src/renderer/src/components/dropdown-list/DropdownListItem.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RawList } from "../raw-list/RawList";
22
import { useDropdownList } from "./DropdownList";
3+
import { cn } from "@renderer/lib/css.utils";
34
import { Component, onCleanup } from "solid-js";
45
import { JSX } from "solid-js/jsx-runtime";
56

@@ -24,6 +25,7 @@ const DropdownListItem: Component<Props> = (props) => {
2425
}}
2526
{...attrs}
2627
{...props}
28+
class={cn("cursor-pointer", props.class)}
2729
/>
2830
);
2931
};

src/renderer/src/components/notice/NoticeAnimations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const noticeAnimations = {
2828
},
2929
animation: {
3030
"notice-slide-in": "notice-slide-in 300ms cubic-bezier(0.4, 0, 0.2, 1) forwards",
31-
// TODO: Make this 3000ms configurable
31+
//TODO: Make this 3000ms configurable
3232
"notice-progress": "notice-progress 3000ms linear",
3333
"notice-slide-out": "notice-slide-out 300ms cubic-bezier(0.4, 0, 0.2, 1) forwards",
3434
},

src/renderer/src/components/select/Select.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const SelectTrigger: ParentComponent<Props> = (_props) => {
2828
{...rest}
2929
class={cn(
3030
inputStyles({ variant: props.variant, class: props.class }),
31-
"box-border flex h-auto min-h-[42px] items-center justify-between gap-2 hover:bg-surface data-[open='true']:bg-surface",
31+
"box-border flex h-auto min-h-[42px] cursor-pointer items-center justify-between gap-2 hover:bg-surface data-[open='true']:bg-surface",
3232
)}
3333
>
3434
<span class="text-base leading-6">{props.children}</span>

0 commit comments

Comments
 (0)