git ssb

10+

Matt McKegg / patchwork



Tree: a97b2ac07374b443c84bbd1f8d2c42f40456a4bb

Files: a97b2ac07374b443c84bbd1f8d2c42f40456a4bb / index.js

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

Built with git-ssb-web