Fix #499: Add options to control file download behavior (PR #526)

This commit is contained in:
Bob Roth 2018-01-26 08:59:58 -06:00 committed by Ronan Jouchet
parent 28dca8c647
commit cec9c4b819
5 changed files with 23 additions and 2 deletions

View File

@ -12,11 +12,12 @@ import inferFlash from './helpers/inferFlash';
const { isOSX } = helpers;
electronDownload();
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
const fileDownloadOptions = Object.assign({}, appArgs.fileDownloadOptions);
electronDownload(fileDownloadOptions);
if (appArgs.processEnvs) {
Object.keys(appArgs.processEnvs).forEach((key) => {
/* eslint-env node */

View File

@ -460,6 +460,20 @@ Example:
nativefier <your-geolocation-enabled-website> --processEnvs '{"GOOGLE_API_KEY": "<your-google-api-key>"}'
```
#### [file-download-options]
```
--file-download-options <json-string>
```
a JSON string of key/value pairs to be set as file download options. See [electron-dl](https://github.com/sindresorhus/electron-dl) for available options.
Example:
```bash
nativefier <your-website> --file-download-options '{"saveAs": true}'
```
## Programmatic API
You can use the Nativefier programmatic API as well.
@ -498,6 +512,9 @@ var options = {
honest: false,
zoom: 1.0,
singleInstance: false,
fileDownloadOptions: {
saveAs: true // always show "Save As" dialog
},
processEnvs: {
"GOOGLE_API_KEY": "<your-google-api-key>"
}

View File

@ -48,6 +48,7 @@ function selectAppArgs(options) {
win32metadata: options.win32metadata,
versionString: options.versionString,
processEnvs: options.processEnvs,
fileDownloadOptions: options.fileDownloadOptions,
tray: options.tray,
basicAuthUsername: options.basicAuthUsername,
basicAuthPassword: options.basicAuthPassword,

View File

@ -85,6 +85,7 @@ if (require.main === module) {
.option('--crash-reporter <value>', 'remote server URL to send crash reports')
.option('--single-instance', 'allow only a single instance of the application')
.option('--processEnvs <json-string>', 'a JSON string of key/value pairs to be set as environment variables before any browser windows are opened.', getProcessEnvs)
.option('--file-download-options <json-string>', 'a JSON string of key/value pairs to be set as file download options. See https://github.com/sindresorhus/electron-dl for available options.', parseJson)
.option('--tray', 'allow app to stay in system tray')
.option('--basic-auth-username <value>', 'basic http(s) auth username')
.option('--basic-auth-password <value>', 'basic http(s) auth password')

View File

@ -66,6 +66,7 @@ export default function (inpOptions) {
FileDescription: inpOptions.name,
},
processEnvs: inpOptions.processEnvs,
fileDownloadOptions: inpOptions.fileDownloadOptions,
tray: inpOptions.tray || false,
basicAuthUsername: inpOptions.basicAuthUsername || null,
basicAuthPassword: inpOptions.basicAuthPassword || null,