git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 4557a7bfe93e3b06fc8154b38538b6b926f8c512

Files: 4557a7bfe93e3b06fc8154b38538b6b926f8c512 / index.js

2838 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 autoHideMenuBar: true,
60 title: 'Patchwork',
61 show: true,
62 backgroundColor: '#EEE',
63 webPreferences: {
64 experimentalFeatures: true
65 },
66 icon: './assets/icon.png'
67 })
68 windows.main.setSheetOffset(40)
69 windows.main.on('closed', function () {
70 windows.main = null
71 if (process.platform !== 'darwin') electron.app.quit()
72 })
73 }
74}
75
76function setupContext (appName, opts, cb) {
77 ssbConfig = require('ssb-config/inject')(appName, extend({
78 port: 8008,
79 blobsPort: 7777
80 }, opts))
81
82 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
83
84 if (opts.server === false) {
85 cb && cb()
86 } else {
87 electron.ipcMain.once('server-started', function (ev, config) {
88 ssbConfig = config
89 cb && cb()
90 })
91 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
92 connect: false,
93 center: true,
94 fullscreen: false,
95 fullscreenable: false,
96 height: 150,
97 maximizable: false,
98 minimizable: false,
99 resizable: false,
100 show: false,
101 skipTaskbar: true,
102 title: 'patchwork-server',
103 useContentSize: true,
104 width: 150
105 })
106 // windows.background.on('close', (ev) => {
107 // ev.preventDefault()
108 // windows.background.hide()
109 // })
110 }
111}
112

Built with git-ssb-web