Skip to content

Commit 82dd526

Browse files
committed
cleanup and fixing 🚀
1 parent 5696be7 commit 82dd526

File tree

9 files changed

+438
-205
lines changed

9 files changed

+438
-205
lines changed

‎main/background.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { parseFile } from "music-metadata";
3535
import fs from "fs";
3636
import { Client } from "@xhayper/discord-rpc";
3737
import { eq, sql } from "drizzle-orm";
38-
import { albums } from "./helpers/db/schema";
3938
import { initializeLastFmHandlers } from "./helpers/lastfm-service";
4039
import * as electronLog from "electron-log";
4140

‎main/helpers/create-window.ts‎

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -3,115 +3,8 @@ import {
33
BrowserWindow,
44
BrowserWindowConstructorOptions,
55
Rectangle,
6-
ipcMain,
7-
nativeImage,
86
} from "electron";
97
import Store from "electron-store";
10-
import path from "path";
11-
import { app } from "electron";
12-
13-
// Helper function to create media control icons using Node.js Buffer
14-
const createMediaIcon = (
15-
type: "prev" | "play" | "pause" | "next",
16-
): Electron.NativeImage => {
17-
// Create a simple binary representation of icons
18-
// Each icon is a 16x16 monochrome bitmap with white content on transparent background
19-
const width = 16;
20-
const height = 16;
21-
const bytesPerPixel = 4; // RGBA
22-
const stride = width * bytesPerPixel;
23-
const bufferSize = width * height * bytesPerPixel;
24-
25-
const buffer = Buffer.alloc(bufferSize, 0);
26-
27-
// White color (RGBA: 255, 255, 255, 255)
28-
const color = { r: 255, g: 255, b: 255, a: 255 };
29-
30-
// Helper function to set a pixel
31-
const setPixel = (x: number, y: number) => {
32-
if (x >= 0 && x < width && y >= 0 && y < height) {
33-
const offset = y * stride + x * bytesPerPixel;
34-
buffer[offset] = color.r;
35-
buffer[offset + 1] = color.g;
36-
buffer[offset + 2] = color.b;
37-
buffer[offset + 3] = color.a;
38-
}
39-
};
40-
41-
// Helper function to draw a filled rectangle
42-
const fillRect = (x1: number, y1: number, x2: number, y2: number) => {
43-
for (let y = y1; y <= y2; y++) {
44-
for (let x = x1; x <= x2; x++) {
45-
setPixel(x, y);
46-
}
47-
}
48-
};
49-
50-
// Helper function to draw a triangle
51-
const fillTriangle = (
52-
x1: number,
53-
y1: number,
54-
x2: number,
55-
y2: number,
56-
x3: number,
57-
y3: number,
58-
) => {
59-
// Simple triangle filling algorithm
60-
const minX = Math.min(x1, x2, x3);
61-
const maxX = Math.max(x1, x2, x3);
62-
const minY = Math.min(y1, y2, y3);
63-
const maxY = Math.max(y1, y2, y3);
64-
65-
for (let y = minY; y <= maxY; y++) {
66-
for (let x = minX; x <= maxX; x++) {
67-
// Check if point (x,y) is inside triangle using barycentric coordinates
68-
const d1 = (x - x2) * (y1 - y2) - (x1 - x2) * (y - y2);
69-
const d2 = (x - x3) * (y2 - y3) - (x2 - x3) * (y - y3);
70-
const d3 = (x - x1) * (y3 - y1) - (x3 - x1) * (y - y1);
71-
72-
const hasNeg = d1 < 0 || d2 < 0 || d3 < 0;
73-
const hasPos = d1 > 0 || d2 > 0 || d3 > 0;
74-
75-
if (!(hasNeg && hasPos)) {
76-
setPixel(x, y);
77-
}
78-
}
79-
}
80-
};
81-
82-
// Draw the icon based on type
83-
switch (type) {
84-
case "prev":
85-
// Previous icon - two triangles pointing left
86-
fillTriangle(10, 4, 10, 12, 5, 8); // First triangle
87-
fillTriangle(5, 4, 5, 12, 0, 8); // Second triangle
88-
break;
89-
90-
case "play":
91-
// Play icon - triangle pointing right
92-
fillTriangle(5, 4, 5, 12, 12, 8);
93-
break;
94-
95-
case "pause":
96-
// Pause icon - two rectangles
97-
fillRect(4, 4, 6, 12);
98-
fillRect(9, 4, 11, 12);
99-
break;
100-
101-
case "next":
102-
// Next icon - two triangles pointing right
103-
fillTriangle(5, 4, 5, 12, 10, 8); // First triangle
104-
fillTriangle(10, 4, 10, 12, 15, 8); // Second triangle
105-
break;
106-
}
107-
108-
// Create a native image from the buffer
109-
return nativeImage.createFromBuffer(buffer, {
110-
width: width,
111-
height: height,
112-
scaleFactor: 1.0,
113-
});
114-
};
1158

