-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
48 lines (40 loc) · 1.15 KB
/
main.js
File metadata and controls
48 lines (40 loc) · 1.15 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
var { app, BrowserWindow, ipcMain, session } = require('electron');
var fs = require('fs');
var path = require('path');
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
let mainWindow = null;
app.on('ready', function() {
if(!fs.existsSync(path.join(app.getPath('userData'), 'Libris.json'))) {
createStorage();
}
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://' + __dirname +'/public/index.html');
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
});
ipcMain.on('createStorage', function() {
createStorage();
mainWindow.webContents.reload();
});
ipcMain.on('cleanCache', function() {
session.defaultSession.clearCache(function() {
console.log('cleaned');
});
});
mainWindow.on('closed', function() {
mainWindow = null;
});
});
function createStorage() {
return fs.writeFileSync(path.resolve(app.getPath('userData'), 'Libris.json'),
JSON.stringify({
books: [],
config: JSON.parse(fs.readFileSync(path.join(__dirname, 'json', 'config.json')))
})
);
}