git ssb

16+

Dominic / patchbay



Tree: 47439fb7f64a0c82a1bc1e89a5f84566caf3634c

Files: 47439fb7f64a0c82a1bc1e89a5f84566caf3634c / index.js

4240 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 frame: !process.env.FRAME,
112 // titleBarStyle: 'hidden',
113 show: true,
114 backgroundColor: '#FFF',
115 icon: './assets/icon.png'
116 })
117 windowState.manage(windows.main)
118 windows.main.setSheetOffset(40)
119 windows.main.on('close', function (e) {
120 if (!quitting && process.platform === 'darwin') {
121 e.preventDefault()
122 windows.main.hide()
123 }
124 })
125 windows.main.on('closed', function () {
126 windows.main = null
127 if (process.platform !== 'darwin') electron.app.quit()
128 })
129 }
130}
131
132function openWindow (path, opts) {
133 var window = new electron.BrowserWindow(opts)
134 window.webContents.on('dom-ready', function () {
135 window.webContents.executeJavaScript(`
136 var electron = require('electron')
137 var h = require('mutant/h')
138 electron.webFrame.setZoomLevelLimits(1, 1)
139 var title = ${JSON.stringify(opts.title || 'Patchbay')}
140 document.documentElement.querySelector('head').appendChild(
141 h('title', title)
142 )
143 require(${JSON.stringify(path)})
144 `) // NOTE tried process(electron)
145 })
146
147 window.webContents.on('will-navigate', function (e, url) {
148 e.preventDefault()
149 electron.shell.openExternal(url)
150 })
151
152 window.webContents.on('new-window', function (e, url) {
153 e.preventDefault()
154 electron.shell.openExternal(url)
155 })
156
157 window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html'))
158 return window
159}
160

Built with git-ssb-web