Files: d56fe5e284a2a1b36f5b540a214aedd8c458bdcd / lib / window.js
1765 bytesRaw
1 | var Path = require('path') |
2 | var electron = require('electron') |
3 | var extend = require('xtend/mutable') |
4 | |
5 | module.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