mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-13 03:11:46 +00:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { dialog } from 'electron';
|
|
|
|
import { downloadPlaylist } from './main';
|
|
import { getFolder } from './main/utils';
|
|
import { DefaultPresetList } from './types';
|
|
|
|
import { t } from '@/i18n';
|
|
|
|
import type { MenuContext } from '@/types/contexts';
|
|
import type { MenuTemplate } from '@/menu';
|
|
|
|
import type { DownloaderPluginConfig } from './index';
|
|
|
|
export const onMenu = async ({
|
|
getConfig,
|
|
setConfig,
|
|
}: MenuContext<DownloaderPluginConfig>): Promise<MenuTemplate> => {
|
|
const config = await getConfig();
|
|
|
|
return [
|
|
{
|
|
label: t('plugins.downloader.menu.download-playlist'),
|
|
click: () => downloadPlaylist(),
|
|
},
|
|
{
|
|
label: t('plugins.downloader.menu.choose-download-folder'),
|
|
click() {
|
|
const result = dialog.showOpenDialogSync({
|
|
properties: ['openDirectory', 'createDirectory'],
|
|
defaultPath: getFolder(config.downloadFolder ?? ''),
|
|
});
|
|
if (result) {
|
|
setConfig({ downloadFolder: result[0] });
|
|
} // Else = user pressed cancel
|
|
},
|
|
},
|
|
{
|
|
label: t('plugins.downloader.menu.presets'),
|
|
submenu: Object.keys(DefaultPresetList).map((preset) => ({
|
|
label: preset,
|
|
type: 'radio',
|
|
checked: config.selectedPreset === preset,
|
|
click() {
|
|
setConfig({ selectedPreset: preset });
|
|
},
|
|
})),
|
|
},
|
|
{
|
|
label: t('plugins.downloader.menu.skip-existing'),
|
|
type: 'checkbox',
|
|
checked: config.skipExisting,
|
|
click(item) {
|
|
setConfig({ skipExisting: item.checked });
|
|
},
|
|
},
|
|
];
|
|
};
|