Commit 322cf9527ab94f96536f92a63ad982f647e1f6b9
Add support for custom ssb path
Peter Squicciarini committed on 7/9/2018, 2:22:37 PMParent: 5bbde5f671cc6a6ada171d0696db06cc13652771
Files changed
index.js | changed |
package-lock.json | changed |
package.json | changed |
server-process.js | changed |
index.js | |||
---|---|---|---|
@@ -11,15 +11,22 @@ | |||
11 | 11 … | var WindowState = require('electron-window-state') | |
12 | 12 … | var Menu = electron.Menu | |
13 | 13 … | var extend = require('xtend') | |
14 | 14 … | var ssbKeys = require('ssb-keys') | |
15 … | +var program = require('commander') | ||
15 | 16 … | ||
16 | 17 … | var windows = { | |
17 | 18 … | dialogs: new Set() | |
18 | 19 … | } | |
19 | 20 … | var ssbConfig = null | |
20 | 21 … | var quitting = false | |
21 | 22 … | ||
23 … | +// parse program args | ||
24 … | +program | ||
25 … | + .option('-g, --use-global-ssb', 'Use a global instance of sbot (Patchwork starts its own instance by default)') | ||
26 … | + .option('-p, --path <path>', 'Use a specific path to database files (default is $HOME/.ssb)') | ||
27 … | + .parse(process.argv) | ||
28 … | + | ||
22 | 29 … | /** | |
23 | 30 … | * It's not possible to run two instances of patchwork as it would create two | |
24 | 31 … | * scuttlebot instances that conflict on the same port. Before opening patchwork, | |
25 | 32 … | * we check if it's already running and if it is we focus the existing window | |
@@ -40,12 +47,22 @@ | |||
40 | 47 … | } | |
41 | 48 … | ||
42 | 49 … | quitIfAlreadyRunning() | |
43 | 50 … | ||
51 … | +// pass program arguments into ssb-config | ||
52 … | +var config = { | ||
53 … | + server: !program.useGlobalSsb | ||
54 … | +} | ||
55 … | +if (program.path) { | ||
56 … | + config.path = Path.resolve(program.path) | ||
57 … | + // currently git-ssb-web doesn't accept config options | ||
58 … | + // so a different path than the default would cause it to blow up | ||
59 … | + // so passing in a flag to server-process to skip launching it | ||
60 … | + config.customPath = true | ||
61 … | +} | ||
62 … | + | ||
44 | 63 … | electron.app.on('ready', () => { | |
45 | - setupContext('ssb', { | ||
46 | - server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb')) | ||
47 | - }, () => { | ||
64 … | + setupContext('ssb', config, () => { | ||
48 | 65 … | var browserWindow = openMainWindow() | |
49 | 66 … | var menu = defaultMenu(electron.app, electron.shell) | |
50 | 67 … | ||
51 | 68 … | menu.splice(4, 0, { |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 283508 bytes New file size: 283507 bytes |
package.json | ||
---|---|---|
@@ -16,8 +16,9 @@ | ||
16 | 16 … | "license": "AGPL-3.0", |
17 | 17 … | "dependencies": { |
18 | 18 … | "app-root-path": "^2.0.1", |
19 | 19 … | "bulk-require": "^1.0.1", |
20 … | + "commander": "^2.16.0", | |
20 | 21 … | "compare-version": "^0.1.2", |
21 | 22 … | "cross-script": "^1.0.5", |
22 | 23 … | "deep-equal": "^1.0.1", |
23 | 24 … | "depject": "^4.1.1", |
server-process.js | ||
---|---|---|
@@ -32,15 +32,18 @@ | ||
32 | 32 … | ssbConfig.manifest = context.sbot.getManifest() |
33 | 33 … | fs.writeFileSync(Path.join(ssbConfig.path, 'manifest.json'), JSON.stringify(ssbConfig.manifest)) |
34 | 34 … | electron.ipcRenderer.send('server-started', ssbConfig) |
35 | 35 … | |
36 | - // attempt to run git-ssb if it is installed and in path | |
37 | - var gitSsb = spawn('git-ssb', [ 'web' ], { | |
38 | - stdio: 'inherit' | |
39 | - }) | |
40 | - gitSsb.on('error', () => { | |
41 | - console.log('git-ssb is not installed, or not available in path') | |
42 | - }) | |
43 | - process.on('exit', () => { | |
44 | - gitSsb.kill() | |
45 | - }) | |
36 … | + // check if we are using a custom ssb path (which would break git-ssb-web) | |
37 … | + if (!ssbConfig.customPath) { | |
38 … | + // attempt to run git-ssb if it is installed and in path | |
39 … | + var gitSsb = spawn('git-ssb', [ 'web' ], { | |
40 … | + stdio: 'inherit' | |
41 … | + }) | |
42 … | + gitSsb.on('error', () => { | |
43 … | + console.log('git-ssb is not installed, or not available in path') | |
44 … | + }) | |
45 … | + process.on('exit', () => { | |
46 … | + gitSsb.kill() | |
47 … | + }) | |
48 … | + } | |
46 | 49 … | } |
Built with git-ssb-web