git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: ca4da78423a93192d0c1c35511d0be424d003d8c

Files: ca4da78423a93192d0c1c35511d0be424d003d8c / index.js

2405 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 electron.ipcMain.on('open-background-devtools', function (ev, config) {
34 if (windows.background) {
35 windows.background.webContents.openDevTools({detach: true})
36 }
37 })
38})
39
40function openMainWindow () {
41 if (!windows.main) {
42 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
43 minWidth: 800,
44 width: 1024,
45 height: 768,
46 titleBarStyle: 'hidden-inset',
47 title: 'Patchwork',
48 show: true,
49 backgroundColor: '#EEE',
50 webPreferences: {
51 experimentalFeatures: true
52 },
53 icon: './ferment-logo.png'
54 })
55 windows.main.setSheetOffset(40)
56 windows.main.on('closed', function () {
57 windows.main = null
58 })
59 }
60}
61
62function setupContext (appName, opts, cb) {
63 ssbConfig = require('ssb-config/inject')(appName, extend({
64 port: 8008,
65 blobsPort: 7777
66 }, opts))
67
68 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
69
70 if (opts.server === false) {
71 cb && cb()
72 } else {
73 electron.ipcMain.once('server-started', function (ev, config) {
74 ssbConfig = config
75 cb && cb()
76 })
77 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
78 connect: false,
79 center: true,
80 fullscreen: false,
81 fullscreenable: false,
82 height: 150,
83 maximizable: false,
84 minimizable: false,
85 resizable: false,
86 show: false,
87 skipTaskbar: true,
88 title: 'patchwork-server',
89 useContentSize: true,
90 width: 150
91 })
92 windows.background.on('close', (ev) => {
93 ev.preventDefault()
94 windows.background.hide()
95 })
96 }
97}
98

Built with git-ssb-web