Commit a40d71e4d68bf04bb03d8040fbf7614880514dc8
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.Daan Wynen committed on 3/6/2021, 10:11:18 PM
Parent: 809d3903e0c5c12da6a0c16b9bee86f7c03df6e6
Files changed
assets/base.html | changed |
lib/window.js | changed |
assets/base.html | |||
---|---|---|---|
@@ -32,7 +32,29 @@ | |||
32 | 32 … | e.preventDefault() | |
33 | 33 … | console.log(e) | |
34 | 34 … | console.error(e.error?.stack || 'Uncaught ' + e.error) | |
35 | 35 … | }) | |
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 … | + | ||
36 | 58 … | </script> | |
37 | 59 … | </body> | |
38 | 60 … | </html> |
lib/window.js | ||
---|---|---|
@@ -21,27 +21,14 @@ | ||
21 | 21 … | }) |
22 | 22 … | electron.ipcMain.on('ready-to-show', handleReadyToShow) |
23 | 23 … | |
24 | 24 … | 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 … | + }) | |
44 | 31 … | }) |
45 | 32 … | |
46 | 33 … | // setTimeout(function () { |
47 | 34 … | // window.show() |
Built with git-ssb-web