git ssb

10+

Matt McKegg / patchwork



Tree: 0900401aa912baeaca5a68feb70f4847503c6c70

Files: 0900401aa912baeaca5a68feb70f4847503c6c70 / index.js

3680 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 webPreferences: {
87 experimentalFeatures: true
88 },
89 icon: './assets/icon.png'
90 })
91 windowState.manage(windows.main)
92 windows.main.setSheetOffset(40)
93 windows.main.on('close', function (e) {
94 if (!quitting && process.platform === 'darwin') {
95 e.preventDefault()
96 windows.main.hide()
97 }
98 })
99 windows.main.on('closed', function () {
100 windows.main = null
101 if (process.platform !== 'darwin') electron.app.quit()
102 })
103 }
104}
105
106function setupContext (appName, opts, cb) {
107 ssbConfig = require('ssb-config/inject')(appName, extend({
108 port: 8008,
109 blobsPort: 7777
110 }, opts))
111
112 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
113
114 if (opts.server === false) {
115 cb && cb()
116 } else {
117 electron.ipcMain.once('server-started', function (ev, config) {
118 ssbConfig = config
119 cb && cb()
120 })
121 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
122 connect: false,
123 center: true,
124 fullscreen: false,
125 fullscreenable: false,
126 height: 150,
127 maximizable: false,
128 minimizable: false,
129 resizable: false,
130 show: false,
131 skipTaskbar: true,
132 title: 'patchwork-server',
133 useContentSize: true,
134 width: 150
135 })
136 // windows.background.on('close', (ev) => {
137 // ev.preventDefault()
138 // windows.background.hide()
139 // })
140 }
141}
142

Built with git-ssb-web