Commit f739478e4a840b03a7f827fdf437965a27c21958
ahoy! - first pass hack of ssb-ahoy into place
mixmix committed on 2/13/2019, 10:02:21 AMParent: 9b0b78d08222f41f2d21ddae8b55449a25a0784c
Files changed
config.js | changed |
index.js | changed |
package-lock.json | changed |
package.json | changed |
config.js | ||
---|---|---|
@@ -17,10 +17,10 @@ | ||
17 | 17 | }) |
18 | 18 | |
19 | 19 | config = addSockets(config) |
20 | 20 | config = fixLocalhost(config) |
21 | - config = pubHopSettings(config) | |
22 | - config = torOnly(config) | |
21 | + // config = pubHopSettings(config) | |
22 | + // config = torOnly(config) | |
23 | 23 | |
24 | 24 | return config |
25 | 25 | }) |
26 | 26 | } |
index.js | ||
---|---|---|
@@ -3,168 +3,185 @@ | ||
3 | 3 | var electron = require('electron') |
4 | 4 | var Menu = electron.Menu |
5 | 5 | var Path = require('path') |
6 | 6 | |
7 | -var windows = {} | |
8 | -var quitting = false | |
7 | +const ahoy = require('ssb-ahoy') | |
8 | +const config = require('./config').create().config.sync.load() | |
9 | +const plugins = [ | |
10 | + 'ssb-server/plugins/unix-socket', | |
11 | + 'ssb-server/plugins/no-auth', | |
12 | + 'ssb-private', | |
13 | + 'ssb-backlinks', | |
14 | + 'ssb-about', | |
15 | + 'ssb-query', | |
16 | + 'ssb-suggest' | |
17 | +] | |
9 | 18 | |
10 | -console.log('STARTING electron') | |
11 | -electron.app.on('ready', () => { | |
12 | - startMenus() | |
19 | +ahoy(config, plugins, () => { | |
20 | + var state = { | |
21 | + windows: {}, | |
22 | + quitting: false | |
23 | + } | |
13 | 24 | |
14 | - startBackgroundProcess() | |
15 | - // wait until server has started before opening main window | |
16 | - electron.ipcMain.once('server-started', function (ev, config) { | |
17 | - openMainWindow() | |
18 | - }) | |
25 | + console.log('STARTING electron (patchbay)') | |
26 | + // mix: disable the on-ready because electron is already ready from ssb-ahoy... | |
27 | + // electron.app.on('ready', () => { | |
28 | + startMenus() | |
19 | 29 | |
20 | - electron.app.on('before-quit', function () { | |
21 | - quitting = true | |
22 | - }) | |
30 | + startBackgroundProcess() | |
31 | + // wait until server has started before opening main window | |
32 | + electron.ipcMain.once('server-started', function (ev, config) { | |
33 | + openMainWindow() | |
34 | + }) | |
23 | 35 | |
24 | - electron.app.on('activate', function (e) { | |
25 | - // reopen the app when dock icon clicked on macOS | |
26 | - if (windows.main) { | |
27 | - windows.main.show() | |
28 | - } | |
29 | - }) | |
36 | + electron.app.on('before-quit', function () { | |
37 | + state.quitting = true | |
38 | + }) | |
30 | 39 | |
31 | - // allow inspecting of background process | |
32 | - electron.ipcMain.on('open-background-devtools', function (ev, config) { | |
33 | - if (windows.background) { | |
34 | - windows.background.webContents.openDevTools({ detach: true }) | |
35 | - } | |
36 | - }) | |
37 | -}) | |
40 | + electron.app.on('activate', function (e) { | |
41 | + // reopen the app when dock icon clicked on macOS | |
42 | + if (state.windows.main) { | |
43 | + state.windows.main.show() | |
44 | + } | |
45 | + }) | |
38 | 46 | |
39 | -function startBackgroundProcess () { | |
40 | - if (windows.background) return | |
47 | + // allow inspecting of background process | |
48 | + electron.ipcMain.on('open-background-devtools', function (ev, config) { | |
49 | + if (state.windows.background) { | |
50 | + state.windows.background.webContents.openDevTools({ detach: true }) | |
51 | + } | |
52 | + }) | |
53 | + // }) | |
41 | 54 | |
42 | - windows.background = openWindow(Path.join(__dirname, 'server.js'), { | |
43 | - title: 'patchbay-server', | |
44 | - show: false, | |
45 | - connect: false, | |
46 | - width: 150, | |
47 | - height: 150, | |
48 | - center: true, | |
49 | - fullscreen: false, | |
50 | - fullscreenable: false, | |
51 | - maximizable: false, | |
52 | - minimizable: false, | |
53 | - resizable: false, | |
54 | - skipTaskbar: true, | |
55 | - useContentSize: true | |
56 | - }) | |
57 | -} | |
55 | + function startBackgroundProcess () { | |
56 | + if (state.windows.background) return | |
58 | 57 | |
59 | -function openMainWindow () { | |
60 | - if (windows.main) return | |
58 | + state.windows.background = openWindow(Path.join(__dirname, 'server.js'), { | |
59 | + title: 'patchbay-server', | |
60 | + show: false, | |
61 | + connect: false, | |
62 | + width: 150, | |
63 | + height: 150, | |
64 | + center: true, | |
65 | + fullscreen: false, | |
66 | + fullscreenable: false, | |
67 | + maximizable: false, | |
68 | + minimizable: false, | |
69 | + resizable: false, | |
70 | + skipTaskbar: true, | |
71 | + useContentSize: true | |
72 | + }) | |
73 | + } | |
61 | 74 | |
62 | - var windowState = WindowState({ | |
63 | - defaultWidth: 1024, | |
64 | - defaultHeight: 768 | |
65 | - }) | |
66 | - windows.main = openWindow(Path.join(__dirname, 'main.js'), { | |
67 | - title: 'Patchbay', | |
68 | - show: true, | |
75 | + function openMainWindow () { | |
76 | + if (state.windows.main) return | |
69 | 77 | |
70 | - x: windowState.x, | |
71 | - y: windowState.y, | |
72 | - minWidth: 800, | |
73 | - width: windowState.width, | |
74 | - height: windowState.height, | |
75 | - autoHideMenuBar: true, | |
76 | - frame: !process.env.FRAME, | |
77 | - // titleBarStyle: 'hidden', | |
78 | - backgroundColor: '#FFF', | |
79 | - icon: './assets/icon.png' | |
80 | - }) | |
81 | - windowState.manage(windows.main) | |
82 | - windows.main.setSheetOffset(40) | |
83 | - windows.main.on('close', function (e) { | |
84 | - if (!quitting && process.platform === 'darwin') { | |
85 | - e.preventDefault() | |
86 | - windows.main.hide() | |
87 | - } | |
88 | - }) | |
89 | - windows.main.on('closed', function () { | |
90 | - windows.main = null | |
91 | - if (process.platform !== 'darwin') electron.app.quit() | |
92 | - }) | |
93 | -} | |
78 | + var windowState = WindowState({ | |
79 | + defaultWidth: 1024, | |
80 | + defaultHeight: 768 | |
81 | + }) | |
82 | + state.windows.main = openWindow(Path.join(__dirname, 'main.js'), { | |
83 | + title: 'Patchbay', | |
84 | + show: true, | |
94 | 85 | |
95 | -function openWindow (path, opts) { | |
96 | - var window = new electron.BrowserWindow(opts) | |
86 | + x: windowState.x, | |
87 | + y: windowState.y, | |
88 | + minWidth: 800, | |
89 | + width: windowState.width, | |
90 | + height: windowState.height, | |
91 | + autoHideMenuBar: true, | |
92 | + frame: !process.env.FRAME, | |
93 | + // titleBarStyle: 'hidden', | |
94 | + backgroundColor: '#FFF', | |
95 | + icon: './assets/icon.png' | |
96 | + }) | |
97 | + windowState.manage(state.windows.main) | |
98 | + state.windows.main.setSheetOffset(40) | |
99 | + state.windows.main.on('close', function (e) { | |
100 | + if (!state.quitting && process.platform === 'darwin') { | |
101 | + e.preventDefault() | |
102 | + state.windows.main.hide() | |
103 | + } | |
104 | + }) | |
105 | + state.windows.main.on('closed', function () { | |
106 | + state.windows.main = null | |
107 | + if (process.platform !== 'darwin') electron.app.quit() | |
108 | + }) | |
109 | + } | |
97 | 110 | |
98 | - window.webContents.on('dom-ready', function () { | |
99 | - window.webContents.executeJavaScript(` | |
100 | - var electron = require('electron') | |
101 | - var h = require('mutant/h') | |
102 | - electron.webFrame.setVisualZoomLevelLimits(1, 1) | |
103 | - var title = ${JSON.stringify(opts.title || 'Patchbay')} | |
104 | - document.documentElement.querySelector('head').appendChild( | |
105 | - h('title', title) | |
106 | - ) | |
107 | - require(${JSON.stringify(path)}) | |
108 | - `) // NOTE tried process(electron) | |
109 | - }) | |
111 | + function openWindow (path, opts) { | |
112 | + var window = new electron.BrowserWindow(opts) | |
110 | 113 | |
111 | - window.webContents.on('will-navigate', function (e, url) { | |
112 | - e.preventDefault() | |
113 | - electron.shell.openExternal(url) | |
114 | - }) | |
114 | + window.webContents.on('dom-ready', function () { | |
115 | + window.webContents.executeJavaScript(` | |
116 | + var electron = require('electron') | |
117 | + var h = require('mutant/h') | |
118 | + electron.webFrame.setVisualZoomLevelLimits(1, 1) | |
119 | + var title = ${JSON.stringify(opts.title || 'Patchbay')} | |
120 | + document.documentElement.querySelector('head').appendChild( | |
121 | + h('title', title) | |
122 | + ) | |
123 | + require(${JSON.stringify(path)}) | |
124 | + `) // NOTE tried process(electron) | |
125 | + }) | |
115 | 126 | |
116 | - window.webContents.on('new-window', function (e, url) { | |
117 | - e.preventDefault() | |
118 | - electron.shell.openExternal(url) | |
119 | - }) | |
127 | + window.webContents.on('will-navigate', function (e, url) { | |
128 | + e.preventDefault() | |
129 | + electron.shell.openExternal(url) | |
130 | + }) | |
120 | 131 | |
121 | - window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | |
122 | - return window | |
123 | -} | |
132 | + window.webContents.on('new-window', function (e, url) { | |
133 | + e.preventDefault() | |
134 | + electron.shell.openExternal(url) | |
135 | + }) | |
124 | 136 | |
125 | -function startMenus () { | |
126 | - var menu = defaultMenu(electron.app, electron.shell) | |
127 | - var view = menu.find(x => x.label === 'View') | |
128 | - view.submenu = [ | |
129 | - { role: 'reload' }, | |
130 | - { role: 'toggledevtools' }, | |
131 | - { type: 'separator' }, | |
132 | - { role: 'resetzoom' }, | |
133 | - { role: 'zoomin' }, | |
134 | - { role: 'zoomout' }, | |
135 | - { type: 'separator' }, | |
136 | - { role: 'togglefullscreen' } | |
137 | - ] | |
138 | - var win = menu.find(x => x.label === 'Window') | |
139 | - win.submenu = [ | |
140 | - { role: 'minimize' }, | |
141 | - { role: 'zoom' }, | |
142 | - { role: 'close', label: 'Close Window', accelerator: 'CmdOrCtrl+Shift+W' }, | |
143 | - { type: 'separator' }, | |
144 | - { | |
145 | - label: 'Close Tab', | |
146 | - accelerator: 'CmdOrCtrl+W', | |
147 | - click () { | |
148 | - windows.main.webContents.send('closeTab') | |
149 | - } | |
150 | - }, | |
151 | - { | |
152 | - label: 'Select Next Tab', | |
153 | - accelerator: 'CmdOrCtrl+Shift+]', | |
154 | - click () { | |
155 | - windows.main.webContents.send('nextTab') | |
156 | - } | |
157 | - }, | |
158 | - { | |
159 | - label: 'Select Previous Tab', | |
160 | - accelerator: 'CmdOrCtrl+Shift+[', | |
161 | - click () { | |
162 | - windows.main.webContents.send('previousTab') | |
163 | - } | |
164 | - }, | |
165 | - { type: 'separator' }, | |
166 | - { role: 'front' } | |
167 | - ] | |
137 | + window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | |
138 | + return window | |
139 | + } | |
168 | 140 | |
169 | - Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | |
170 | -} | |
141 | + function startMenus () { | |
142 | + var menu = defaultMenu(electron.app, electron.shell) | |
143 | + var view = menu.find(x => x.label === 'View') | |
144 | + view.submenu = [ | |
145 | + { role: 'reload' }, | |
146 | + { role: 'toggledevtools' }, | |
147 | + { type: 'separator' }, | |
148 | + { role: 'resetzoom' }, | |
149 | + { role: 'zoomin' }, | |
150 | + { role: 'zoomout' }, | |
151 | + { type: 'separator' }, | |
152 | + { role: 'togglefullscreen' } | |
153 | + ] | |
154 | + var win = menu.find(x => x.label === 'Window') | |
155 | + win.submenu = [ | |
156 | + { role: 'minimize' }, | |
157 | + { role: 'zoom' }, | |
158 | + { role: 'close', label: 'Close Window', accelerator: 'CmdOrCtrl+Shift+W' }, | |
159 | + { type: 'separator' }, | |
160 | + { | |
161 | + label: 'Close Tab', | |
162 | + accelerator: 'CmdOrCtrl+W', | |
163 | + click () { | |
164 | + state.windows.main.webContents.send('closeTab') | |
165 | + } | |
166 | + }, | |
167 | + { | |
168 | + label: 'Select Next Tab', | |
169 | + accelerator: 'CmdOrCtrl+Shift+]', | |
170 | + click () { | |
171 | + state.windows.main.webContents.send('nextTab') | |
172 | + } | |
173 | + }, | |
174 | + { | |
175 | + label: 'Select Previous Tab', | |
176 | + accelerator: 'CmdOrCtrl+Shift+[', | |
177 | + click () { | |
178 | + state.windows.main.webContents.send('previousTab') | |
179 | + } | |
180 | + }, | |
181 | + { type: 'separator' }, | |
182 | + { role: 'front' } | |
183 | + ] | |
184 | + | |
185 | + Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | |
186 | + } | |
187 | +}) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 592290 bytes New file size: 591840 bytes |
Built with git-ssb-web