git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 45eb38ea158546001d22126e5b308ea80452483a

Files: 45eb38ea158546001d22126e5b308ea80452483a / lib / window.js

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

Built with git-ssb-web