-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (75 loc) · 1.97 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
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
const { app, BrowserWindow, ipcMain } = require('electron');
const http = require('http');
const server = http.createServer(app);
const io = require('socket.io').listen(server);
const fs = require('fs');
const path = require('path');
const files = require('./modules/files');
const loader = require('./modules/loader');
const socketHandler = require('./modules/socket');
const port = 3000;
global.paths = {
root: __dirname,
storage: path.join(__dirname, 'storage'),
remote: path.join(__dirname, 'remote')
};
global.windows = {};
function createWindow() {
// Create the browser window.
let win = new BrowserWindow({
title: 'Axe House',
show: false,
width: 1080,
height: 600,
minWidth: 800,
minHeight: 500,
//backgroundColor: '#ffffff',
//transparent: true,
frame: false,
icon: './www/assets/icon/favicon.png'
})
win.loadURL(`file://${__dirname}/www/index.html`);
//// uncomment below to open the DevTools.
win.setMinimizable(false);
win.webContents.openDevTools();
// Event when the window is closed.
win.on('closed', function () {
win = null;
app.quit();
});
global.windows['main-window'] = win;
}
ipcMain.on('local-store', (e, obj) => {
files.localStore(obj).then((result)=>{
e.sender.send('local-store-reply', result);
});
});
ipcMain.on('local-get', (e, obj) => {
files.localGet(obj).then((result)=>{
e.sender.send('local-get-reply', result);
});
});
ipcMain.on('app-quit', () => {
console.log('App Quit')
if (process.platform !== 'darwin') {
app.quit();
}
})
io.on('connection', (socket)=>{
socketHandler.process(socket, io);
});
// Create window on electron intialization
app.on('ready', () => {
loader.init();
createWindow();
files.initializeDirectory(global.paths.storage);
})
app.on('activate', function () {
// macOS specific close process
if (global.windows['main-window'] === null) {
createWindow()
}
});
server.listen(port, ()=>{
console.log('Listening on port: '+ port);
})