From 4657aeca4589a23e12ced6a0f7f3d2ff622067ef Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Sun, 18 Feb 2024 11:58:26 +0900 Subject: [PATCH] fix: apply fix from eslint --- src/index.ts | 2 +- src/plugins/downloader/main/index.ts | 3 +- .../in-app-menu/renderer/MenuButton.tsx | 1 + src/plugins/in-app-menu/renderer/Panel.tsx | 1 + src/plugins/in-app-menu/renderer/TitleBar.tsx | 3 +- src/plugins/lyrics-genius/main.ts | 2 +- src/plugins/music-together/connection.ts | 2 +- src/plugins/scrobbler/index.ts | 2 +- src/plugins/scrobbler/main.ts | 4 +- src/plugins/skip-disliked-songs/index.ts | 38 +++++++----- src/providers/song-controls.ts | 58 ++++++++++--------- src/providers/song-info.ts | 2 +- 12 files changed, 67 insertions(+), 51 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4f9ae1ab..b015d077 100644 --- a/src/index.ts +++ b/src/index.ts @@ -586,7 +586,7 @@ app.whenReady().then(async () => { ); try { // Check if shortcut is registered and valid - const shortcutDetails = shell.readShortcutLink(shortcutPath); // Throw error if doesn't exist yet + const shortcutDetails = shell.readShortcutLink(shortcutPath); // Throw error if it doesn't exist yet if ( shortcutDetails.target !== appLocation || shortcutDetails.appUserModelId !== appID diff --git a/src/plugins/downloader/main/index.ts b/src/plugins/downloader/main/index.ts index 42629d97..17414e93 100644 --- a/src/plugins/downloader/main/index.ts +++ b/src/plugins/downloader/main/index.ts @@ -30,7 +30,7 @@ import { import { fetchFromGenius } from '@/plugins/lyrics-genius/main'; import { isEnabled } from '@/config/plugins'; -import { cleanupName, getImage, SongInfo } from '@/providers/song-info'; +import { cleanupName, getImage, MediaType, type SongInfo } from '@/providers/song-info'; import { getNetFetchAsFetch } from '@/plugins/utils/main'; import { cache } from '@/providers/decorators'; @@ -686,6 +686,7 @@ const getMetadata = (info: TrackInfo): CustomSongInfo => ({ ?.url, views: info.basic_info.view_count!, songDuration: info.basic_info.duration!, + mediaType: MediaType.Audio, }); // This is used to bypass age restrictions diff --git a/src/plugins/in-app-menu/renderer/MenuButton.tsx b/src/plugins/in-app-menu/renderer/MenuButton.tsx index 0556edc0..ae6ac9f8 100644 --- a/src/plugins/in-app-menu/renderer/MenuButton.tsx +++ b/src/plugins/in-app-menu/renderer/MenuButton.tsx @@ -1,5 +1,6 @@ import { JSX, splitProps } from 'solid-js'; import { css } from 'solid-styled-components'; + import { cache } from '@/providers/decorators'; const menuStyle = cache(() => css` diff --git a/src/plugins/in-app-menu/renderer/Panel.tsx b/src/plugins/in-app-menu/renderer/Panel.tsx index 32dd8931..9234095e 100644 --- a/src/plugins/in-app-menu/renderer/Panel.tsx +++ b/src/plugins/in-app-menu/renderer/Panel.tsx @@ -4,6 +4,7 @@ import { css } from 'solid-styled-components'; import { Transition } from 'solid-transition-group'; import { autoUpdate, flip, offset, OffsetOptions, size } from '@floating-ui/dom'; import { useFloating } from 'solid-floating-ui'; + import { cache } from '@/providers/decorators'; const panelStyle = cache(() => css` diff --git a/src/plugins/in-app-menu/renderer/TitleBar.tsx b/src/plugins/in-app-menu/renderer/TitleBar.tsx index 27605855..aad30828 100644 --- a/src/plugins/in-app-menu/renderer/TitleBar.tsx +++ b/src/plugins/in-app-menu/renderer/TitleBar.tsx @@ -9,9 +9,10 @@ import { PanelItem } from './PanelItem'; import { IconButton } from './IconButton'; import { WindowController } from './WindowController'; +import { cache } from '@/providers/decorators'; + import type { RendererContext } from '@/types/contexts'; import type { InAppMenuConfig } from '../constants'; -import { cache } from '@/providers/decorators'; const titleStyle = cache(() => css` -webkit-app-region: drag; diff --git a/src/plugins/lyrics-genius/main.ts b/src/plugins/lyrics-genius/main.ts index 13c69ae9..fd40c765 100644 --- a/src/plugins/lyrics-genius/main.ts +++ b/src/plugins/lyrics-genius/main.ts @@ -38,7 +38,7 @@ export const fetchFromGenius = async (metadata: SongInfo) => { const songArtist = `${cleanupName(metadata.artist)}`; let lyrics: string | null; - /* Uses Regex to test the title and artist first for said characters if romanization is enabled. Otherwise normal + /* Uses Regex to test the title and artist first for said characters if romanization is enabled. Otherwise, normal Genius Lyrics behavior is observed. */ let hasAsianChars = false; diff --git a/src/plugins/music-together/connection.ts b/src/plugins/music-together/connection.ts index 4248ab54..a03fc116 100644 --- a/src/plugins/music-together/connection.ts +++ b/src/plugins/music-together/connection.ts @@ -74,7 +74,7 @@ export class Connection { return conn; } - async disconnect() { + disconnect() { if (this._mode === 'disconnected') throw new Error('Already disconnected'); this._mode = 'disconnected'; diff --git a/src/plugins/scrobbler/index.ts b/src/plugins/scrobbler/index.ts index 6b0ae881..26b24657 100644 --- a/src/plugins/scrobbler/index.ts +++ b/src/plugins/scrobbler/index.ts @@ -76,7 +76,7 @@ export const defaultConfig: ScrobblerPluginConfig = { enabled: false, token: undefined, session_key: undefined, - api_root: 'http://ws.audioscrobbler.com/2.0/', + api_root: 'https://ws.audioscrobbler.com/2.0/', api_key: '04d76faaac8726e60988e14c105d421a', secret: 'a5d2a36fdf64819290f6982481eaffa2', }, diff --git a/src/plugins/scrobbler/main.ts b/src/plugins/scrobbler/main.ts index 96537356..e55e44a0 100644 --- a/src/plugins/scrobbler/main.ts +++ b/src/plugins/scrobbler/main.ts @@ -1,4 +1,4 @@ -import registerCallback, { type SongInfo } from '@/providers/song-info'; +import registerCallback, { MediaType, type SongInfo } from '@/providers/song-info'; import { createBackend } from '@/utils'; import { ScrobblerPluginConfig } from './index'; @@ -52,7 +52,7 @@ export const backend = createBackend<{ if (!songInfo.isPaused) { const configNonnull = this.config!; // Scrobblers normally have no trouble working with official music videos - if (!configNonnull.scrobble_other_media && (songInfo.mediaType !== 'AUDIO' && songInfo.mediaType !== 'ORIGINAL_MUSIC_VIDEO')) { + if (!configNonnull.scrobble_other_media && (songInfo.mediaType !== MediaType.Audio && songInfo.mediaType !== MediaType.OriginalMusicVideo)) { return; } diff --git a/src/plugins/skip-disliked-songs/index.ts b/src/plugins/skip-disliked-songs/index.ts index 3e3143cb..90ad9779 100644 --- a/src/plugins/skip-disliked-songs/index.ts +++ b/src/plugins/skip-disliked-songs/index.ts @@ -1,18 +1,37 @@ import { t } from '@/i18n'; import { createPlugin } from '@/utils'; -export default createPlugin({ +export default createPlugin< + unknown, + unknown, + { + observer?: MutationObserver; + waitForElem(selector: string): Promise; + start(): void; + stop(): void; + } +>({ name: () => t('plugins.skip-disliked-songs.name'), description: () => t('plugins.skip-disliked-songs.description'), restartNeeded: false, renderer: { - observer: null as MutationObserver | null, + waitForElem(selector: string) { + return new Promise((resolve) => { + const interval = setInterval(() => { + const elem = document.querySelector(selector); + if (!elem) return; + + clearInterval(interval); + resolve(elem); + }); + }); + }, start() { this.waitForElem('#like-button-renderer').then((likeBtn) => { this.observer = new MutationObserver(() => { if (likeBtn?.getAttribute('like-status') == 'DISLIKE') { document - .querySelector('tp-yt-paper-icon-button.next-button') + .querySelector('tp-yt-paper-icon-button.next-button') ?.click(); } }); @@ -26,16 +45,5 @@ export default createPlugin({ stop() { this.observer?.disconnect(); }, - waitForElem(selector) { - return new Promise((resolve) => { - const interval = setInterval(() => { - const elem = document.querySelector(selector); - if (!elem) return; - - clearInterval(interval); - resolve(elem); - }); - }); - }, }, -}); \ No newline at end of file +}); diff --git a/src/providers/song-controls.ts b/src/providers/song-controls.ts index 3d1c7f61..a421031d 100644 --- a/src/providers/song-controls.ts +++ b/src/providers/song-controls.ts @@ -3,33 +3,37 @@ import { BrowserWindow, ipcMain } from 'electron'; export default (win: BrowserWindow) => { const commands = { - // Playback - previous: () => win.webContents.send('ytmd:previous-video'), - next: () => win.webContents.send('ytmd:next-video'), - playPause: () => win.webContents.send('ytmd:toggle-play'), - like: () => win.webContents.send('ytmd:update-like', 'LIKE'), - dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'), - go10sBack: () => win.webContents.send('ytmd:seek-by', -10), - go10sForward: () => win.webContents.send('ytmd:seek-by', 10), - go1sBack: () => win.webContents.send('ytmd:seek-by', -1), - go1sForward: () => win.webContents.send('ytmd:seek-by', 1), - shuffle: () => win.webContents.send('ytmd:shuffle'), - switchRepeat: (n = 1) => win.webContents.send('ytmd:switch-repeat', n), - // General - volumeMinus10: () => { - ipcMain.once('ytmd:get-volume-return', (_, volume) => { - win.webContents.send('ytmd:update-volume', volume - 10); - }); - win.webContents.send('ytmd:get-volume'); - }, - volumePlus10: () => { - ipcMain.once('ytmd:get-volume-return', (_, volume) => { - win.webContents.send('ytmd:update-volume', volume + 10); - }); - win.webContents.send('ytmd:get-volume'); - }, - fullscreen: () => win.webContents.send('ytmd:toggle-fullscreen'), - muteUnmute: () => win.webContents.send('ytmd:toggle-mute'), + // Playback + previous: () => win.webContents.send('ytmd:previous-video'), + next: () => win.webContents.send('ytmd:next-video'), + playPause: () => win.webContents.send('ytmd:toggle-play'), + like: () => win.webContents.send('ytmd:update-like', 'LIKE'), + dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'), + go10sBack: () => win.webContents.send('ytmd:seek-by', -10), + go10sForward: () => win.webContents.send('ytmd:seek-by', 10), + go1sBack: () => win.webContents.send('ytmd:seek-by', -1), + go1sForward: () => win.webContents.send('ytmd:seek-by', 1), + shuffle: () => win.webContents.send('ytmd:shuffle'), + switchRepeat: (n = 1) => win.webContents.send('ytmd:switch-repeat', n), + // General + volumeMinus10: () => { + ipcMain.once('ytmd:get-volume-return', (_, volume) => { + win.webContents.send('ytmd:update-volume', volume - 10); + }); + win.webContents.send('ytmd:get-volume'); + }, + volumePlus10: () => { + ipcMain.once('ytmd:get-volume-return', (_, volume) => { + win.webContents.send('ytmd:update-volume', volume + 10); + }); + win.webContents.send('ytmd:get-volume'); + }, + fullscreen: () => win.webContents.send('ytmd:toggle-fullscreen'), + muteUnmute: () => win.webContents.send('ytmd:toggle-mute'), + search: () => win.webContents.sendInputEvent({ + type: 'keyDown', + keyCode: '/', + }), }; return { ...commands, diff --git a/src/providers/song-info.ts b/src/providers/song-info.ts index 8b356410..79a6a2bf 100644 --- a/src/providers/song-info.ts +++ b/src/providers/song-info.ts @@ -7,7 +7,7 @@ import config from '@/config'; import type { GetPlayerResponse } from '@/types/get-player-response'; -enum MediaType { +export enum MediaType { /** * Audio uploaded by the original artist */