git ssb

1+

Daan Patchwork / patchwork



Tree: 401c797bb92a373ffa4499d47ecea37f75e2a16e

Files: 401c797bb92a373ffa4499d47ecea37f75e2a16e / lib / window.js

2163 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 const availableLangs = window.webContents.session.availableSpellCheckerLanguages
33 window.webContents.send('setAvailableDictionaries', availableLangs)
34 })
35
36 // setTimeout(function () {
37 // window.show()
38 // }, 3000)
39
40 window.webContents.on('will-navigate', function (e, url) {
41 e.preventDefault()
42 electron.shell.openExternal(url)
43 })
44
45 window.webContents.on('new-window', function (e, url) {
46 e.preventDefault()
47 electron.shell.openExternal(url)
48 })
49
50 window.on('closed', function () {
51 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
52 })
53
54 // TODO: better way to determine whether this is the main window ?
55 if (opts.title === "Patchwork") {
56 setupContextMenu(
57 config,
58 serverDevToolsCallback,
59 navigateHandler,
60 window
61 );
62 }
63
64 window.loadURL('file://' + Path.join(__dirname, '..', 'assets', 'base.html'))
65 return window
66
67 // scoped
68
69 function handleReadyToShow (ev) {
70 if (ev.sender === window) {
71 window.show()
72 electron.ipcMain.removeListener('ready-to-show', handleReadyToShow)
73 }
74 }
75}
76

Built with git-ssb-web