Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoMadera committed Sep 5, 2023
1 parent 155fd73 commit 2f5d49a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
34 changes: 14 additions & 20 deletions hooks/useLyricsInPictureInPicture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function useLyricsInPictureInPicture({
]);

useEffect(() => {
if (!isPlaying || !currentlyPlayingDuration) {
if (!isPlaying || !currentlyPlayingDuration || !requestLyrics) {
return;
}
const minimumIntervalCheck = 200;
Expand Down Expand Up @@ -150,13 +150,13 @@ export function useLyricsInPictureInPicture({

function drawLoadingSpinner(rotation: number) {
if (!ctx) return;
ctx.clearRect(0, LYRICS_PIP_HEADER_HEIGH, canvasWidth, canvasHeight);
const [h, s] = hexToHsl(lyricsBackgroundColor ?? "", true) ?? [0, 0, 0];
const [h, s] = hexToHsl(lyricsBackgroundColor ?? "#ccacaa", true) ?? [
0, 0, 0,
];

for (let i = 0; i < numSegments; i++) {
const startAngle = i * segmentAngle + rotation;
const endAngle = startAngle + segmentAngle;

ctx.beginPath();
ctx.arc(centerX, centerY, radius, startAngle, endAngle);
ctx.lineWidth = lineWidth;
Expand All @@ -168,13 +168,9 @@ export function useLyricsInPictureInPicture({

const segmentColor = `hsl(${h}, ${s}%, ${adjustedLightness}%)`;
ctx.strokeStyle = segmentColor;
ctx.globalCompositeOperation = "source-over";
ctx.stroke();
}

ctx.globalCompositeOperation = "destination-over";
ctx.fillStyle = lyricsBackgroundColor ?? "#000";

ctx.fillRect(0, LYRICS_PIP_HEADER_HEIGH, canvasWidth, canvasHeight);
}

function animate() {
Expand All @@ -185,25 +181,23 @@ export function useLyricsInPictureInPicture({
}

if (!lyricsError && !lines && !spinnerFrame) {
ctx.fillStyle = "#fff";

animate();
return;
}

if (spinnerFrame && (lines || lyricsError)) {
cancelAnimationFrame(spinnerFrame);
setSpinnerFrame(null);
ctx.globalCompositeOperation = "destination-over";
ctx.fillStyle = lyricsBackgroundColor ?? "#000";

ctx.fillRect(
0,
0,
pictureInPictureCanvas.current.width,
pictureInPictureCanvas.current.height
);
}
ctx.globalCompositeOperation = "destination-over";
ctx.fillStyle = lyricsBackgroundColor ?? "#000";

ctx.fillRect(
0,
0,
pictureInPictureCanvas.current.width,
pictureInPictureCanvas.current.height
);
}, [
spinnerFrame,
isPictureInPictureLyircsCanvas,
Expand Down
1 change: 1 addition & 0 deletions utils/applyLyricLinePositionAndColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function applyLyricLinePositionAndColor(
const limit = LINE_HEIGHT + LYRICS_PIP_HEADER_HEIGH;
const isOutsideCanvas = lineY < limit || lineY > containerHeight + limit;
if (isOutsideCanvas) return;
ctx.globalCompositeOperation = "source-over";
ctx.fillText(line.text, LYRICS_PADDING_LEFT, lineY);
});
}

0 comments on commit 2f5d49a

Please sign in to comment.