-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.js
63 lines (53 loc) · 1.62 KB
/
dev.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
var { app, BrowserWindow, crashReporter, ipcMain, session } = require('electron');
var fs = require('fs');
var path = require('path');
var installExtensions = require('./devTools.config');
crashReporter.start({
productName: 'Libris',
companyName: 'undefinerds',
submitURL: 'http://localhost:8080',
uploadToServer: true
});
let mainWindow = null;
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
app.on('ready', function() {
if(!fs.existsSync(path.resolve(app.getPath('userData'), 'Libris.json'))) {
fs.writeFileSync(path.resolve(app.getPath('userData'), 'Libris.json'),
JSON.stringify({
books: [],
config: JSON.parse(fs.readFileSync(path.join(__dirname, 'json', 'config.json')))
}));
}
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL(`file:///${process.cwd()}/public/development.html`);
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
});
installExtensions();
mainWindow.openDevTools();
ipcMain.on('cleanCache', function() {
session.defaultSession.clearCache(function() {
console.log('cleaned');
});
});
ipcMain.on('createStorage', (event) => {
fs.writeFileSync('./funciono.txt', 'creo que si');
createStorage();
});
ipcMain.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')))
})
);
}