Skip to content
Permalink
Newer
Older
100644 99 lines (89 sloc) 3.37 KB
1
import { app, BrowserWindow, ipcMain } from 'electron';
May 31, 2017
2
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';
3
import { enableLiveReload } from 'electron-compile';
4
import IPFS from 'ipfs';
5
import IpfsEventService from './services/api/event/EventIpfs';
6
import TelescopConfigEventService from './services/api/event/EventConfig';
7
import TelecopEventService from './services/api/event/EventTelescop';
8
import Logger from './services/logger';
9
May 31, 2017
10
// Keep a global reference of the window object, if you don't, the window will
11
// be closed automatically when the JavaScript object is garbage collected.
12
let mainWindow;
May 31, 2017
14
const isDevMode = process.execPath.match(/[\\/]electron/);
15
const logger = new Logger();
16
logger.level = 'debug';
17
18
if (isDevMode) enableLiveReload({ strategy: 'react-hmr' });
May 31, 2017
19
20
const createWindow = async () => {
21
// Create the browser window.
22
mainWindow = new BrowserWindow({
23
width: 800,
24
height: 600,
25
});
26
27
// and load the index.html of the app.
28
mainWindow.loadURL(`file://${__dirname}/index.html`);
29
30
// Open the DevTools.
31
if (isDevMode) {
32
await installExtension(REACT_DEVELOPER_TOOLS);
33
mainWindow.webContents.openDevTools();
34
}
35
36
// Emitted when the window is closed.
37
mainWindow.on('closed', () => {
38
// Dereference the window object, usually you would store windows
39
// in an array if your app supports multi windows, this is the time
40
// when you should delete the corresponding element.
41
mainWindow = null;
42
});
43
};
44
45
// This method will be called when Electron has finished
46
// initialization and is ready to create browser windows.
47
// Some APIs can only be used after this event occurs.
48
app.on('ready', (err, a) => {
49
logger.debug('app ready');
50
try{
51
node = new IPFS()
52
node.on('error', (error) =>{
53
if(error.message.indexOf("mismatch version") > -1){
54
logger.warn("Bad version of IPFS change version in ~/.jsipfs/version 5 to 6 or in you repository path");
55
process.exit(1);
56
}
57
logger.error(error.message);
58
process.exit(1);
59
});
60
node.on('ready', () => {
61
node.id((err, id) => {
62
if (err) {
63
return console.log(err)
64
}
65
var eventIpfs = new IpfsEventService(ipcMain, node);
66
var eventTelescopConfig = new TelescopConfigEventService(ipcMain, node);
67
var eventTelescop = new TelecopEventService(ipcMain, node);
68
logger.debug('ipfs daemon is started display main windows');
69
createWindow();
70
});
71
});
72
}catch(e){
73
logger.error(e);
74
process.exit(1);
75
}
May 31, 2017
76
});
77
78
// Quit when all windows are closed.
79
app.on('window-all-closed', () => {
80
// On OS X it is common for applications and their menu bar
81
// to stay active until the user quits explicitly with Cmd + Q
82
/*node.stopDaemon((err) => {
83
if (process.platform !== 'darwin') {
84
app.quit();
85
}
May 31, 2017
88
89
app.on('activate', () => {
90
// On OS X it's common to re-create a window in the app when the
91
// dock icon is clicked and there are no other windows open.
92
if (mainWindow === null) {
93
createWindow();
94
}
95
});
May 31, 2017
97
98
// In this file you can include the rest of your app's specific main process
99
// code. You can also put them in separate files and import them here.