Files: c0020bee25c8fb4c60ca23afc9576fec7efaa1bc / index.js
3381 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 WindowState = require('electron-window-state') |
12 | var Menu = electron.Menu |
13 | var extend = require('xtend') |
14 | var ssbKeys = require('ssb-keys') |
15 | |
16 | var windows = { |
17 | dialogs: new Set() |
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 | 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 | if (process.platform === 'darwin') { |
38 | var win = menu.find(x => x.label === 'Window') |
39 | win.submenu = [ |
40 | { role: 'minimize' }, |
41 | { role: 'zoom' }, |
42 | { role: 'close', label: 'Close' }, |
43 | { type: 'separator' }, |
44 | { role: 'front' } |
45 | ] |
46 | } |
47 | Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) |
48 | openMainWindow() |
49 | }) |
50 | |
51 | electron.app.on('activate', function (e) { |
52 | openMainWindow() |
53 | }) |
54 | |
55 | electron.ipcMain.on('open-background-devtools', function (ev, config) { |
56 | if (windows.background) { |
57 | windows.background.webContents.openDevTools({detach: true}) |
58 | } |
59 | }) |
60 | }) |
61 | |
62 | function openMainWindow () { |
63 | if (!windows.main) { |
64 | var windowState = WindowState({ |
65 | defaultWidth: 1024, |
66 | defaultHeight: 768 |
67 | }) |
68 | windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), { |
69 | minWidth: 800, |
70 | x: windowState.x, |
71 | y: windowState.y, |
72 | width: windowState.width, |
73 | height: windowState.height, |
74 | titleBarStyle: 'hidden-inset', |
75 | autoHideMenuBar: true, |
76 | title: 'Patchwork', |
77 | show: true, |
78 | backgroundColor: '#EEE', |
79 | webPreferences: { |
80 | experimentalFeatures: true |
81 | }, |
82 | icon: './assets/icon.png' |
83 | }) |
84 | windowState.manage(windows.main) |
85 | windows.main.setSheetOffset(40) |
86 | windows.main.on('closed', function () { |
87 | windows.main = null |
88 | if (process.platform !== 'darwin') electron.app.quit() |
89 | }) |
90 | } |
91 | } |
92 | |
93 | function setupContext (appName, opts, cb) { |
94 | ssbConfig = require('ssb-config/inject')(appName, extend({ |
95 | port: 8008, |
96 | blobsPort: 7777 |
97 | }, opts)) |
98 | |
99 | ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret')) |
100 | |
101 | if (opts.server === false) { |
102 | cb && cb() |
103 | } else { |
104 | electron.ipcMain.once('server-started', function (ev, config) { |
105 | ssbConfig = config |
106 | cb && cb() |
107 | }) |
108 | windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), { |
109 | connect: false, |
110 | center: true, |
111 | fullscreen: false, |
112 | fullscreenable: false, |
113 | height: 150, |
114 | maximizable: false, |
115 | minimizable: false, |
116 | resizable: false, |
117 | show: false, |
118 | skipTaskbar: true, |
119 | title: 'patchwork-server', |
120 | useContentSize: true, |
121 | width: 150 |
122 | }) |
123 | // windows.background.on('close', (ev) => { |
124 | // ev.preventDefault() |
125 | // windows.background.hide() |
126 | // }) |
127 | } |
128 | } |
129 |
Built with git-ssb-web