git ssb

16+

Dominic / patchbay



Tree: d07e0d2417f507c7cffdae3ae46476122eaba98b

Files: d07e0d2417f507c7cffdae3ae46476122eaba98b / index.js

4173 bytesRaw
1var defaultMenu = require('electron-default-menu')
2var WindowState = require('electron-window-state')
3var electron = require('electron')
4var Menu = electron.Menu
5var Path = require('path')
6
7var windows = {}
8var quitting = false
9
10console.log('STARTING electron')
11
12electron.app.on('ready', () => {
13 var menu = defaultMenu(electron.app, electron.shell)
14 var view = menu.find(x => x.label === 'View')
15 view.submenu = [
16 { role: 'reload' },
17 { role: 'toggledevtools' },
18 { type: 'separator' },
19 { role: 'resetzoom' },
20 { role: 'zoomin' },
21 { role: 'zoomout' },
22 { type: 'separator' },
23 { role: 'togglefullscreen' }
24 ]
25 var win = menu.find(x => x.label === 'Window')
26 win.submenu = [
27 { role: 'minimize' },
28 { role: 'zoom' },
29 { role: 'close', label: 'Close Window', accelerator: 'CmdOrCtrl+Shift+W' },
30 { type: 'separator' },
31 {
32 label: 'Close Tab',
33 accelerator: 'CmdOrCtrl+W',
34 click() {
35 windows.main.webContents.send('closeTab')
36 }
37 },
38 {
39 label: 'Select Next Tab',
40 accelerator: 'CmdOrCtrl+Shift+]',
41 click() {
42 windows.main.webContents.send('nextTab')
43 }
44 },
45 {
46 label: 'Select Previous Tab',
47 accelerator: 'CmdOrCtrl+Shift+[',
48 click() {
49 windows.main.webContents.send('previousTab')
50 }
51 },
52 { type: 'separator' },
53 { role: 'front' }
54 ]
55
56 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
57
58 startBackgroundProcess()
59
60 // wait until server has started before opening main window
61 electron.ipcMain.once('server-started', function (ev, config) {
62 openMainWindow()
63 })
64
65 electron.app.on('before-quit', function () {
66 quitting = true
67 })
68
69 // allow inspecting of background process
70 electron.ipcMain.on('open-background-devtools', function (ev, config) {
71 if (windows.background) {
72 windows.background.webContents.openDevTools({detach: true})
73 }
74 })
75})
76
77function startBackgroundProcess () {
78 if (!windows.background) {
79 windows.background = openWindow(Path.join(__dirname, 'background-process.js'), {
80 connect: false,
81 center: true,
82 fullscreen: false,
83 fullscreenable: false,
84 height: 150,
85 maximizable: false,
86 minimizable: false,
87 resizable: false,
88 show: false,
89 skipTaskbar: true,
90 title: 'patchbay-server',
91 useContentSize: true,
92 width: 150
93 })
94 }
95}
96
97function openMainWindow () {
98 if (!windows.main) {
99 var windowState = WindowState({
100 defaultWidth: 1024,
101 defaultHeight: 768
102 })
103 windows.main = openWindow(Path.join(__dirname, 'main.js'), {
104 minWidth: 800,
105 x: windowState.x,
106 y: windowState.y,
107 width: windowState.width,
108 height: windowState.height,
109 autoHideMenuBar: true,
110 title: 'Patchbay',
111 show: true,
112 backgroundColor: '#FFF',
113 icon: './assets/icon.png'
114 })
115 windowState.manage(windows.main)
116 windows.main.setSheetOffset(40)
117 windows.main.on('close', function (e) {
118 if (!quitting && process.platform === 'darwin') {
119 e.preventDefault()
120 windows.main.hide()
121 }
122 })
123 windows.main.on('closed', function () {
124 windows.main = null
125 if (process.platform !== 'darwin') electron.app.quit()
126 })
127 }
128}
129
130function openWindow (path, opts) {
131 var window = new electron.BrowserWindow(opts)
132 window.webContents.on('dom-ready', function () {
133 window.webContents.executeJavaScript(`
134 var electron = require('electron')
135 var h = require('mutant/h')
136 electron.webFrame.setZoomLevelLimits(1, 1)
137 var title = ${JSON.stringify(opts.title || 'Patchbay')}
138 document.documentElement.querySelector('head').appendChild(
139 h('title', title)
140 )
141 require(${JSON.stringify(path)})
142 `) // NOTE tried process(electron)
143 })
144
145 window.webContents.on('will-navigate', function (e, url) {
146 e.preventDefault()
147 electron.shell.openExternal(url)
148 })
149
150 window.webContents.on('new-window', function (e, url) {
151 e.preventDefault()
152 electron.shell.openExternal(url)
153 })
154
155 window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html'))
156 return window
157}
158

Built with git-ssb-web