Commit 55c50c08f47ee3fafa299acdf1e07ea2102b0e87
working electron setup
mix irving committed on 9/1/2017, 4:51:01 AMParent: 8e75010c68d2c079e58d57c19ae1919e2b878d31
Files changed
app/html/app.js | changed |
index.js | changed |
main.js | changed |
package-lock.json | changed |
package.json | changed |
assets/base.html | added |
assets/icon.png | added |
background-process.js | added |
config.js | added |
app/html/app.js | ||
---|---|---|
@@ -20,9 +20,16 @@ | ||
20 | 20 … | exports.create = function (api) { |
21 | 21 … | return nest('app.html.app', app) |
22 | 22 … | |
23 | 23 … | function app () { |
24 … | + console.log("STARTING app") | |
25 … | + | |
24 | 26 … | window = api.app.sync.window(window) |
27 … | + // TODO re-enable: | |
28 … | + // - context menu | |
29 … | + // - catchKeyboardShortcut | |
30 … | + // - error handling | |
31 … | + | |
25 | 32 … | const css = values(api.styles.css()).join('\n') |
26 | 33 … | insertCss(css) |
27 | 34 … | |
28 | 35 … | const initialTabs = [ '/public', '/private', '/notifications' ] |
index.js | ||
---|---|---|
@@ -1,7 +1,138 @@ | ||
1 | -const bulk = require('bulk-require') | |
1 … | +var defaultMenu = require('electron-default-menu') | |
2 … | +var WindowState = require('electron-window-state') | |
3 … | +var electron = require('electron') | |
4 … | +var Menu = electron.Menu | |
5 … | +var Path = require('path') | |
2 | 6 … | |
3 | -module.exports = { | |
4 | - patchbay: bulk(__dirname, [ | |
5 | - '!(node_modules|junk)/**/*.js' | |
6 | - ]) | |
7 … | +var windows = {} | |
8 … | +var quitting = false | |
9 … | + | |
10 … | +console.log('STARTING electron') | |
11 … | + | |
12 … | +electron.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 … | + if (process.platform === 'darwin') { | |
26 … | + var win = menu.find(x => x.label === 'Window') | |
27 … | + win.submenu = [ | |
28 … | + { role: 'minimize' }, | |
29 … | + { role: 'zoom' }, | |
30 … | + { role: 'close', label: 'Close' }, | |
31 … | + { type: 'separator' }, | |
32 … | + { role: 'front' } | |
33 … | + ] | |
34 … | + } | |
35 … | + | |
36 … | + Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | |
37 … | + | |
38 … | + startBackgroundProcess() | |
39 … | + | |
40 … | + // wait until server has started before opening main window | |
41 … | + electron.ipcMain.once('server-started', function (ev, config) { | |
42 … | + openMainWindow() | |
43 … | + }) | |
44 … | + | |
45 … | + electron.app.on('before-quit', function () { | |
46 … | + quitting = true | |
47 … | + }) | |
48 … | + | |
49 … | + // allow inspecting of background process | |
50 … | + electron.ipcMain.on('open-background-devtools', function (ev, config) { | |
51 … | + if (windows.background) { | |
52 … | + windows.background.webContents.openDevTools({detach: true}) | |
53 … | + } | |
54 … | + }) | |
55 … | +}) | |
56 … | + | |
57 … | +function startBackgroundProcess () { | |
58 … | + if (!windows.background) { | |
59 … | + windows.background = openWindow(Path.join(__dirname, 'background-process.js'), { | |
60 … | + connect: false, | |
61 … | + center: true, | |
62 … | + fullscreen: false, | |
63 … | + fullscreenable: false, | |
64 … | + height: 150, | |
65 … | + maximizable: false, | |
66 … | + minimizable: false, | |
67 … | + resizable: false, | |
68 … | + show: false, | |
69 … | + skipTaskbar: true, | |
70 … | + title: 'patchbay-server', | |
71 … | + useContentSize: true, | |
72 … | + width: 150 | |
73 … | + }) | |
74 … | + } | |
7 | 75 … | } |
76 … | + | |
77 … | +function openMainWindow () { | |
78 … | + if (!windows.main) { | |
79 … | + var windowState = WindowState({ | |
80 … | + defaultWidth: 1024, | |
81 … | + defaultHeight: 768 | |
82 … | + }) | |
83 … | + windows.main = openWindow(Path.join(__dirname, 'main.js'), { | |
84 … | + minWidth: 800, | |
85 … | + x: windowState.x, | |
86 … | + y: windowState.y, | |
87 … | + width: windowState.width, | |
88 … | + height: windowState.height, | |
89 … | + autoHideMenuBar: true, | |
90 … | + title: 'Patchbay', | |
91 … | + show: true, | |
92 … | + backgroundColor: '#FFF', | |
93 … | + icon: './assets/icon.png' | |
94 … | + }) | |
95 … | + windowState.manage(windows.main) | |
96 … | + windows.main.setSheetOffset(40) | |
97 … | + windows.main.on('close', function (e) { | |
98 … | + if (!quitting && process.platform === 'darwin') { | |
99 … | + e.preventDefault() | |
100 … | + windows.main.hide() | |
101 … | + } | |
102 … | + }) | |
103 … | + windows.main.on('closed', function () { | |
104 … | + windows.main = null | |
105 … | + if (process.platform !== 'darwin') electron.app.quit() | |
106 … | + }) | |
107 … | + } | |
108 … | +} | |
109 … | + | |
110 … | +function openWindow (path, opts) { | |
111 … | + var window = new electron.BrowserWindow(opts) | |
112 … | + window.webContents.on('dom-ready', function () { | |
113 … | + window.webContents.executeJavaScript(` | |
114 … | + var electron = require('electron') | |
115 … | + var h = require('mutant/h') | |
116 … | + electron.webFrame.setZoomLevelLimits(1, 1) | |
117 … | + var title = ${JSON.stringify(opts.title || 'Patchbay')} | |
118 … | + document.documentElement.querySelector('head').appendChild( | |
119 … | + h('title', title) | |
120 … | + ) | |
121 … | + require(${JSON.stringify(path)}) | |
122 … | + `) // NOTE tried process(electron) | |
123 … | + }) | |
124 … | + | |
125 … | + window.webContents.on('will-navigate', function (e, url) { | |
126 … | + e.preventDefault() | |
127 … | + electron.shell.openExternal(url) | |
128 … | + }) | |
129 … | + | |
130 … | + window.webContents.on('new-window', function (e, url) { | |
131 … | + e.preventDefault() | |
132 … | + electron.shell.openExternal(url) | |
133 … | + }) | |
134 … | + | |
135 … | + window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | |
136 … | + return window | |
137 … | +} | |
138 … | + |
main.js | ||
---|---|---|
@@ -1,32 +1,57 @@ | ||
1 | 1 … | const combine = require('depject') |
2 | 2 … | const entry = require('depject/entry') |
3 | 3 … | const nest = require('depnest') |
4 … | +const bulk = require('bulk-require') | |
4 | 5 … | |
5 | -const horcrux = require('ssb-horcrux') | |
6 | -const ssbchess = require('ssb-chess') | |
7 | -const patchHub = require('patch-hub') | |
8 | -const gatherings = require('patch-gatherings') | |
9 | -const bayGatherings = require('patchbay-gatherings') | |
10 | -const patchbay = require('./') | |
11 | -const patchContext = require('patch-context') | |
12 | -const patchcore = require('patchcore') | |
13 | - | |
14 | 6 … | // polyfills |
15 | 7 … | require('setimmediate') |
16 | 8 … | |
9 … | +const patchbay = { | |
10 … | + patchbay: { | |
11 … | + about: bulk(__dirname, [ 'about/**/*.js' ]), | |
12 … | + app: bulk(__dirname, [ 'app/**/*.js' ]), | |
13 … | + blob: bulk(__dirname, [ 'blob/**/*.js' ]), | |
14 … | + channel: bulk(__dirname, [ 'channel/**/*.js' ]), | |
15 … | + contact: bulk(__dirname, [ 'contact/**/*.js' ]), | |
16 … | + message: bulk(__dirname, [ 'message/**/*.js' ]), | |
17 … | + router: bulk(__dirname, [ 'router/**/*.js' ]), | |
18 … | + styles: bulk(__dirname, [ 'styles/**/*.js' ]), | |
19 … | + config: require('./config'), // shouldn't be in here ? | |
20 … | + contextMenu: require('patch-context'), | |
21 … | + } | |
22 … | +} | |
23 … | + | |
24 … | + | |
17 | 25 … | // from more specialized to more general |
18 | 26 … | const sockets = combine( |
19 | - // horcrux, | |
20 | - // ssbchess, | |
21 | - // patchHub, | |
22 | - // gatherings, | |
23 | - // bayGatherings, // TODO collect gatherings into this | |
27 … | + // require('ssb-horcrux'), | |
28 … | + // require('ssb-chess'), | |
29 … | + // require('patch-hub'), | |
30 … | + // require('patch-gatherings'), | |
31 … | + // require('patchbay-gatherings'), // TODO collect gatherings into this | |
24 | 32 … | patchbay, |
25 | - patchContext, | |
26 | - patchcore | |
33 … | + require('patchcore') | |
27 | 34 … | ) |
28 | 35 … | |
29 | 36 … | const api = entry(sockets, nest('app.html.app', 'first')) |
37 … | +const app = api.app.html.app | |
30 | 38 … | |
31 | -const app = api.app.html.app() | |
32 | -document.body.appendChild(app) | |
39 … | +console.log('LOADING modules') | |
40 … | +const yes = app() | |
41 … | +document.body.appendChild(yes) | |
42 … | + | |
43 … | +// function start (electron) { | |
44 … | +// document.body.appendChild(app(electron)) | |
45 … | +// } | |
46 … | + | |
47 … | +// // for electro | |
48 … | +// if (typeof window !== 'undefined') { | |
49 … | +// start() | |
50 … | +// } | |
51 … | + | |
52 … | +// // for people building with patchbay | |
53 … | +// start.modules = patchbay | |
54 … | + | |
55 … | +// // for electron | |
56 … | +// module.exports = start | |
57 … | + |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 252990 bytes New file size: 257871 bytes |
package.json | ||
---|---|---|
@@ -1,14 +1,14 @@ | ||
1 | 1 … | { |
2 | 2 … | "name": "patchbay", |
3 | 3 … | "version": "7.9.0", |
4 | 4 … | "description": "patchbay 2, built on patchcore", |
5 | - "main": "index.js", | |
5 … | + "main": "main.js", | |
6 | 6 … | "scripts": { |
7 | 7 … | "lint": "standard", |
8 | - "setup": "npm install electron electro -g", | |
9 | - "rebuild": "npm rebuild --runtime=electron --target=$(electron -v) --abi=$(electron --abi) --disturl=https://atom.io/download/atom-shell", | |
10 | - "start": "electro main.js" | |
8 … | + "rebuild": "cross-script npm rebuild --runtime=electron \"--target=$(electron -v)\" \"--abi=$(electron --abi)\" --disturl=https://atom.io/download/atom-shell", | |
9 … | + "start": "electron index.js", | |
10 … | + "dev": "echo 'run your own sbot!' && electro main.js" | |
11 | 11 … | }, |
12 | 12 … | "browserify": { |
13 | 13 … | "transform": [ |
14 | 14 … | "bulkify", |
@@ -35,11 +35,14 @@ | ||
35 | 35 … | "homepage": "https://github.com/ssbc/patchbay#readme", |
36 | 36 … | "dependencies": { |
37 | 37 … | "bulk-require": "^1.0.0", |
38 | 38 … | "bulkify": "^1.4.2", |
39 … | + "cross-script": "^1.0.5", | |
39 | 40 … | "dataurl-": "^0.1.0", |
40 | 41 … | "depject": "^3.2.0", |
41 | 42 … | "depnest": "^1.0.2", |
43 … | + "electron-default-menu": "^1.0.1", | |
44 … | + "electron-window-state": "^4.1.1", | |
42 | 45 … | "es2040": "^1.2.5", |
43 | 46 … | "font-awesome": "^4.7.0", |
44 | 47 … | "hypercrop": "^1.1.0", |
45 | 48 … | "hyperfile": "^2.0.0", |
@@ -58,21 +61,33 @@ | ||
58 | 61 … | "patchcore": "^1.10.3", |
59 | 62 … | "pull-abortable": "^4.1.1", |
60 | 63 … | "pull-cat": "^1.1.11", |
61 | 64 … | "pull-next": "1.0.0", |
62 | - "pull-scroll": "^1.0.7", | |
65 … | + "pull-scroll": "^1.0.9", | |
63 | 66 … | "pull-stream": "^3.5.0", |
64 | 67 … | "read-directory": "^2.0.0", |
65 | 68 … | "require-style": "^1.0.0", |
69 … | + "scuttlebot": "^10.4.4", | |
66 | 70 … | "setimmediate": "^1.0.5", |
67 | - "ssb-chess": "1.4.3", | |
68 | 71 … | "ssb-horcrux": "^0.1.3", |
69 | - "ssb-mentions": "~0.4.0", | |
72 … | + "ssb-ws": "^1.0.3", | |
70 | 73 … | "style-resolve": "^1.0.1", |
71 | 74 … | "suggest-box": "^2.2.3", |
72 | 75 … | "text-node-searcher": "^1.1.1", |
73 | 76 … | "xtend": "^4.0.1" |
74 | 77 … | }, |
75 | 78 … | "devDependencies": { |
79 … | + "electro": "^2.0.3", | |
80 … | + "electron": "~1.6.11", | |
81 … | + "ssb-about": "^0.1.0", | |
82 … | + "ssb-backlinks": "^0.4.0", | |
83 … | + "ssb-blobs": "^1.1.3", | |
84 … | + "ssb-contacts": "0.0.2", | |
85 … | + "ssb-friends": "^2.2.2", | |
86 … | + "ssb-fulltext": "^1.0.1", | |
87 … | + "ssb-keys": "^7.0.10", | |
88 … | + "ssb-mentions": "^0.4.0", | |
89 … | + "ssb-private": "^0.1.2", | |
90 … | + "ssb-query": "^0.1.2", | |
76 | 91 … | "standard": "^8.6.0" |
77 | 92 … | } |
78 | 93 … | } |
assets/base.html | ||
---|---|---|
@@ -1,0 +1,32 @@ | ||
1 … | + | |
2 … | +<html> | |
3 … | + <head></head> | |
4 … | + <body> | |
5 … | + <script> | |
6 … | + // redirect console to main process | |
7 … | + var electron = require('electron') | |
8 … | + var localLog = console.log | |
9 … | + var localError = console.error | |
10 … | + var remoteLog = electron.remote.getGlobal('console').log | |
11 … | + var remoteError = electron.remote.getGlobal('console').error | |
12 … | + | |
13 … | + console.log = function (...args) { | |
14 … | + localLog.apply(console, args) | |
15 … | + remoteLog(...args) | |
16 … | + } | |
17 … | + | |
18 … | + console.error = function (...args) { | |
19 … | + localError.apply(console, args) | |
20 … | + remoteError(...args) | |
21 … | + } | |
22 … | + | |
23 … | + process.exit = electron.remote.app.quit | |
24 … | + // redirect errors to stderr | |
25 … | + window.addEventListener('error', function (e) { | |
26 … | + e.preventDefault() | |
27 … | + console.error(e.error.stack || 'Uncaught ' + e.error) | |
28 … | + }) | |
29 … | + </script> | |
30 … | + </body> | |
31 … | +</html> | |
32 … | + |
assets/icon.png |
---|
background-process.js | ||
---|---|---|
@@ -1,0 +1,32 @@ | ||
1 … | +var fs = require('fs') | |
2 … | +var Path = require('path') | |
3 … | +var electron = require('electron') | |
4 … | + | |
5 … | +console.log('STARTING SBOT') | |
6 … | + | |
7 … | +var createSbot = require('scuttlebot') | |
8 … | + .use(require('scuttlebot/plugins/master')) | |
9 … | + .use(require('scuttlebot/plugins/gossip')) | |
10 … | + .use(require('scuttlebot/plugins/replicate')) | |
11 … | + .use(require('ssb-friends')) | |
12 … | + .use(require('ssb-blobs')) | |
13 … | + .use(require('ssb-backlinks')) | |
14 … | + .use(require('ssb-private')) | |
15 … | + .use(require('scuttlebot/plugins/invite')) | |
16 … | + .use(require('scuttlebot/plugins/local')) | |
17 … | + .use(require('scuttlebot/plugins/logging')) | |
18 … | + .use(require('ssb-query')) | |
19 … | + .use(require('ssb-about')) | |
20 … | + .use(require('ssb-contacts')) | |
21 … | + .use(require('ssb-fulltext')) | |
22 … | + // .use(require('ssb-ebt')) | |
23 … | + .use(require('ssb-ws')) | |
24 … | + | |
25 … | +// pull config options out of depject | |
26 … | +var config = require('./config').create().config.sync.load() | |
27 … | + | |
28 … | +var sbot = createSbot(config) | |
29 … | +var manifest = sbot.getManifest() | |
30 … | +fs.writeFileSync(Path.join(config.path, 'manifest.json'), JSON.stringify(manifest)) | |
31 … | +electron.ipcRenderer.send('server-started') | |
32 … | + |
config.js | ||
---|---|---|
@@ -1,0 +1,26 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const Config = require('ssb-config/inject') | |
3 … | +const ssbKeys = require('ssb-keys') | |
4 … | +const Path = require('path') | |
5 … | + | |
6 … | +const appName = process.env.ssb_appname || 'ssb' | |
7 … | +const opts = appName == 'ssb' | |
8 … | + ? null | |
9 … | + : null // require('./default-config.json') | |
10 … | + | |
11 … | +exports.gives = nest('config.sync.load') | |
12 … | +exports.create = (api) => { | |
13 … | + var config | |
14 … | + return nest('config.sync.load', () => { | |
15 … | + if (!config) { | |
16 … | + console.log('LOADING config') | |
17 … | + config = Config(appName, opts) | |
18 … | + config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | |
19 … | + | |
20 … | + // HACK: fix offline on windows by specifying 127.0.0.1 instead of localhost (default) | |
21 … | + config.remote = `net:127.0.0.1:${config.port}~shs:${config.keys.id.slice(1).replace('.ed25519', '')}` | |
22 … | + } | |
23 … | + return config | |
24 … | + }) | |
25 … | +} | |
26 … | + |
Built with git-ssb-web