-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·178 lines (119 loc) · 3.79 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
const msg = require('./module/export')
const ejse = require('ejs-electron')
const db = require('./module/db.js')
const dblog = require('./module/logdb.js')
const fs = require('fs')
const bg = require('./module/background.js')
function makeid(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}
function createWindow() {
const win = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
bg.zfc(win)
async function pathCreator(dirPath) {
dirPath.split(path.sep).reduce((prevPath, folder) => {
const currentPath = path.join(prevPath, folder, path.sep);
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
win.maximize();
win.show();
ipcMain.on('create', (event, arg) => {
console.log(arg);
})
ipcMain.on('zfc_get', async (event, arg) => {
var response = await db.find({})
response.sort((a, b) => {
return new Date(b.created) - new Date(a.created);
});
msg.send('zfc_data_c', response, win)
})
ipcMain.on('ram_btn_db', async (event, arg) => {
await db.remove({})
msg.send('zfc_data', ``, win)
msg.send('notification', `The entire order database has been cleared.`, win)
})
ipcMain.on('ram_btn_log', async (event, arg) => {
await dblog.remove({})
msg.send('zfc_data', ``, win)
msg.send('notification', 'The entire translation history database has been cleaned.', win)
})
ipcMain.on('saveconfig', (event, arg) => {
fs.writeFileSync(__dirname + '/config.json', JSON.stringify(arg))
})
ipcMain.on('download', (event, arg) => {
msg.send('downloadjs', {
href: `file://` + __dirname + '/' + arg.path,
name: arg.data + '.json'
}, win)
})
ipcMain.on('config', (event, arg) => {
var all = fs.readFileSync(__dirname + '/config.json', 'utf-8')
all = JSON.parse(all)
msg.send('configdata', all, win)
})
ipcMain.on('addcron', async (event, arg) => {
var id = makeid(25) + Date.now()
console.log(id);
pathCreator(__dirname + '/dir/' + id + '/' + 'response')
var path = '/dir/' + id + '/' + 'default' + '.json'
try {
fs.writeFileSync(__dirname + path, JSON.stringify(arg.data))
} catch (err) {
fs.writeFileSync(__dirname + path, arg.data)
}
await db.add({
id: id,
path: path,
created: Date.now(),
status: 'Pending',
code: 200,
model: arg.model,
order_name: arg.order_name,
languages: arg.languages.map(el => {
return {
name: el.name,
code: el.code,
status: false,
path: '/'
}
}),
})
msg.send('startcron', '', win)
msg.send('notification', `The translation process was successfully started. You can view the progress and download the prepared JSON data from the History tab.`, win)
})
msg.send('zfc_data', '', win)
msg.send('zfc', '', win)
win.loadFile(__dirname + '/views/index.ejs')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})