Skip to content

Commit

Permalink
SongDownloader - Fix issues with defaultDownloadPath & prompting
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Sep 11, 2024
1 parent 447d263 commit 3fd2cd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion plugins/SongDownloader/src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export const Settings = () => html`<div style="display: grid; grid-gap: 20px; ma
options=${validQualitiesSettings}
title="Download quality"
/>
<${TextInput} text=${settings.defaultDownloadPath} onText=${(text: string) => (settings.defaultDownloadPath = text)} title="Default save path" />
<${TextInput}
text=${settings.defaultDownloadPath}
onText=${(text: string) => {
settings.defaultDownloadPath = text;
if (text === "") settings.alwaysUseDefaultPath = false;
}}
title="Default save path"
/>
<${SwitchSetting}
checked=${settings.defaultDownloadPath !== "" && settings.alwaysUseDefaultPath}
onClick=${() => (settings.alwaysUseDefaultPath = !settings.alwaysUseDefaultPath)}
Expand Down
9 changes: 5 additions & 4 deletions plugins/SongDownloader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ ContextMenu.onOpen(async (contextSource, contextMenu, trackItems) => {

downloadButton.addEventListener("click", async () => {
if (context === undefined) return;
let folderPath = settings.defaultDownloadPath;
if (trackItems.length > 1 && (folderPath === "" || !settings.alwaysUseDefaultPath)) {
let folderPath;
if (settings.alwaysUseDefaultPath) folderPath = settings.defaultDownloadPath;
else if (trackItems.length > 1) {
updateMethods.set("Prompting for download folder...");
const dialogResult = await openDialog({ properties: ["openDirectory", "createDirectory"], defaultPath: folderPath });
if (dialogResult.canceled) return updateMethods.clear();
Expand All @@ -92,7 +93,7 @@ ContextMenu.onOpen(async (contextSource, contextMenu, trackItems) => {
updateMethods.prep();
for (const trackItem of trackItems) {
if (trackItem.id === undefined) continue;
await downloadTrack(trackItem, updateMethods, folderPath, trackItems.length > 1).catch(trace.msg.err.withContext("Error downloading track"));
await downloadTrack(trackItem, updateMethods, folderPath).catch(trace.msg.err.withContext("Error downloading track"));
}
updateMethods.clear();
});
Expand All @@ -115,7 +116,7 @@ const downloadTrack = async (trackItem: TrackItem, updateMethods: ButtonMethods,
const pathInfo = parseFileName(await metaTags, await playbackInfo);

pathInfo.basePath = folderPath;
if ((folderPath === undefined || !settings.alwaysUseDefaultPath) && !noTriggerDialog) {
if (folderPath === undefined) {
updateMethods.set("Prompting for download path...");
const fileName = pathInfo.fileName;
const dialogResult = await saveDialog({ defaultPath: `${folderPath ?? ""}${pathSeparator}${fileName}`, filters: [{ name: "", extensions: [fileName ?? "*"] }] });
Expand Down

0 comments on commit 3fd2cd8

Please sign in to comment.