git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: e836f599f0095c03c6bb4b228c714e7130f797f6

Files: e836f599f0095c03c6bb4b228c714e7130f797f6 / lib / window.js

1766 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 electron.ipcMain.on('ready-to-show', handleReadyToShow)
11
12 window.webContents.on('dom-ready', function () {
13 window.webContents.executeJavaScript(`
14 var electron = require('electron')
15 var rootView = require(${JSON.stringify(path)})
16 var h = require('mutant/h')
17
18 electron.webFrame.setZoomLevelLimits(1, 1)
19
20 var config = ${JSON.stringify(config)}
21 var data = ${JSON.stringify(opts.data)}
22 var title = ${JSON.stringify(opts.title || "Patchwork" )}
23
24 document.documentElement.querySelector('head').appendChild(
25 h('title', title)
26 )
27
28 var shouldShow = ${opts.show !== false}
29 var shouldConnect = ${opts.connect !== false}
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