git ssb

10+

Matt McKegg / patchwork



Tree: 17a07cae56f9526af24d72a4feda4e99d29e71ea

Files: 17a07cae56f9526af24d72a4feda4e99d29e71ea / lib / window.js

1825 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 require('../lib/context-menu')
20 electron.webFrame.setZoomLevelLimits(1, 1)
21
22 var config = ${JSON.stringify(config)}
23 var data = ${JSON.stringify(opts.data)}
24 var title = ${JSON.stringify(opts.title || 'Patchwork')}
25
26 document.documentElement.querySelector('head').appendChild(
27 h('title', title)
28 )
29
30 var shouldShow = ${opts.show !== false}
31 var shouldConnect = ${opts.connect !== false}
32
33 document.documentElement.replaceChild(h('body', [
34 rootView(config, data)
35 ]), document.body)
36 `)
37 })
38
39 // setTimeout(function () {
40 // window.show()
41 // }, 3000)
42
43 window.webContents.on('will-navigate', function (e, url) {
44 e.preventDefault()
45 electron.shell.openExternal(url)
46 })
47
48 window.webContents.on('new-window', function (e, url) {
49 e.preventDefault()
50 electron.shell.openExternal(url)
51 })
52
53 window.on('closed', function () {
54 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
55 })
56
57 window.loadURL('file://' + Path.join(__dirname, '..', 'assets', 'base.html'))
58 return window
59
60 // scoped
61
62 function handleReadyToShow (ev) {
63 if (ev.sender === window) {
64 window.show()
65 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
66 }
67 }
68}
69

Built with git-ssb-web