This repository has been archived by the owner on Jan 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.development.js
182 lines (164 loc) · 4.27 KB
/
main.development.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { app, BrowserWindow, Menu, shell, ipcMain } from 'electron';
import pkg from './package.json';
let menu;
let template;
let mainWindow = null;
const appWidth = 750 + (process.platform === 'win32' ? 20 : 0);
const appHeight = 560 + (process.platform === 'win32' ? 30 : 0);
global.args = {
isProduction: (process.env.NODE_ENV === 'production')
};
if (process.env.NODE_ENV === 'development') {
require('electron-debug')(); // eslint-disable-line global-require
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
const installExtensions = async() => {
if (process.env.NODE_ENV === 'development') {
const installer = require('electron-devtools-installer'); // eslint-disable-line global-require
const extensions = [
'REACT_DEVELOPER_TOOLS',
'REDUX_DEVTOOLS'
];
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload);
} catch (e) {
console.error(e);
}
}
}
};
app.on('ready', async() => {
await installExtensions();
mainWindow = new BrowserWindow({
show: false,
width: appWidth,
resizable: false,
height: appHeight,
});
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL(`file://${__dirname}/app/app.html`);
} else {
mainWindow.loadURL(`file://${__dirname}/app.html`);
}
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
});
mainWindow.on('closed', () => {
mainWindow = null;
});
if (process.env.NODE_ENV === 'development') {
mainWindow.openDevTools();
mainWindow.webContents.on('context-menu', (e, props) => {
const { x, y } = props;
Menu.buildFromTemplate([{
label: 'Inspect element',
click() {
mainWindow.inspectElement(x, y);
}
}]).popup(mainWindow);
});
}
if (process.platform === 'darwin') {
template = [{
label: `${pkg.productName}`,
submenu: [{
label: `About ${pkg.productName}`,
selector: 'orderFrontStandardAboutPanel:'
}, {
type: 'separator'
}, {
label: 'Services',
submenu: []
}, {
type: 'separator'
}, {
label: `Hide ${pkg.productName}`,
accelerator: 'Command+H',
selector: 'hide:'
}, {
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
}, {
label: 'Show All',
selector: 'unhideAllApplications:'
}, {
type: 'separator'
}, {
label: `Quit ${pkg.productName}`,
accelerator: 'Command+Q',
click() {
app.quit();
}
}]
}, {
label: 'Edit',
submenu: [{
label: 'Undo',
accelerator: 'Command+Z',
selector: 'undo:'
}, {
label: 'Redo',
accelerator: 'Shift+Command+Z',
selector: 'redo:'
}, {
type: 'separator'
}, {
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
}, {
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
}, {
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
}, {
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:'
}]
}, {
label: 'Window',
submenu: [{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
}, {
label: 'Close',
accelerator: 'Command+W',
selector: 'performClose:'
}, {
type: 'separator'
}, {
label: 'Bring All to Front',
selector: 'arrangeInFront:'
}]
}, {
label: 'Help',
submenu: [{
label: 'Learn More',
click() {
shell.openExternal('https://maidsafe.readme.io');
}
}, {
label: 'Community Discussions',
click() {
shell.openExternal('https://safenetforum.org/');
}
}]
}];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
ipcMain.on('invite', (event, arg) => {
mainWindow.webContents.send('messageFromMain', arg);
});
});