git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: ec22930fce654eefee73dc9cc02061810988d4bd

Files: ec22930fce654eefee73dc9cc02061810988d4bd / index.js

3892 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 }, opts))
112
113 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
114
115 // fix offline on windows by specifying 127.0.0.1 instead of localhost (default)
116 var id = ssbConfig.keys.id
117 ssbConfig.remote = `net:127.0.0.1:${ssbConfig.port}~shs:${id.slice(1).replace('.ed25519', '')}`
118
119 if (opts.server === false) {
120 cb && cb()
121 } else {
122 electron.ipcMain.once('server-started', function (ev, config) {
123 ssbConfig = config
124 cb && cb()
125 })
126 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
127 connect: false,
128 center: true,
129 fullscreen: false,
130 fullscreenable: false,
131 height: 150,
132 maximizable: false,
133 minimizable: false,
134 resizable: false,
135 show: false,
136 skipTaskbar: true,
137 title: 'patchwork-server',
138 useContentSize: true,
139 width: 150
140 })
141 // windows.background.on('close', (ev) => {
142 // ev.preventDefault()
143 // windows.background.hide()
144 // })
145 }
146}
147

Built with git-ssb-web