git ssb

10+

Matt McKegg / patchwork



Tree: 4a443a53ebb8d1cf5b4c743923aa6b4a5c1c419a

Files: 4a443a53ebb8d1cf5b4c743923aa6b4a5c1c419a / index.js

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

Built with git-ssb-web