git ssb

10+

Matt McKegg / patchwork



Tree: 53f025a1f54ccd17981e2fc9a71ef5b27bce8f99

Files: 53f025a1f54ccd17981e2fc9a71ef5b27bce8f99 / index.js

2113 bytesRaw
1process.on('uncaughtException', function (err) {
2 console.log(err)
3 process.exit()
4})
5
6var electron = require('electron')
7var openWindow = require('./lib/window')
8
9var Path = require('path')
10var defaultMenu = require('electron-default-menu')
11var Menu = electron.Menu
12var extend = require('xtend')
13var ssbKeys = require('ssb-keys')
14
15var windows = {
16 dialogs: new Set()
17}
18
19var ssbConfig = null
20
21electron.app.on('ready', () => {
22 setupContext('ssb', {
23 server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
24 }, () => {
25 Menu.setApplicationMenu(Menu.buildFromTemplate(defaultMenu(electron.app, electron.shell)))
26 openMainWindow()
27 })
28
29 electron.app.on('activate', function (e) {
30 openMainWindow()
31 })
32})
33
34function openMainWindow () {
35 if (!windows.main) {
36 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
37 minWidth: 800,
38 width: 1024,
39 height: 768,
40 titleBarStyle: 'hidden-inset',
41 title: 'Patchwork',
42 show: true,
43 backgroundColor: '#EEE',
44 webPreferences: {
45 experimentalFeatures: true
46 },
47 icon: './ferment-logo.png'
48 })
49 windows.main.setSheetOffset(40)
50 windows.main.on('closed', function () {
51 windows.main = null
52 })
53 }
54}
55
56function setupContext (appName, opts, cb) {
57 ssbConfig = require('ssb-config/inject')(appName, extend({
58 port: 8008,
59 blobsPort: 7777
60 }, opts))
61
62 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
63
64 if (opts.server === false) {
65 cb && cb()
66 } else {
67 electron.ipcMain.once('server-started', function (ev, config) {
68 ssbConfig = config
69 cb && cb()
70 })
71 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
72 connect: false,
73 center: true,
74 fullscreen: false,
75 fullscreenable: false,
76 height: 150,
77 maximizable: false,
78 minimizable: false,
79 resizable: false,
80 show: false,
81 skipTaskbar: true,
82 title: 'patchwork-server',
83 useContentSize: true,
84 width: 150
85 })
86 }
87}
88

Built with git-ssb-web