-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (61 loc) · 1.7 KB
/
Copy pathmain.js
File metadata and controls
77 lines (61 loc) · 1.7 KB
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
const {app, BrowserWindow, Menu} = require('electron');
const path = require('path');
const url = require('url');
const IPFS = require('ipfs');
const node = new IPFS();
var mainWindow;
//function to create Initial Window
function createWindow(){
//Create Browser window
mainWindow = new BrowserWindow({width: 800, height: 600, icon: __dirname+'assets/icons/egress.png' });
//load index.html
mainWindow.loadURL(url.format({
protocol: "file:",
slashes: true,
pathname: path.join(__dirname, 'index.html')
}));
//load devtools
//win.webContents.openDevTools();
//Setting the Mainmenu
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate)
//Start IPFS node
startIpfsDaemon();
mainWindow.on('closed', ()=>{
app.quit();
});
}
function startIpfsDaemon(){
node.on('ready', () => {
console.log('Node is ready to use!');
node.start();
});
node.on('error', error => {
console.error('Something went terribly wrong!', error);
});
node.on('start', () => console.log('Node started!'));
}
//Main Menu Template
const mainMenuTemplate = [
{
label: 'File',
submenu: [
{
label: 'Quit',
accelerator: process.platform == 'darwin' ? 'Command+Q' : 'Ctrl+Q',
click(){
app.quit();
}
}
]
}
]
//if run on MAC, then add a empty element
if(process.platform == 'darwin'){
mainMenuTemplate.unshift({});
}
//Run createWindows function
app.on('ready',createWindow);
//Quit when all windows are closed
app.on('window-all-closed',()=>{
app.quit();
});