This repository has been archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (67 loc) · 1.91 KB
/
index.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
/**
* Author : Thophile
* Project : Deskapp
*/
/**
* Build command :
* electron-packager . --platform=win32 --arch=x64 --overwrite --icon=assets/icons/win/icon_512x512.ico DeskApp
* node build_installer.js
*/
const electron = require('electron')
const { app, BrowserWindow } = electron
const fs = require('fs')
const path = require('path')
global.config = {
widgets : [],
devTools : false,
openAtLogin : false,
jwt: ""
};
global.details = {
watchList : [],
tasks : []
}
app.setLoginItemSettings({
openAtLogin: config.openAtLogin,
path: app.getPath("exe")
});
app.on('ready', () => {
global.Start()
})
app.on('window-all-closed', () => {
app.quit()
})
global.Start = function(){
//Read config file
fs.readFile(path.join(app.getPath('userData'), 'config.json'), (err, data) => {
if (err){
if (err.code === 'ENOENT') {
//Setting default if the file does not exists
console.log('File not found , setting defaults');
fs.writeFile(path.join(app.getPath('userData'), 'config.json'), JSON.stringify(config), function (err) {
if (err) throw err;
});
} else {
//throwing other error
throw err;
}
}else{
//Saving config object with the configuration
config = JSON.parse(data);
}
//Creating windows from config
let win = new BrowserWindow({
minWidth: 450,
minHeight: 350,
frame: false,
icon: __dirname + '/assets/icons/png/icon_512x512.png',
webPreferences: {
nodeIntegration: true
},
})
win.maximize()
win.loadURL(`file://${__dirname}/views/index.html`)
app.allowRendererProcessReuse = true;
if(config.devTools) win.webContents.openDevTools();
})
}