Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit fbdda4e

Browse files
Do window content loading without remote
We were literally sending over a bunch of javascript code, and using remote to execute it. Now it's done via a handler.
1 parent 06407a5 commit fbdda4e

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

assets/base.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
e.preventDefault()
2727
console.error(e.error.stack || 'Uncaught ' + e.error)
2828
})
29+
30+
electron.ipcRenderer.once('window-setup', (event, msg) => {
31+
const {
32+
config,
33+
rootPath,
34+
data,
35+
title,
36+
} = msg
37+
var rootView = require(rootPath)
38+
var h = require('mutant/h')
39+
40+
electron.webFrame.setVisualZoomLevelLimits(1, 1)
41+
42+
document.documentElement.querySelector('head').appendChild(
43+
h('title', title)
44+
)
45+
46+
document.documentElement.replaceChild(h('body', [
47+
rootView(config, data)
48+
]), document.body)
49+
})
50+
2951
</script>
3052
</body>
3153
</html>

lib/window.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,12 @@ module.exports = function Window (config, path, opts) {
2222
electron.ipcMain.on('ready-to-show', handleReadyToShow)
2323

2424
window.webContents.on('dom-ready', function () {
25-
window.webContents.executeJavaScript(`
26-
var electron = require('electron')
27-
var rootView = require(${JSON.stringify(path)})
28-
var h = require('mutant/h')
29-
30-
electron.webFrame.setVisualZoomLevelLimits(1, 1)
31-
32-
var config = ${JSON.stringify(config)}
33-
var data = ${JSON.stringify(opts.data)}
34-
var title = ${JSON.stringify(opts.title || 'Patchwork')}
35-
36-
document.documentElement.querySelector('head').appendChild(
37-
h('title', title)
38-
)
39-
40-
document.documentElement.replaceChild(h('body', [
41-
rootView(config, data)
42-
]), document.body)
43-
`)
25+
window.webContents.send('window-setup', {
26+
rootPath: path,
27+
config: config,
28+
data: opts.data || '',
29+
title: opts.title || 'Patchwork',
30+
})
4431
})
4532

4633
// setTimeout(function () {

0 commit comments

Comments
 (0)