git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: acc18907d6e2af88fbfaac4a30d812a09c9a1571

Files: acc18907d6e2af88fbfaac4a30d812a09c9a1571 / index.js

2478 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 Menu.setApplicationMenu(Menu.buildFromTemplate(defaultMenu(electron.app, electron.shell)))
26 openMainWindow()
27 })
28
29 electron.app.on('activate', function (e) {
30 openMainWindow()
31 })
32
33 electron.ipcMain.on('open-background-devtools', function (ev, config) {
34 if (windows.background) {
35 windows.background.webContents.openDevTools({detach: true})
36 }
37 })
38})
39
40function openMainWindow () {
41 if (!windows.main) {
42 windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), {
43 minWidth: 800,
44 width: 1024,
45 height: 768,
46 titleBarStyle: 'hidden-inset',
47 title: 'Patchwork',
48 show: true,
49 backgroundColor: '#EEE',
50 webPreferences: {
51 experimentalFeatures: true
52 },
53 icon: './ferment-logo.png'
54 })
55 windows.main.setSheetOffset(40)
56 windows.main.on('closed', function () {
57 windows.main = null
58 if (process.platform !== 'darwin') electron.app.quit()
59 })
60 }
61}
62
63function setupContext (appName, opts, cb) {
64 ssbConfig = require('ssb-config/inject')(appName, extend({
65 port: 8008,
66 blobsPort: 7777
67 }, opts))
68
69 ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret'))
70
71 if (opts.server === false) {
72 cb && cb()
73 } else {
74 electron.ipcMain.once('server-started', function (ev, config) {
75 ssbConfig = config
76 cb && cb()
77 })
78 windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), {
79 connect: false,
80 center: true,
81 fullscreen: false,
82 fullscreenable: false,
83 height: 150,
84 maximizable: false,
85 minimizable: false,
86 resizable: false,
87 show: false,
88 skipTaskbar: true,
89 title: 'patchwork-server',
90 useContentSize: true,
91 width: 150
92 })
93 // windows.background.on('close', (ev) => {
94 // ev.preventDefault()
95 // windows.background.hide()
96 // })
97 }
98}
99

Built with git-ssb-web