From b06f28ae104215c7440c2c77d451ba0a5792b330 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 22 Jul 2016 01:32:39 +0100 Subject: [PATCH] Adds plugin hook for decorating the electron browser options (#310) * adds hook for decorating the electron browser options * pass browser options to decorator --- index.js | 7 +++++-- plugins.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 112e5138..b39d8bc0 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ app.on('ready', () => { function createWindow (fn) { const cfg = plugins.getDecoratedConfig(); - const win = new BrowserWindow({ + const browserDefaults = { width: 540, height: 380, minHeight: 190, @@ -61,7 +61,10 @@ app.on('ready', () => { // we only want to show when the prompt // is ready for user input show: process.env.HYPERTERM_DEBUG || isDev - }); + }; + const browserOptions = plugins.getDecoratedBrowserOptions(browserDefaults); + + const win = new BrowserWindow(browserOptions); windowSet.add(win); win.loadURL(url); diff --git a/plugins.js b/plugins.js index f2b16035..ff749813 100644 --- a/plugins.js +++ b/plugins.js @@ -311,3 +311,19 @@ exports.getDecoratedConfig = function () { }); return decorated; }; + +exports.getDecoratedBrowserOptions = function (defaults) { + let decorated = defaults; + modules.forEach((plugin) => { + if (plugin.decorateBrowserOptions) { + const res = plugin.decorateBrowserOptions(decorated); + if (res && 'object' === typeof res) { + decorated = res; + } else { + notify('Plugin error!', `"${plugin._name}": invalid return type for \`decorateBrowserOptions\``); + } + } + }); + return decorated; +}; +