git ssb

1+

Daan Patchwork / patchwork



Tree: 9b514132e92bd744e5003fc4f189a46ed5cdbf7e

Files: 9b514132e92bd744e5003fc4f189a46ed5cdbf7e / lib / window.js

1776 bytesRaw
1const Path = require('path')
2const electron = require('electron')
3const extend = require('xtend/mutable')
4
5module.exports = function Window (config, path, opts) {
6 const window = new electron.BrowserWindow(extend({
7 show: false,
8 webPreferences: {
9 nodeIntegration: true // XXX: Maybe not always necessary (?)
10 }
11 }, opts))
12
13 electron.ipcMain.on('ready-to-show', handleReadyToShow)
14
15 window.webContents.on('dom-ready', function () {
16 window.webContents.executeJavaScript(`
17 var electron = require('electron')
18 var rootView = require(${JSON.stringify(path)})
19 var h = require('mutant/h')
20
21 electron.webFrame.setVisualZoomLevelLimits(1, 1)
22
23 var config = ${JSON.stringify(config)}
24 var data = ${JSON.stringify(opts.data)}
25 var title = ${JSON.stringify(opts.title || 'Patchwork')}
26
27 document.documentElement.querySelector('head').appendChild(
28 h('title', title)
29 )
30
31 document.documentElement.replaceChild(h('body', [
32 rootView(config, data)
33 ]), document.body)
34 `)
35 })
36
37 // setTimeout(function () {
38 // window.show()
39 // }, 3000)
40
41 window.webContents.on('will-navigate', function (e, url) {
42 e.preventDefault()
43 electron.shell.openExternal(url)
44 })
45
46 window.webContents.on('new-window', function (e, url) {
47 e.preventDefault()
48 electron.shell.openExternal(url)
49 })
50
51 window.on('closed', function () {
52 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
53 })
54
55 window.loadURL('file://' + Path.join(__dirname, '..', 'assets', 'base.html'))
56 return window
57
58 // scoped
59
60 function handleReadyToShow (ev) {
61 if (ev.sender === window) {
62 window.show()
63 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
64 }
65 }
66}
67

Built with git-ssb-web