mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 11:51:47 +00:00
feat(downloader): New option to download on finish (#1964)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
import { dialog } from 'electron';
|
||||
import prompt from 'custom-electron-prompt';
|
||||
import { deepmerge } from 'deepmerge-ts';
|
||||
|
||||
import { downloadPlaylist } from './main';
|
||||
import { getFolder } from './main/utils';
|
||||
@ -6,11 +8,13 @@ import { DefaultPresetList } from './types';
|
||||
|
||||
import { t } from '@/i18n';
|
||||
|
||||
import promptOptions from '@/providers/prompt-options';
|
||||
|
||||
import { type DownloaderPluginConfig, defaultConfig } from './index';
|
||||
|
||||
import type { MenuContext } from '@/types/contexts';
|
||||
import type { MenuTemplate } from '@/menu';
|
||||
|
||||
import type { DownloaderPluginConfig } from './index';
|
||||
|
||||
export const onMenu = async ({
|
||||
getConfig,
|
||||
setConfig,
|
||||
@ -18,6 +22,142 @@ export const onMenu = async ({
|
||||
const config = await getConfig();
|
||||
|
||||
return [
|
||||
{
|
||||
label: t('plugins.downloader.menu.download-finish-settings.label'),
|
||||
type: 'submenu',
|
||||
submenu: [
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.submenu.enabled',
|
||||
),
|
||||
type: 'checkbox',
|
||||
checked: config.downloadOnFinish?.enabled ?? false,
|
||||
click(item) {
|
||||
setConfig({
|
||||
downloadOnFinish: {
|
||||
...deepmerge(defaultConfig.downloadOnFinish, config.downloadOnFinish)!,
|
||||
enabled: item.checked,
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'separator',
|
||||
},
|
||||
{
|
||||
label: t('plugins.downloader.menu.choose-download-folder'),
|
||||
click() {
|
||||
const result = dialog.showOpenDialogSync({
|
||||
properties: ['openDirectory', 'createDirectory'],
|
||||
defaultPath: getFolder(config.downloadOnFinish?.folder ?? config.downloadFolder),
|
||||
});
|
||||
if (result) {
|
||||
setConfig({
|
||||
downloadOnFinish: {
|
||||
...deepmerge(defaultConfig.downloadOnFinish, config.downloadOnFinish)!,
|
||||
folder: result[0],
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.submenu.mode',
|
||||
),
|
||||
type: 'submenu',
|
||||
submenu: [
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.submenu.seconds',
|
||||
),
|
||||
type: 'radio',
|
||||
checked: config.downloadOnFinish?.mode === 'seconds',
|
||||
click() {
|
||||
setConfig({
|
||||
downloadOnFinish: {
|
||||
...deepmerge(defaultConfig.downloadOnFinish, config.downloadOnFinish)!,
|
||||
mode: 'seconds',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.submenu.percent',
|
||||
),
|
||||
type: 'radio',
|
||||
checked: config.downloadOnFinish?.mode === 'percent',
|
||||
click() {
|
||||
setConfig({
|
||||
downloadOnFinish: {
|
||||
...deepmerge(defaultConfig.downloadOnFinish, config.downloadOnFinish)!,
|
||||
mode: 'percent',
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.submenu.advanced',
|
||||
),
|
||||
async click() {
|
||||
const res = await prompt({
|
||||
title: t(
|
||||
'plugins.downloader.menu.download-finish-settings.prompt.title',
|
||||
),
|
||||
type: 'multiInput',
|
||||
multiInputOptions: [
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.prompt.last-seconds',
|
||||
),
|
||||
inputAttrs: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
min: '0',
|
||||
step: '1',
|
||||
},
|
||||
value: config.downloadOnFinish?.seconds ?? defaultConfig.downloadOnFinish!.seconds,
|
||||
},
|
||||
{
|
||||
label: t(
|
||||
'plugins.downloader.menu.download-finish-settings.prompt.last-percent',
|
||||
),
|
||||
inputAttrs: {
|
||||
type: 'number',
|
||||
required: true,
|
||||
min: '1',
|
||||
max: '100',
|
||||
step: '1',
|
||||
},
|
||||
value: config.downloadOnFinish?.percent ?? defaultConfig.downloadOnFinish!.percent,
|
||||
},
|
||||
],
|
||||
...promptOptions(),
|
||||
height: 240,
|
||||
resizable: true,
|
||||
}).catch(console.error);
|
||||
|
||||
if (!res) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
setConfig({
|
||||
downloadOnFinish: {
|
||||
...deepmerge(defaultConfig.downloadOnFinish, config.downloadOnFinish)!,
|
||||
seconds: Number(res[0]),
|
||||
percent: Number(res[1]),
|
||||
},
|
||||
});
|
||||
return;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
label: t('plugins.downloader.menu.download-playlist'),
|
||||
click: () => downloadPlaylist(),
|
||||
|
||||
Reference in New Issue
Block a user