Add --browserwindow-options to completely expose Electron options (PR #835)

This adds a new flag `--browserwindow-options`, taking a stringified JSON object as input.  
It will be inserted directly into the options when BrowserConfig is initialized.

This allows total configurability of the electron BrowserWindow configuration via nativefier.

An example use case is added to the documentation, which modifies the default font family in the browser.

#### References

- https://github.com/electron/electron/blob/master/docs/api/browser-window.md#new-browserwindowoptions
  - See the following for electron v3.1.7
  - https://github.com/electron/electron/blob/v3.1.7/docs/api/browser-window.md#new-browserwindowoptions
This commit is contained in:
FabulousCupcake 2019-08-22 21:37:49 +02:00 committed by Ronan Jouchet
parent 81c422d4e0
commit d0a0614ba3
5 changed files with 26 additions and 0 deletions

View File

@ -104,6 +104,8 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
},
};
const browserwindowOptions = Object.assign({}, options.browserwindowOptions);
const mainWindow = new BrowserWindow(
Object.assign(
{
@ -128,6 +130,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
backgroundColor: options.backgroundColor,
},
DEFAULT_WINDOW_OPTIONS,
browserwindowOptions,
),
);

View File

@ -64,6 +64,7 @@
- [[file-download-options]](#file-download-options)
- [[always-on-top]](#always-on-top)
- [[global-shortcuts]](#global-shortcuts)
- [[browserwindow-options]](#browserwindow-options)
- [[darwin-dark-mode-support]](#darwin-dark-mode-support)
- [[background-color]](#background-color)
- [Programmatic API](#programmatic-api)
@ -696,6 +697,21 @@ Example `shortcuts.json` for `https://deezer.com` & `https://soundcloud.com` to
]
```
#### [browserwindow-options]
```
--browserwindow-options <json-string>
```
a JSON string that will be sent directly into electron BrowserWindow options.
See [Electron's BrowserWindow API Documentation](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions) for the complete list of options.
Example:
```bash
nativefier <your-website> --browserwindow-options '{ "webPreferences": { "defaultFontFamily": { "standard": "Comic Sans MS", "serif": "Comic Sans MS" } } }'
```
#### [darwin-dark-mode-support]
```

View File

@ -58,6 +58,7 @@ function selectAppArgs(options) {
alwaysOnTop: options.alwaysOnTop,
titleBarStyle: options.titleBarStyle,
globalShortcuts: options.globalShortcuts,
browserwindowOptions: options.browserwindowOptions,
backgroundColor: options.backgroundColor,
darwinDarkModeSupport: options.darwinDarkModeSupport,
};

View File

@ -238,6 +238,11 @@ if (require.main === module) {
'--global-shortcuts <value>',
'JSON file with global shortcut configuration. See https://github.com/jiahaog/nativefier/blob/master/docs/api.md#global-shortcuts',
)
.option(
'--browserwindow-options <json-string>',
'a JSON string that will be sent directly into electron BrowserWindow options. See https://github.com/jiahaog/nativefier/blob/master/docs/api.md#browserwindow-options',
parseJson,
)
.option(
'--background-color <value>',
"Sets the background color (for seamless experience while the app is loading). Example value: '#2e2c29'",

View File

@ -77,6 +77,7 @@ export default function(inpOptions) {
alwaysOnTop: inpOptions.alwaysOnTop || false,
titleBarStyle: inpOptions.titleBarStyle || null,
globalShortcuts: inpOptions.globalShortcuts || null,
browserwindowOptions: inpOptions.browserwindowOptions,
backgroundColor: inpOptions.backgroundColor || null,
darwinDarkModeSupport: inpOptions.darwinDarkModeSupport || false,
};