-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
101 lines (83 loc) · 2.34 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
const electron = require('electron');
// Module to control application life.
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
// ipc module
const ipcMain = electron.ipcMain;
// dialog
const dialog = electron.dialog;
const _crypto = require('crypto');
const algorithm = 'aes-256-ctr';
const salt = 'mANiNThEdARk';
let mainWindow;
let win2;
let fse = require('fs-extra');
let path = require('path');
let fs = require('fs');
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600});
win2 = new BrowserWindow();
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
let dataPath = app.getPath('appData');
let appPath = path.join(dataPath, 'kQueue');
let configFile = path.join(appPath, 'config.json');
let cipher = _crypto.createCipher(algorithm, salt);
let _crypted = cipher.update('123456', 'utf8', 'hex');
_crypted += cipher.final('hex');
fse.ensureDirSync(appPath);
fs.access(configFile, fs.W_OK && fs.R_OK, (err) => {
if (err) {
let defaultConfig = {
hosxp: {
host: '127.0.0.1',
database: 'hos',
port: 3306,
user: 'sa',
password: _crypted
},
queue: {
host: '127.0.0.1',
database: 'hos',
port: 3306,
user: 'sa',
password: _crypted
}
};
fse.writeJsonSync(configFile, defaultConfig);
}
});
ipcMain.on('open-file', function(event) {
let file = dialog.showOpenDialog({
properties: [ 'openFile', 'multiSelections' ],
filters: [
{ name: 'PDF', extensions: ['pdf'] },
//{ name: 'PNG Image', extensions: ['png'] }
]
});
if (file) event.returnValue = file;
else event.returnValue = null;
});
ipcMain.on('get-config-file', function(event, arg) {
event.returnValue = configFile;
});
// Emitted when the window is closed.
mainWindow.on('closed', function() {
mainWindow = null;
});
}
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});