Skip to content

Commit 0802abb

Browse files
committed
synced-lyrics: use mdui for the picker
1 parent 217d4a2 commit 0802abb

File tree

5 files changed

+69
-106
lines changed

5 files changed

+69
-106
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@jellybrick/electron-better-web-request": "1.0.4",
8282
"@jellybrick/mpris-service": "2.1.5",
8383
"@jimp/plugin-color": "1.6.0",
84+
"@mdui/icons": "^1.0.3",
8485
"@skyra/jaro-winkler": "1.1.1",
8586
"@xhayper/discord-rpc": "1.3.0",
8687
"async-mutex": "0.5.0",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx

Lines changed: 42 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable stylistic/no-mixed-operators */
12
import {
23
createEffect,
34
createMemo,
@@ -8,13 +9,15 @@ import {
89
onCleanup,
910
onMount,
1011
type Setter,
12+
Show,
1113
Switch,
1214
} from 'solid-js';
1315

1416
import * as z from 'zod';
1517

1618
import {
1719
type ProviderName,
20+
ProviderNames,
1821
providerNames,
1922
ProviderNameSchema,
2023
type ProviderState,
@@ -23,7 +26,14 @@ import { currentLyrics, lyricsStore, setLyricsStore } from '../store';
2326
import { _ytAPI } from '../index';
2427
import { config } from '../renderer';
2528

26-
import type { YtIcons } from '@/types/icons';
29+
import '@mdui/icons/chevron-left.js';
30+
import '@mdui/icons/chevron-right.js';
31+
import '@mdui/icons/check-circle.js';
32+
import '@mdui/icons/warning.js';
33+
import '@mdui/icons/error.js';
34+
import '@mdui/icons/star.js';
35+
import '@mdui/icons/star-border.js';
36+
2737
import type { PlayerAPIEvents } from '@/types/player-api-events';
2838

2939
const LocalStorageSchema = z.object({
@@ -47,7 +57,8 @@ const shouldSwitchProvider = (providerData: ProviderState) => {
4757
const providerBias = (p: ProviderName) =>
4858
(lyricsStore.lyrics[p].state === 'done' ? 1 : -1) +
4959
(lyricsStore.lyrics[p].data?.lines?.length ? 2 : -1) +
50-
(lyricsStore.lyrics[p].data?.lines?.length && p === 'YTMusic' ? 1 : 0) +
60+
// eslint-disable-next-line prettier/prettier
61+
(lyricsStore.lyrics[p].data?.lines?.length && p === ProviderNames.YTMusic ? 1 : 0) +
5162
(lyricsStore.lyrics[p].data?.lyrics ? 1 : -1);
5263

5364
const pickBestProvider = () => {
@@ -60,7 +71,6 @@ const pickBestProvider = () => {
6071
}
6172

6273
const providers = Array.from(providerNames);
63-
6474
providers.sort((a, b) => providerBias(b) - providerBias(a));
6575

6676
return { provider: providers[0], force: false };
@@ -175,50 +185,16 @@ export const LyricsPicker = (props: {
175185
});
176186
};
177187

178-
const chevronLeft: YtIcons = 'yt-icons:chevron_left';
179-
const chevronRight: YtIcons = 'yt-icons:chevron_right';
180-
181-
const successIcon: YtIcons = 'yt-icons:check-circle';
182-
const errorIcon: YtIcons = 'yt-icons:error';
183-
const notFoundIcon: YtIcons = 'yt-icons:warning';
184-
185188
return (
186189
<div class="lyrics-picker" ref={props.setStickRef}>
187190
<div class="lyrics-picker-left">
188-
<yt-icon-button
189-
class="style-scope ytmusic-player-bar"
190-
icon={chevronLeft}
191-
onClick={previous}
192-
role={'button'}
193-
>
194-
<span class="yt-icon-shape style-scope yt-icon yt-spec-icon-shape">
195-
<div
196-
style={{
197-
'width': '100%',
198-
'height': '100%',
199-
'display': 'flex',
200-
'align-items': 'center',
201-
'fill': 'currentcolor',
202-
}}
203-
>
204-
<svg
205-
class="style-scope yt-icon"
206-
fill="#FFFFFF"
207-
height={'40px'}
208-
preserveAspectRatio="xMidYMid meet"
209-
viewBox="0 -960 960 960"
210-
width={'40px'}
211-
>
212-
<g class="style-scope yt-icon">
213-
<path
214-
class="style-scope yt-icon"
215-
d="M560.67-240 320-480.67l240.67-240.66L608-674 414.67-480.67 608-287.33 560.67-240Z"
216-
/>
217-
</g>
218-
</svg>
219-
</div>
220-
</span>
221-
</yt-icon-button>
191+
<mdui-button-icon>
192+
<mdui-icon-chevron-left
193+
onClick={previous}
194+
role="button"
195+
style={{ padding: '5px' }}
196+
/>
197+
</mdui-button-icon>
222198
</div>
223199

224200
<div class="lyrics-picker-content">
@@ -247,9 +223,8 @@ export const LyricsPicker = (props: {
247223
/>
248224
</Match>
249225
<Match when={currentLyrics().state === 'error'}>
250-
<yt-icon
251-
icon={errorIcon}
252-
style={{ padding: '5px', transform: 'scale(0.8)' }}
226+
<mdui-icon-error
227+
style={{ padding: '5px', scale: '0.8' }}
253228
tabindex="-1"
254229
/>
255230
</Match>
@@ -260,9 +235,8 @@ export const LyricsPicker = (props: {
260235
currentLyrics().data?.lyrics)
261236
}
262237
>
263-
<yt-icon
264-
icon={successIcon}
265-
style={{ padding: '5px', transform: 'scale(0.8)' }}
238+
<mdui-icon-check-circle
239+
style={{ padding: '5px', scale: '0.8' }}
266240
tabindex="-1"
267241
/>
268242
</Match>
@@ -273,9 +247,8 @@ export const LyricsPicker = (props: {
273247
!currentLyrics().data?.lyrics
274248
}
275249
>
276-
<yt-icon
277-
icon={notFoundIcon}
278-
style={{ padding: '5px', transform: 'scale(0.8)' }}
250+
<mdui-icon-warning
251+
style={{ padding: '5px', scale: '0.8' }}
279252
tabindex="-1"
280253
/>
281254
</Match>
@@ -284,20 +257,14 @@ export const LyricsPicker = (props: {
284257
class="description ytmusic-description-shelf-renderer"
285258
text={{ runs: [{ text: provider() }] }}
286259
/>
287-
<yt-icon
288-
icon={
289-
starredProvider() === provider()
290-
? 'yt-sys-icons:star-filled'
291-
: 'yt-sys-icons:star'
292-
}
293-
onClick={toggleStar}
294-
style={{
295-
padding: '5px',
296-
transform: 'scale(0.8)',
297-
cursor: 'pointer',
298-
}}
299-
tabindex="-1"
300-
/>
260+
<mdui-button-icon onClick={toggleStar} tabindex={-1}>
261+
<Show
262+
fallback={<mdui-icon-star-border />}
263+
when={starredProvider() === provider()}
264+
>
265+
<mdui-icon-star />
266+
</Show>
267+
</mdui-button-icon>
301268
</div>
302269
)}
303270
</Index>
@@ -318,41 +285,14 @@ export const LyricsPicker = (props: {
318285
</ul>
319286
</div>
320287

321-
<div class="lyrics-picker-right">
322-
<yt-icon-button
323-
class="style-scope ytmusic-player-bar"
324-
icon={chevronRight}
325-
onClick={next}
326-
role={'button'}
327-
>
328-
<span class="yt-icon-shape style-scope yt-icon yt-spec-icon-shape">
329-
<div
330-
style={{
331-
'width': '100%',
332-
'height': '100%',
333-
'display': 'flex',
334-
'align-items': 'center',
335-
'fill': 'currentcolor',
336-
}}
337-
>
338-
<svg
339-
class="style-scope yt-icon"
340-
fill="#FFFFFF"
341-
height={'40px'}
342-
preserveAspectRatio="xMidYMid meet"
343-
viewBox="0 -960 960 960"
344-
width={'40px'}
345-
>
346-
<g class="style-scope yt-icon">
347-
<path
348-
class="style-scope yt-icon"
349-
d="M521.33-480.67 328-674l47.33-47.33L616-480.67 375.33-240 328-287.33l193.33-193.34Z"
350-
/>
351-
</g>
352-
</svg>
353-
</div>
354-
</span>
355-
</yt-icon-button>
288+
<div class="lyrics-picker-left">
289+
<mdui-button-icon>
290+
<mdui-icon-chevron-right
291+
onClick={next}
292+
role="button"
293+
style={{ padding: '5px' }}
294+
/>
295+
</mdui-button-icon>
356296
</div>
357297
</div>
358298
);

src/renderer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import i18next from 'i18next';
22

3-
import 'mdui';
43
import { setTheme } from 'mdui/functions/setTheme.js';
5-
6-
setTheme('dark');
4+
import 'mdui/mdui.css';
5+
import 'mdui';
76

87
import { startingPages } from './providers/extracted-data';
98
import { setupSongInfo } from './providers/song-info-front';
@@ -30,6 +29,8 @@ import type { QueueResponse } from '@/types/youtube-music-desktop-internal';
3029
import type { YouTubeMusicAppElement } from '@/types/youtube-music-app-element';
3130
import type { SearchBoxElement } from '@/types/search-box-element';
3231

32+
setTheme('dark');
33+
3334
let api: (Element & YoutubePlayer) | null = null;
3435
let isPluginLoaded = false;
3536
let isApiLoaded = false;

src/yt-web-components.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ declare module 'solid-js' {
3939
key?: string;
4040
}
4141

42-
interface IntrinsicElements extends MDUIElements {
42+
type MduiIcons = Extract<
43+
keyof HTMLElementTagNameMap,
44+
`mdui-icon-${string}`
45+
>;
46+
47+
type MduiIconElements = {
48+
[k in MduiIcons]: ComponentProps<'div'>;
49+
};
50+
51+
interface IntrinsicElements extends MDUIElements, MduiIconElements {
4352
'center': ComponentProps<'div'>;
4453
'ytmd-trans': ComponentProps<'span'> & YtmdTransProps;
4554
'yt-formatted-string': ComponentProps<'span'> & YtFormattedStringProps;

0 commit comments

Comments
 (0)