From b7171b099092fcd374bbd626ab630d36fab0deeb Mon Sep 17 00:00:00 2001 From: Pio Neto Date: Mon, 27 Jun 2022 13:49:20 -0300 Subject: [PATCH 01/12] Added dialog options to personalize the dialog screen. --- index.d.ts | 7 +++++++ index.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/index.d.ts b/index.d.ts index 4239a49..102ba1d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -111,6 +111,13 @@ declare namespace electronDl { @default false */ readonly overwrite?: boolean; + + /** + Save dialog options used to personalize the dialog. + + @defalt {} + */ + readonly dialogOptions?: any; } } diff --git a/index.js b/index.js index 0e8b8a6..9ff1279 100644 --- a/index.js +++ b/index.js @@ -86,6 +86,11 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { + const saveOptions = options.dialogOptions; + if (!saveOptions.defaultPath) { + saveOptions.defaultPath = filePath; + } + item.setSaveDialogOptions({defaultPath: filePath}); } else { item.setSavePath(filePath); From e5227d62ce16393abd137f6bfbad7e5e610111a0 Mon Sep 17 00:00:00 2001 From: Pio Neto Date: Mon, 27 Jun 2022 13:53:42 -0300 Subject: [PATCH 02/12] Missing line. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9ff1279..5a44063 100644 --- a/index.js +++ b/index.js @@ -91,7 +91,7 @@ function registerListener(session, options, callback = () => {}) { saveOptions.defaultPath = filePath; } - item.setSaveDialogOptions({defaultPath: filePath}); + item.setSaveDialogOptions(saveOptions); } else { item.setSavePath(filePath); } From 477e21373ab496751d88669deb6f127d8b632af6 Mon Sep 17 00:00:00 2001 From: Pio Neto Date: Tue, 28 Jun 2022 09:27:39 -0300 Subject: [PATCH 03/12] Fixed undefined saveOptions error. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5a44063..2ee01d2 100644 --- a/index.js +++ b/index.js @@ -86,7 +86,7 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { - const saveOptions = options.dialogOptions; + let saveOptions = options.dialogOptions ? options.dialogOptions : {}; if (!saveOptions.defaultPath) { saveOptions.defaultPath = filePath; } From 6877362d0ad35cc473beef516a345fdabca80205 Mon Sep 17 00:00:00 2001 From: Louis Lin Date: Thu, 10 Nov 2022 17:15:46 +1300 Subject: [PATCH 04/12] Added strongly typed options and docs --- index.d.ts | 6 ++++-- readme.md | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 102ba1d..4ef967e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -import {BrowserView, BrowserWindow, DownloadItem} from 'electron'; +import {BrowserView, BrowserWindow, DownloadItem, SaveDialogOptions} from 'electron'; declare namespace electronDl { interface Progress { @@ -115,9 +115,11 @@ declare namespace electronDl { /** Save dialog options used to personalize the dialog. + See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. + @defalt {} */ - readonly dialogOptions?: any; + readonly dialogOptions?: SaveDialogOptions; } } diff --git a/readme.md b/readme.md index 2d8af03..ba5bce7 100644 --- a/readme.md +++ b/readme.md @@ -206,6 +206,15 @@ Allow downloaded files to overwrite files with the same name in the directory th The default behavior is to append a number to the filename. +#### dialogOptions + +Type: `SaveDialogOptions`\ +Default: `{}` + +Save dialog options used to personalize the dialog. + +See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. + ## Development After making changes, run the automated tests: From 3be9ac61848fc16d47b3569af3a1ccb5ff857f76 Mon Sep 17 00:00:00 2001 From: Louis Lin Date: Thu, 10 Nov 2022 23:10:35 +1300 Subject: [PATCH 05/12] Fixed typo, indentation and improved doc --- index.d.ts | 8 ++++---- readme.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 45adf2e..e9a80c3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -120,12 +120,12 @@ declare namespace electronDl { readonly overwrite?: boolean; /** - Save dialog options used to personalize the dialog. + Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path. - See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. + See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. - @defalt {} - */ + @default {} + */ readonly dialogOptions?: SaveDialogOptions; } } diff --git a/readme.md b/readme.md index dcb27c3..01133ea 100644 --- a/readme.md +++ b/readme.md @@ -218,7 +218,7 @@ The default behavior is to append a number to the filename. Type: `SaveDialogOptions`\ Default: `{}` -Save dialog options used to personalize the dialog. +Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path. See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. From 5ebb7d2c603c0d8ac71fe2068a2375286232e0fa Mon Sep 17 00:00:00 2001 From: Louis Lin <46121192+louis-cf-lin@users.noreply.github.com> Date: Thu, 10 Nov 2022 23:12:52 +1300 Subject: [PATCH 06/12] Update readme.md Co-authored-by: Sindre Sorhus --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 01133ea..bc7b7e5 100644 --- a/readme.md +++ b/readme.md @@ -215,7 +215,7 @@ The default behavior is to append a number to the filename. #### dialogOptions -Type: `SaveDialogOptions`\ +Type: [`SaveDialogOptions`](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions)\ Default: `{}` Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path. From 864ff781b983ae007d7c16262b8552ad83c6614a Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 10 Nov 2022 18:40:39 +0700 Subject: [PATCH 07/12] Update readme.md --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index bc7b7e5..5a49a78 100644 --- a/readme.md +++ b/readme.md @@ -218,9 +218,9 @@ The default behavior is to append a number to the filename. Type: [`SaveDialogOptions`](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions)\ Default: `{}` -Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path. +Customize the save dialog. -See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. +If `defaultPath` is not explicity defined, a default value is assigned based on the file path. ## Development From 7cefb4531a2a8f5f82f16e8605bbd5b451a60cc4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 10 Nov 2022 18:41:12 +0700 Subject: [PATCH 08/12] Update index.d.ts --- index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index e9a80c3..66ffa8f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -120,9 +120,9 @@ declare namespace electronDl { readonly overwrite?: boolean; /** - Save dialog options used to personalize the dialog. If `defaultPath` is not explicity defined, a default value is assigned based on the file path. + Customize the save dialog. - See [`options` parameter](https://www.electronjs.org/docs/latest/api/download-item#downloaditemsetsavedialogoptionsoptions) for properties. + If `defaultPath` is not explicity defined, a default value is assigned based on the file path. @default {} */ From b8d41d4551a71b94a953b52da43568fd274df5ee Mon Sep 17 00:00:00 2001 From: Louis Lin Date: Fri, 11 Nov 2022 01:38:49 +1300 Subject: [PATCH 09/12] Destructure and assign default save options --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index 878558b..1fe82e9 100644 --- a/index.js +++ b/index.js @@ -87,11 +87,7 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { - let saveOptions = options.dialogOptions ? options.dialogOptions : {}; - if (!saveOptions.defaultPath) { - saveOptions.defaultPath = filePath; - } - + const saveOptions = { defaultPath: filePath, ...(options.dialogOptions ?? {}) }; item.setSaveDialogOptions(saveOptions); } else { item.setSavePath(filePath); From c3b81163033ca462ee10cf86e3e35bba9ed5fdff Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 10 Nov 2022 19:50:59 +0700 Subject: [PATCH 10/12] Update index.js --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 1fe82e9..cb0879f 100644 --- a/index.js +++ b/index.js @@ -87,8 +87,7 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { - const saveOptions = { defaultPath: filePath, ...(options.dialogOptions ?? {}) }; - item.setSaveDialogOptions(saveOptions); + item.setSaveDialogOptions({defaultPath: filePath, ...options.dialogOptions}); } else { item.setSavePath(filePath); } From beaedc8acd6cdf6d1a714a07698426c29bdb5a3d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 10 Nov 2022 19:50:59 +0700 Subject: [PATCH 11/12] Revert "Update index.js" This reverts commit c3b81163033ca462ee10cf86e3e35bba9ed5fdff. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index cb0879f..1fe82e9 100644 --- a/index.js +++ b/index.js @@ -87,7 +87,8 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { - item.setSaveDialogOptions({defaultPath: filePath, ...options.dialogOptions}); + const saveOptions = { defaultPath: filePath, ...(options.dialogOptions ?? {}) }; + item.setSaveDialogOptions(saveOptions); } else { item.setSavePath(filePath); } From e88530b47b251e47eabf5a92c60a008e362b0970 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 10 Nov 2022 19:50:59 +0700 Subject: [PATCH 12/12] Revert "Revert "Update index.js"" This reverts commit beaedc8acd6cdf6d1a714a07698426c29bdb5a3d. --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 1fe82e9..cb0879f 100644 --- a/index.js +++ b/index.js @@ -87,8 +87,7 @@ function registerListener(session, options, callback = () => {}) { const errorMessage = options.errorMessage || 'The download of {filename} was interrupted'; if (options.saveAs) { - const saveOptions = { defaultPath: filePath, ...(options.dialogOptions ?? {}) }; - item.setSaveDialogOptions(saveOptions); + item.setSaveDialogOptions({defaultPath: filePath, ...options.dialogOptions}); } else { item.setSavePath(filePath); }