git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 1a1dfa987b784a002e626f97e18aeaf2164d1299

Files: 1a1dfa987b784a002e626f97e18aeaf2164d1299 / index.js

3940 bytesRaw
1process.on('uncaughtException', function (err) {
2 console.log(err)
3 process.exit()
4})
5
6var i18n = require('./lib/i18n').i18n
7
8var electron = require('electron')
9var openWindow = require('./lib/window')
10
11var Path = require('path')
12var defaultMenu = require('electron-default-menu')
13var WindowState = require('electron-window-state')
14var Menu = electron.Menu
15var extend = require('xtend')
16var ssbKeys = require('ssb-keys')
17
18var windows = {
19 dialogs: new Set()
20}
21var ssbConfig = null
22var quitting = false
23
24
25electron.app.on('ready', () => {
26 setupContext('ssb', {
27 server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
28 }, () => {
29 var menu = defaultMenu(electron.app, electron.shell)
30 var view = menu.find(x => x.label === 'View')
31 view.submenu = [
32 { role: 'reload' },
33 { role: 'toggledevtools' },
34 { type: 'separator' },
35 { role: 'resetzoom' },
36 { role: 'zoomin' },
37 { role: 'zoomout' },
38 { type: 'separator' },
39 { role: 'togglefullscreen' }
40 ]
41 if (process.platform === 'darwin') {
42 var win = menu.find(x => x.label === 'Window')
43 win.submenu = [
44 { role: 'minimize' },
45 { role: 'zoom' },
46 { role: 'close', label: 'Close' },
47 { type: 'separator' },
48 { role: 'front' }
49 ]
50 }
51 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
52 openMainWindow()
53 })
54
55 electron.app.on('activate', function (e) {
56 if (windows.main) {
57 windows.main.show()
58 }
59 })
60
61 electron.app.on('before-quit', function () {
62 quitting = true
63 })
64
65 electron.ipcMain.on('open-background-devtools', function (ev, config) {
66 if (windows.background) {
67 windows.background.webContents.openDevTools({detach: true})
68 }
69 })
70})
71
72function openMainWindow () {
73 if (!windows.main) {
74 var windowState = WindowState({
75 defaultWidth: 1024,
76 defaultHeight: 768
77 })
78 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
79 minWidth: 800,
80 x: windowState.x,
81 y: windowState.y,
82 width: windowState.width,
83 height: windowState.height,
84 titleBarStyle: 'hidden-inset',
85 autoHideMenuBar: true,
86 title: i18n.__("Patchwork"),
87 show: true,
88 backgroundColor: '#EEE',
89 webPreferences: {
90 experimentalFeatures: true
91 },
92 icon: './assets/icon.png'
93 })
94 windowState.manage(windows.main)
95 windows.main.setSheetOffset(40)
96 windows.main.on('close', function (e) {
97 if (!quitting && process.platform === 'darwin') {
98 e.preventDefault()
99 windows.main.hide()
100 }
101 })
102 windows.main.on('closed', function () {
103 windows.main = null
104 if (process.platform !== 'darwin') electron.app.quit()
105 })
106 }
107}
108
109function setupContext (appName, opts, cb) {
110 ssbConfig = require('ssb-config/inject')(appName, extend({
111 port: 8008,
112 blobsPort: 7777
113 }, opts))
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