git ssb

10+

Matt McKegg / patchwork



Tree: 2d8c9a07a0734a2f88fc3920b5074cb64100020a

Files: 2d8c9a07a0734a2f88fc3920b5074cb64100020a / index.js

3919 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 if (process.platform === 'darwin') {
39 var win = menu.find(x => x.label === 'Window')
40 win.submenu = [
41 { role: 'minimize' },
42 { role: 'zoom' },
43 { role: 'close', label: 'Close' },
44 { type: 'separator' },
45 { role: 'front' }
46 ]
47 }
48 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
49 openMainWindow()
50 })
51
52 electron.app.on('activate', function (e) {
53 if (windows.main) {
54 windows.main.show()
55 }
56 })
57
58 electron.app.on('before-quit', function () {
59 quitting = true
60 })
61
62 electron.ipcMain.on('open-background-devtools', function (ev, config) {
63 if (windows.background) {
64 windows.background.webContents.openDevTools({detach: true})
65 }
66 })
67})
68
69function openMainWindow () {
70 if (!windows.main) {
71 var windowState = WindowState({
72 defaultWidth: 1024,
73 defaultHeight: 768
74 })
75 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
76 minWidth: 800,
77 x: windowState.x,
78 y: windowState.y,
79 width: windowState.width,
80 height: windowState.height,
81 titleBarStyle: 'hidden-inset',
82 autoHideMenuBar: true,
83 title: 'Patchwork',
84 show: true,
85 backgroundColor: '#EEE',
86 icon: './assets/icon.png'
87 })
88 windowState.manage(windows.main)
89 windows.main.setSheetOffset(40)
90 windows.main.on('close', function (e) {
91 if (!quitting && process.platform === 'darwin') {
92 e.preventDefault()
93 windows.main.hide()
94 }
95 })
96 windows.main.on('closed', function () {
97 windows.main = null
98 if (process.platform !== 'darwin') electron.app.quit()
99 })
100 }
101}
102
103function setupContext (appName, opts, cb) {
104 ssbConfig = require('ssb-config/inject')(appName, extend({
105 port: 8008,
106 blobsPort: 7777,
107 friends: {
108 dunbar: 150,
109 hops: 2 // down from 3
110 }
111 }, opts))
112
113 console.log(ssbConfig)
114
115 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
116
117 // fix offline on windows by specifying 127.0.0.1 instead of localhost (default)
118 var id = ssbConfig.keys.id
119 ssbConfig.remote = `net:127.0.0.1:${ssbConfig.port}~shs:${id.slice(1).replace('.ed25519', '')}`
120
121 if (opts.server === false) {
122 cb && cb()
123 } else {
124 electron.ipcMain.once('server-started', function (ev, config) {
125 ssbConfig = config
126 cb && cb()
127 })
128 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
129 connect: false,
130 center: true,
131 fullscreen: false,
132 fullscreenable: false,
133 height: 150,
134 maximizable: false,
135 minimizable: false,
136 resizable: false,
137 show: false,
138 skipTaskbar: true,
139 title: 'patchwork-server',
140 useContentSize: true,
141 width: 150
142 })
143 // windows.background.on('close', (ev) => {
144 // ev.preventDefault()
145 // windows.background.hide()
146 // })
147 }
148}
149

Built with git-ssb-web