1169
export const createWindow = (
11710
windowName: string,
@@ -187,47 +80,6 @@ export const createWindow = (
18780
},
18881
});
18982

190-
const updateWindow = (isPlaying, artistName, songName) => {
191-
// Update window title based on playback status
192-
if (isPlaying && songName && artistName) {
193-
win.setTitle(`${songName} - ${artistName}`);
194-
} else {
195-
win.setTitle("Wora");
196-
}
197-
198-
if (process.platform !== "win32") return;
199-
200-
win.setThumbarButtons([
201-
{
202-
tooltip: "Previous",
203-
icon: createMediaIcon("prev"),
204-
click: () => {
205-
win.webContents.send("media-control", "previous");
206-
},
207-
},
208-
{
209-
tooltip: isPlaying ? "Pause" : "Play",
210-
icon: createMediaIcon(isPlaying ? "pause" : "play"),
211-
click: () => {
212-
win.webContents.send("media-control", "play-pause");
213-
},
214-
},
215-
{
216-
tooltip: "Next",
217-
icon: createMediaIcon("next"),
218-
click: () => {
219-
win.webContents.send("media-control", "next");
220-
},
221-
},
222-
]);
223-
};
224-
225-
updateWindow(false, null, null);
226-
227-
ipcMain.on("update-window", (event, [isPlaying, artistName, songName]) => {
228-
updateWindow(isPlaying, artistName, songName);
229-
});
230-
23183
win.on("close", saveState);
23284

23385
return win;

‎renderer/components/main/player.tsx‎

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ export const Player = () => {
663663
);
664664
}
665665

