Skip to content

Commit

Permalink
Remove deepMerge for window opts
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Dec 4, 2020
1 parent 2509838 commit 4545524
Showing 1 changed file with 17 additions and 48 deletions.
65 changes: 17 additions & 48 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,30 +147,6 @@ exports.builder = yargs => {
})
}

function windowOptions (argv) {
const customWindowOptions = argv['window-config-file'] ? require(join(process.cwd(), argv['window-config-file'])) : {}
const windowOptions = mergeDeep(
{
height: 700,
width: 1200,
focusable: argv.renderer || argv.inspect,
webPreferences: {
enableRemoteModule: true,
contextIsolation: false,
nodeIntegration: true,
webSecurity: false
}
},
customWindowOptions,
{
webPreferences: {
preload: join(__dirname, '..', 'renderer', 'run.js')
}
}
)
return windowOptions
}

exports.handler = async argv => {
try {
await helpers.handleRequires(argv['require-main'])
Expand All @@ -197,7 +173,23 @@ exports.handler = async argv => {
}
})
} else {
const win = createWindow(windowOptions(argv))
const customWindowOptions = argv['window-config-file']
? require(resolve(argv['window-config-file']))
: {}

const win = createWindow({
height: 700,
width: 1200,
focusable: argv.renderer || argv.inspect,
...customWindowOptions,
webPreferences: {
enableRemoteModule: true,
contextIsolation: false,
nodeIntegration: true,
...customWindowOptions.webPreferences,
preload: join(__dirname, '..', 'renderer', 'run.js')
}
})

win.webContents.on('destroyed', () => app.exit(code))

Expand Down Expand Up @@ -263,26 +255,3 @@ const print = (method, args) => {
const output = util.format.apply(null, args)
console[method](output)
}

function isObject (item) {
return (item && typeof item === 'object' && !Array.isArray(item))
}

// Copied from https://stackoverflow.com/a/34749873/51209
function mergeDeep (target, ...sources) {
if (!sources.length) return target
const source = sources.shift()

if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} })
mergeDeep(target[key], source[key])
} else {
Object.assign(target, { [key]: source[key] })
}
}
}

return mergeDeep(target, ...sources)
}

0 comments on commit 4545524

Please sign in to comment.