git ssb

1+

Daan Patchwork / patchwork



Tree: 1786f9c4c5f7c770e215e697546f92cbd098bc2c

Files: 1786f9c4c5f7c770e215e697546f92cbd098bc2c / lib / window.js

2006 bytesRaw
1const Path = require('path')
2const electron = require('electron')
3const extend = require('xtend/mutable')
4const setupContextMenu = require('./context-menu')
5
6module.exports = function Window (config, path, opts, serverDevToolsCallback, navigateHandler) {
7 const window = new electron.BrowserWindow(extend({
8 show: false,
9 webPreferences: {
10 nodeIntegration: true, // XXX: Maybe not always necessary (?)
11 enableRemoteModule: true,
12 }
13 }, opts))
14
15 // have to forward the OS window state to the renderer because it cannot
16 // access directly
17 window.on('enter-full-screen', (event, alwaysOnTop) => {
18 window.webContents.send("enter-full-screen");
19 })
20 window.on('leave-full-screen', (event, alwaysOnTop) => {
21 window.webContents.send("leave-full-screen");
22 })
23 electron.ipcMain.on('ready-to-show', handleReadyToShow)
24
25 window.webContents.on('dom-ready', function () {
26 window.webContents.send('window-setup', {
27 rootPath: path,
28 config: config,
29 data: opts.data || '',
30 title: opts.title || 'Patchwork',
31 })
32 })
33
34 // setTimeout(function () {
35 // window.show()
36 // }, 3000)
37
38 window.webContents.on('will-navigate', function (e, url) {
39 e.preventDefault()
40 electron.shell.openExternal(url)
41 })
42
43 window.webContents.on('new-window', function (e, url) {
44 e.preventDefault()
45 electron.shell.openExternal(url)
46 })
47
48 window.on('closed', function () {
49 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
50 })
51
52 // TODO: better way to determine whether this is the main window ?
53 if (opts.title === "Patchwork") {
54 setupContextMenu(
55 config,
56 serverDevToolsCallback,
57 navigateHandler,
58 window
59 );
60 }
61
62 window.loadURL('file://' + Path.join(__dirname, '..', 'assets', 'base.html'))
63 return window
64
65 // scoped
66
67 function handleReadyToShow (ev) {
68 if (ev.sender === window) {
69 window.show()
70 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
71 }
72 }
73}
74

Built with git-ssb-web