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

Commit a40d71e

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 809d390 commit a40d71e

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
@@ -33,6 +33,28 @@
3333
console.log(e)
3434
console.error(e.error?.stack || 'Uncaught ' + e.error)
3535
})
36+
37+
electron.ipcRenderer.once('window-setup', (event, msg) => {
38+
const {
39+
config,
40+
rootPath,
41+
data,
42+
title,
43+
} = msg
44+
var rootView = require(rootPath)
45+
var h = require('mutant/h')
46+
47+
electron.webFrame.setVisualZoomLevelLimits(1, 1)
48+
49+
document.documentElement.querySelector('head').appendChild(
50+
h('title', title)
51+
)
52+
53+
document.documentElement.replaceChild(h('body', [
54+
rootView(config, data)
55+
]), document.body)
56+
})
57+
3658
</script>
3759
</body>
3860
</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)