git ssb

10+

Matt McKegg / patchwork



Tree: b1c890d592e7fb5f231385508a3bc61f145d4a5b

Files: b1c890d592e7fb5f231385508a3bc61f145d4a5b / index.js

4127 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 WindowState = require('electron-window-state')
12var Menu = electron.Menu
13var extend = require('xtend')
14var ssbKeys = require('ssb-keys')
15
16var windows = {
17 dialogs: new Set()
18}
19var ssbConfig = null
20var quitting = false
21
22electron.app.on('ready', () => {
23 setupContext('ssb', {
24 server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
25 }, () => {
26 var menu = defaultMenu(electron.app, electron.shell)
27 var view = menu.find(x => x.label === 'View')
28 view.submenu = [
29 { role: 'reload' },
30 { role: 'toggledevtools' },
31 { type: 'separator' },
32 { role: 'resetzoom' },
33 { role: 'zoomin' },
34 { role: 'zoomout' },
35 { type: 'separator' },
36 { role: 'togglefullscreen' }
37 ]
38 var help = menu.find(x => x.label === 'Help')
39 help.submenu = [
40 {
41 label: 'Learn More',
42 click () { require('electron').shell.openExternal('https://scuttlebutt.nz') }
43 }
44 ]
45 if (process.platform === 'darwin') {
46 var win = menu.find(x => x.label === 'Window')
47 win.submenu = [
48 { role: 'minimize' },
49 { role: 'zoom' },
50 { role: 'close', label: 'Close' },
51 { type: 'separator' },
52 { role: 'front' }
53 ]
54 }
55 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
56 openMainWindow()
57 })
58
59 electron.app.on('activate', function (e) {
60 if (windows.main) {
61 windows.main.show()
62 }
63 })
64
65 electron.app.on('before-quit', function () {
66 quitting = true
67 })
68
69 electron.ipcMain.on('open-background-devtools', function (ev, config) {
70 if (windows.background) {
71 windows.background.webContents.openDevTools({detach: true})
72 }
73 })
74})
75
76function openMainWindow () {
77 if (!windows.main) {
78 var windowState = WindowState({
79 defaultWidth: 1024,
80 defaultHeight: 768
81 })
82 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
83 minWidth: 800,
84 x: windowState.x,
85 y: windowState.y,
86 width: windowState.width,
87 height: windowState.height,
88 titleBarStyle: 'hidden-inset',
89 autoHideMenuBar: true,
90 title: 'Patchwork',
91 show: true,
92 backgroundColor: '#EEE',
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
110function setupContext (appName, opts, cb) {
111 ssbConfig = require('ssb-config/inject')(appName, extend({
112 port: 8008,
113 blobsPort: 7777,
114 friends: {
115 dunbar: 150,
116 hops: 2 // down from 3
117 }
118 }, opts))
119
120 console.log(ssbConfig)
121
122 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
123
124 // fix offline on windows by specifying 127.0.0.1 instead of localhost (default)
125 var id = ssbConfig.keys.id
126 ssbConfig.remote = `net:127.0.0.1:${ssbConfig.port}~shs:${id.slice(1).replace('.ed25519', '')}`
127
128 if (opts.server === false) {
129 cb && cb()
130 } else {
131 electron.ipcMain.once('server-started', function (ev, config) {
132 ssbConfig = config
133 cb && cb()
134 })
135 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
136 connect: false,
137 center: true,
138 fullscreen: false,
139 fullscreenable: false,
140 height: 150,
141 maximizable: false,
142 minimizable: false,
143 resizable: false,
144 show: false,
145 skipTaskbar: true,
146 title: 'patchwork-server',
147 useContentSize: true,
148 width: 150
149 })
150 // windows.background.on('close', (ev) => {
151 // ev.preventDefault()
152 // windows.background.hide()
153 // })
154 }
155}
156

Built with git-ssb-web