forked from buildog/BarterDEX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dev.js
132 lines (112 loc) · 3.96 KB
/
main.dev.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
/*
Bootstrap of Electron 🚀
*/
import { app, BrowserWindow, Menu, ipcMain } from 'electron';
import { menuTemplate } from './menu';
import { API } from './api';
import { electronEvents, shepherdEvents, tradeEvents, portfolioEvents, orderbookEvents } from './events';
import { main } from './config/config';
const api = new API();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow = null
let menu
const installExtensions = async () => {
if (process.env.NODE_ENV === 'development') {
require('electron-debug')();
const installer = require('electron-devtools-installer') // eslint-disable-line global-require
const extensions = ['REACT_DEVELOPER_TOOLS', 'REACT_PERF']
const forceDownload = !!process.env.UPGRADE_EXTENSIONS
for (const name of extensions) {
try {
await installer.default(installer[name], forceDownload);
} catch (e) {} // eslint-disable-line
}
}
}
app.on('ready', async () => {
await installExtensions()
mainWindow = new BrowserWindow({
width: 900,
height: 786,
minWidth: 720,
show: false,
backgroundColor: '#25282A'
})
// Bootstrap listeners
const eventsConfig = { api, emitter: mainWindow.webContents, listener: ipcMain, config: main };
const eventsElectron = { app, emitter: mainWindow.webContents, mainWindow, api, config: main, listener: ipcMain };
electronEvents(eventsElectron);
shepherdEvents(eventsConfig);
tradeEvents(eventsConfig);
portfolioEvents(eventsConfig);
orderbookEvents(eventsConfig);
mainWindow.loadURL(`file://${__dirname}/app/index.html`)
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show()
mainWindow.focus()
});
mainWindow.on('closed', () => { mainWindow = null })
mainWindow.on('enter-full-screen', () => {
// Send async message to renderer process to update the store
mainWindow.webContents.send('fullscreen-toggled', true);
});
mainWindow.on('leave-full-screen', () => {
// Send async message to renderer process to update the store
mainWindow.webContents.send('fullscreen-toggled', false);
});
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)
});
}
// Check if we are on a MAC
if (process.platform === 'darwin') {
// Create our menu entries so that we can use MAC shortcuts
Menu.setApplicationMenu(Menu.buildFromTemplate([
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' },
{ role: 'quit' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' },
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
role: 'window',
submenu: [
{ role: 'minimize' },
{ role: 'close' }
]
}
]));
}
})