666-
// Queue/History display component (extracted for readability)
667666
const QueuePanel = () => (
668667
<div className="wora-border relative h-full w-full rounded-2xl bg-white/70 backdrop-blur-xl dark:bg-black/70">
669668
<div className="h-utility w-full max-w-3xl px-6 pt-6">
@@ -680,7 +679,6 @@ export const Player = () => {
680679
</TabsTrigger>
681680
</TabsList>
682681

683-
{/* Queue tab content */}
684682
<TabsContent
685683
value="queue"
686684
className="no-scrollbar grow overflow-y-auto pb-64"
@@ -720,7 +718,6 @@ export const Player = () => {
720718
</div>
721719
);
722720

723-
// Helper component for song items in queue/history
724721
const SongListItem = ({ song }) => (
725722
<li className="flex w-full items-center gap-4 overflow-hidden">
726723
<div className="relative min-h-14 min-w-14 overflow-hidden rounded-lg shadow-lg">
@@ -748,7 +745,6 @@ export const Player = () => {
748745

749746
return (
750747
<div>
751-
{/* Lyrics overlay */}
752748
<div className="absolute top-0 right-0 w-full">
753749
{showLyrics && lyrics && (
754750
<Lyrics
@@ -760,16 +756,13 @@ export const Player = () => {
760756
)}
761757
</div>
762758

763-
{/* Queue panel */}
764759
<div className="!absolute top-0 right-0 w-96">
765760
{showQueue && <QueuePanel />}
766761
</div>
767762

768-
{/* Main player UI */}
769763
<div className="wora-border h-28 w-full overflow-hidden rounded-2xl p-6">
770764
<div className="relative flex h-full w-full items-center">
771765
<TooltipProvider>
772-
{/* Left side - Song info */}
773766
<div className="absolute left-0 flex w-1/4 items-center justify-start gap-4 overflow-hidden">
774767
{song ? (
775768
<ContextMenu>
@@ -789,7 +782,6 @@ export const Player = () => {
789782
</Link>
790783
</ContextMenuTrigger>
791784

792-
{/* Song context menu */}
793785
<ContextMenuContent className="w-64">
794786
<Link href={`/albums/${song.album?.id}`}>
795787
<ContextMenuItem className="flex items-center gap-2">
@@ -829,7 +821,6 @@ export const Player = () => {
829821
</div>
830822
)}
831823

832-
{/* Song title and artist */}
833824
<div className="w-full">
834825
<p className="truncate text-sm font-medium">
835826
{song ? song.name : "Echoes of Emptiness"}
@@ -838,13 +829,6 @@ export const Player = () => {
838829
href={
839830
song ? `/artists/${encodeURIComponent(song.artist)}` : "#"
840831
}
841-
onClick={(e) => {
842-
if (!song) return;
843-
e.preventDefault();
844-
// Use router to navigate without stopping song playback
845-
const router = require("next/router").default;
846-
router.push(`/artists/${encodeURIComponent(song.artist)}`);
847-
}}
848832
>
849833
<p className="cursor-pointer truncate opacity-50 hover:underline hover:opacity-80">
850834
{song ? song.artist : "The Void Ensemble"}
@@ -853,11 +837,8 @@ export const Player = () => {
853837
</div>
854838
</div>
855839

856-
{/* Center - Playback controls */}
857840
<div className="absolute right-0 left-0 mx-auto flex h-full w-2/4 flex-col items-center justify-between gap-4">
858-
{/* Playback buttons */}
859841
<div className="flex h-full w-full items-center justify-center gap-8">
860-
{/* Shuffle button */}
861842
<Button
862843
variant="ghost"
863844
onClick={toggleShuffle}
@@ -877,7 +858,6 @@ export const Player = () => {
877858
)}
878859
</Button>
879860

880-
{/* Previous track button */}
881861
<Button variant="ghost" onClick={previousSong}>
882862
<IconPlayerSkipBack
883863
stroke={2}
@@ -886,7 +866,6 @@ export const Player = () => {
886866
/>
887867
</Button>
888868

889-
{/* Play/pause button */}
890869
<Button variant="ghost" onClick={handlePlayPause}>
891870
{!isPlaying ? (
892871
<IconPlayerPlay
@@ -901,15 +880,13 @@ export const Player = () => {
901880
)}
902881
</Button>
903882

904-
{/* Next track button */}
905883
<Button variant="ghost" onClick={nextSong}>
906884
<IconPlayerSkipForward
907885
stroke={2}
908886
className="h-4 w-4 fill-black dark:fill-white"
909887
/>
910888
</Button>
911889

912-
{/* Repeat button */}
913890
<Button
914891
variant="ghost"
915892
onClick={toggleRepeat}
@@ -929,24 +906,23 @@ export const Player = () => {
929906
)}
930907
</Button>
931908

932-
{/* Lossless indicator */}
933909
{metadata?.format?.lossless && (
934910
<div className="absolute left-36">
935911
<Tooltip delayDuration={0}>
936912
<TooltipTrigger>
937-
<IconRipple stroke={2} className="w-3.5" />
913+
<IconRipple
914+
stroke={2}
915+
className="w-3.5 cursor-pointer"
916+
/>
938917
</TooltipTrigger>
939918
<TooltipContent side="left" sideOffset={25}>
940-
<p>
941-
Lossless [{metadata.format.bitsPerSample}/
942-
{(metadata.format.sampleRate / 1000).toFixed(1)}kHz]
943-
</p>
919+
Lossless [{metadata.format.bitsPerSample}/
920+
{(metadata.format.sampleRate / 1000).toFixed(1)}kHz]
944921
</TooltipContent>
945922
</Tooltip>
946923
</div>
947924
)}
948925

949-
{/* Last.fm indicator - only show when enabled and active */}
950926
{lastFmSettings.enableLastFm &&
951927
lastFmSettings.lastFmSessionKey &&
952928
lastFmStatus.lastFmActive && (
@@ -984,7 +960,6 @@ export const Player = () => {
984960
</div>
985961
)}
986962

987-
{/* Favorite button */}
988963
<div className="absolute right-36">
989964
<Tooltip delayDuration={0}>
990965
<TooltipTrigger>
@@ -1011,7 +986,6 @@ export const Player = () => {
1011986
</div>
1012987
</div>
1013988

1014-
{/* Seek slider */}
1015989
<div className="relative flex h-full w-96 items-center px-4">
1016990
<p className="absolute -left-8">{convertTime(seekPosition)}</p>
1017991
<Slider
@@ -1026,9 +1000,7 @@ export const Player = () => {
10261000
</div>
10271001
</div>
10281002

1029-
{/* Right side - Volume and additional controls */}
10301003
<div className="absolute right-0 flex w-1/4 items-center justify-end gap-10">
1031-
{/* Volume controls */}
10321004
<div className="flex items-center gap-4">
10331005
<Button
10341006
variant="ghost"
@@ -1058,9 +1030,7 @@ export const Player = () => {
10581030
/>
10591031
</div>
10601032

1061-
{/* Additional controls */}
10621033
<div className="flex items-center gap-4">
1063-
{/* Lyrics button */}
10641034
{lyrics ? (
10651035
<Button variant="ghost" onClick={toggleLyrics}>
10661036
<IconMessage stroke={2} size={15} />
@@ -1073,7 +1043,6 @@ export const Player = () => {
10731043
/>
10741044
)}
10751045

1076-
{/* Track info dialog */}
10771046
<Dialog>
10781047
<DialogTrigger
10791048
className={
@@ -1177,7 +1146,6 @@ export const Player = () => {
11771146
)}
11781147
</Dialog>
11791148

1180-
{/* Queue button */}
11811149
<Button variant="ghost" onClick={toggleQueue}>
11821150
<IconList stroke={2} size={15} />
11831151
</Button>

0 commit comments

Comments
 (0)