-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
59 lines (48 loc) · 1.23 KB
/
main.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
var app = require('app');
var BrowserWindow = require('browser-window');
var fs = require("fs");
var ipc = require("ipc");
var daemon = require("./lib/daemon.js");
var mainWindow = null;
var config = null;
// Quit when all windows are closed.
// TODO: Allow daemon to run in background
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
daemon.stop();
app.quit();
}
});
app.on('ready', function() {
config = loadConfig();
setupIPCHandlers();
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
title: "Sia"
});
mainWindow.loadUrl('file://' + __dirname + '/site/index.html');
mainWindow.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
});
});
function loadConfig() {
// TODO: error handling
if (fs.existsSync("config.json")) {
return JSON.parse(fs.readFileSync("config.json"));
} else {
return {
"siad_cmd": "siad",
"siad_addr": "http://localhost:9980"
};
}
}
function setupIPCHandlers() {
ipc.on("start-daemon", function() {
daemon.start(config);
});
ipc.on("stop-daemon", function() {
daemon.stop();
});
}