Files: 5b9d7ca9bb4a61d94b54a1fc968703c840a856d9 / index.js
3095 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 | 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 | |
52 | function openMainWindow () { |
53 | if (!windows.main) { |
54 | var windowState = WindowState({ |
55 | defaultWidth: 1024, |
56 | defaultHeight: 768 |
57 | }) |
58 | windows.main = openWindow(ssbConfig, Path.join(__dirname, 'main-window.js'), { |
59 | minWidth: 800, |
60 | x: windowState.x, |
61 | y: windowState.y, |
62 | width: windowState.width, |
63 | height: windowState.height, |
64 | titleBarStyle: 'hidden-inset', |
65 | autoHideMenuBar: true, |
66 | title: 'Patchwork', |
67 | show: true, |
68 | backgroundColor: '#EEE', |
69 | webPreferences: { |
70 | experimentalFeatures: true |
71 | }, |
72 | icon: './assets/icon.png' |
73 | }) |
74 | windowState.manage(windows.main) |
75 | windows.main.setSheetOffset(40) |
76 | windows.main.on('closed', function () { |
77 | windows.main = null |
78 | if (process.platform !== 'darwin') electron.app.quit() |
79 | }) |
80 | } |
81 | } |
82 | |
83 | function setupContext (appName, opts, cb) { |
84 | ssbConfig = require('ssb-config/inject')(appName, extend({ |
85 | port: 8008, |
86 | blobsPort: 7777 |
87 | }, opts)) |
88 | |
89 | ssbConfig.keys = ssbKeys.loadOrCreateSync(Path.join(ssbConfig.path, 'secret')) |
90 | |
91 | if (opts.server === false) { |
92 | cb && cb() |
93 | } else { |
94 | electron.ipcMain.once('server-started', function (ev, config) { |
95 | ssbConfig = config |
96 | cb && cb() |
97 | }) |
98 | windows.background = openWindow(ssbConfig, Path.join(__dirname, 'server-process.js'), { |
99 | connect: false, |
100 | center: true, |
101 | fullscreen: false, |
102 | fullscreenable: false, |
103 | height: 150, |
104 | maximizable: false, |
105 | minimizable: false, |
106 | resizable: false, |
107 | show: false, |
108 | skipTaskbar: true, |
109 | title: 'patchwork-server', |
110 | useContentSize: true, |
111 | width: 150 |
112 | }) |
113 | // windows.background.on('close', (ev) => { |
114 | // ev.preventDefault() |
115 | // windows.background.hide() |
116 | // }) |
117 | } |
118 | } |
119 |
Built with git-ssb-web