From 8a89bbccf7b42ec40a2b1d9a8d81e7ebdb41711d Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 23 Oct 2023 00:19:01 +0900 Subject: [PATCH] fix: fixed bugs in downloader (#1342) --- src/config/plugins.ts | 22 +++++++++++++++++----- src/plugins/downloader/back.ts | 9 ++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/config/plugins.ts b/src/config/plugins.ts index f9ed8d64..c2357f6f 100644 --- a/src/config/plugins.ts +++ b/src/config/plugins.ts @@ -22,8 +22,20 @@ export function isEnabled(plugin: string) { return pluginConfig !== undefined && pluginConfig.enabled; } -export function setOptions(plugin: string, options: T) { +/** + * Set options for a plugin + * @param plugin Plugin name + * @param options Options to set + * @param exclude Options to exclude from the options object + */ +export function setOptions(plugin: string, options: T, exclude: string[] = ['enabled']) { const plugins = store.get('plugins') as Record; + // HACK: This is a workaround for preventing changed options from being overwritten + exclude.forEach((key) => { + if (Object.prototype.hasOwnProperty.call(options, key)) { + delete options[key as keyof T]; + } + }); store.set('plugins', { ...plugins, [plugin]: { @@ -33,8 +45,8 @@ export function setOptions(plugin: string, options: T) { }); } -export function setMenuOptions(plugin: string, options: T) { - setOptions(plugin, options); +export function setMenuOptions(plugin: string, options: T, exclude: string[] = ['enabled']) { + setOptions(plugin, options, exclude); if (store.get('options.restartOnConfigChanges')) { restart(); } @@ -45,11 +57,11 @@ export function getOptions(plugin: string): T { } export function enable(plugin: string) { - setMenuOptions(plugin, { enabled: true }); + setMenuOptions(plugin, { enabled: true }, []); } export function disable(plugin: string) { - setMenuOptions(plugin, { enabled: false }); + setMenuOptions(plugin, { enabled: false }, []); } export default { diff --git a/src/plugins/downloader/back.ts b/src/plugins/downloader/back.ts index fbd8a160..c50bad18 100644 --- a/src/plugins/downloader/back.ts +++ b/src/plugins/downloader/back.ts @@ -84,8 +84,8 @@ export const getCookieFromWindow = async (win: BrowserWindow) => { url: 'https://music.youtube.com', }) ) - .map((it) => it.name + '=' + it.value + ';') - .join(''); + .map((it) => it.name + '=' + it.value) + .join(';'); }; export default async (win_: BrowserWindow) => { @@ -450,12 +450,11 @@ export async function downloadPlaylist(givenUrl?: string | URL) { try { givenUrl = new URL(givenUrl ?? ''); } catch { - return; + givenUrl = new URL(win.webContents.getURL()); } const playlistId = getPlaylistID(givenUrl) || - getPlaylistID(new URL(win.webContents.getURL())) || getPlaylistID(new URL(playingUrl)); if (!playlistId) { @@ -604,7 +603,7 @@ function getFFmpegMetadataArgs(metadata: CustomSongInfo) { // Playlist radio modifier needs to be cut from playlist ID const INVALID_PLAYLIST_MODIFIER = 'RDAMPL'; -const getPlaylistID = (aURL: URL) => { +const getPlaylistID = (aURL?: URL): string | null | undefined => { const result = aURL?.searchParams.get('list') || aURL?.searchParams.get('playlist'); if (result?.startsWith(INVALID_PLAYLIST_MODIFIER)) {