Skip to content

Commit

Permalink
fix(lyric): fix spicetify lyric bug
Browse files Browse the repository at this point in the history
resolve #678
  • Loading branch information
Su-Yong committed Feb 26, 2024
1 parent 5f76040 commit beecd44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common/provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type LyricMetadata = {
};

export type LyricData = LyricMetadata & {
lyric: Record<number, string[]>;
lyric?: Record<number, string[]>;
lyricRaw?: string;
register?: LyricRegister;
};
Expand Down
14 changes: 6 additions & 8 deletions renderer/components/PlayingInfoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ const PlayingInfoProvider = (props: { children: JSX.Element }) => {
}
case 'player': {
const lyricsFromPlayer = playerLyrics();
if (lyricsFromPlayer) {
lyricData = {
id: 'player',
title: data.title ?? '',
lyric: lyricsFromPlayer,
} satisfies LyricData;
}
lyricData = {
id: 'player',
title: data.title ?? '',
lyric: lyricsFromPlayer ?? undefined,
} satisfies LyricData;
break;
}
default: { // AUTO
Expand All @@ -212,7 +210,7 @@ const PlayingInfoProvider = (props: { children: JSX.Element }) => {

setIsMapped(!!mapperData);
setOriginalLyric(lyricData);
if (lyricData) {
if (lyricData?.lyric) {
const treeMap = new FlatMap<number, string[]>();

for (const key in lyricData.lyric) {
Expand Down
6 changes: 3 additions & 3 deletions renderer/hooks/useLyric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const useLyric = () => {
return last;
};

const lyric = createMemo(() => lastIter()?.second);
const index = createMemo(() => lastIter()?.first);
const lyric = createMemo(() => lastIter()?.value ? lastIter()?.second : null);
const index = createMemo(() => lastIter()?.value ? lastIter()?.first : null);

const nextLyricsIter = createMemo(() => {
let nextLyricLength = style().lyric.nextLyric;
Expand Down Expand Up @@ -94,7 +94,7 @@ const useLyric = () => {
});
const lyricRange = createMemo(() => {
const now = lastIter();
if (!now) return null;
if (!now || now.value === undefined) return null;

const prevIter = previousLyricsIter() ?? now;
const nextIter = nextLyricsIter() ?? now;
Expand Down

0 comments on commit beecd44

Please sign in to comment.