Files: c3bad31f482772bb2f1cb0a4e5b4f99071a9a625 / index.js
2113 bytesRaw
1 | process.on('uncaughtException', function (err) { |
2 | console.log(err) |
3 | process.exit() |
4 | }) |
5 | |
6 | var electron = require('electron') |
7 | var openWindow = require('./lib/window') |
8 | |
9 | var Path = require('path') |
10 | var defaultMenu = require('electron-default-menu') |
11 | var Menu = electron.Menu |
12 | var extend = require('xtend') |
13 | var ssbKeys = require('ssb-keys') |
14 | |
15 | var windows = { |
16 | dialogs: new Set() |
17 | } |
18 | |
19 | var ssbConfig = null |
20 | |
21 | electron.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 | |
34 | function openMainWindow () { |
35 | if (!windows.main) { |
36 | windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), { |
37 | minWidth: 800, |
38 | width: 1024, |
39 | height: 768, |
40 | titleBarStyle: 'hidden-inset', |
41 | title: 'Patchwork', |
42 | show: true, |
43 | backgroundColor: '#EEE', |
44 | webPreferences: { |
45 | experimentalFeatures: true |
46 | }, |
47 | icon: './ferment-logo.png' |
48 | }) |
49 | windows.main.setSheetOffset(40) |
50 | windows.main.on('closed', function () { |
51 | windows.main = null |
52 | }) |
53 | } |
54 | } |
55 | |
56 | function setupContext (appName, opts, cb) { |
57 | ssbConfig = require('ssb-config/inject')(appName, extend({ |
58 | port: 8008, |
59 | blobsPort: 7777 |
60 | }, opts)) |
61 | |
62 | ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret')) |
63 | |
64 | if (opts.server === false) { |
65 | cb && cb() |
66 | } else { |
67 | electron.ipcMain.once('server-started', function (ev, config) { |
68 | ssbConfig = config |
69 | cb && cb() |
70 | }) |
71 | windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), { |
72 | connect: false, |
73 | center: true, |
74 | fullscreen: false, |
75 | fullscreenable: false, |
76 | height: 150, |
77 | maximizable: false, |
78 | minimizable: false, |
79 | resizable: false, |
80 | show: false, |
81 | skipTaskbar: true, |
82 | title: 'patchwork-server', |
83 | useContentSize: true, |
84 | width: 150 |
85 | }) |
86 | } |
87 | } |
88 |
Built with git-ssb-web