git ssb

1+

Daan Patchwork / patchwork



Tree: a40d71e4d68bf04bb03d8040fbf7614880514dc8

Files: a40d71e4d68bf04bb03d8040fbf7614880514dc8 / lib / window.js

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

Built with git-ssb-web