-
Notifications
You must be signed in to change notification settings - Fork 4
/
renderer.js
59 lines (53 loc) · 1.7 KB
/
renderer.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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const { ipcMain } = require("electron");
const configOp = require("./npm/lib/configOp.js");
ipcMain.on('get-mode-main', function (event) {
event.sender.send('get-mode-reply', process.env.mode)
})
ipcMain.on('get-text-main', function (event, arg) {
configOp.readConfig((obj)=>{
event.sender.send('get-text-reply', obj)
},true);
})
ipcMain.on('setting-change-all', function (event, arg) {
configOp.readConfig((obj)=>{
if (!!arg.settings) {
obj.settings = arg.settings;
}
if (!!arg.preset) {
obj.preset = arg.preset;
}
configOp.writeConfig(obj);
},true);
})
ipcMain.on('setting-change', function (event, arg) {
configOp.readConfig((obj)=>{
let isUpdate = false;
if (!obj.settings) {//如果没有值的时候就设置成初始的 有的时候赋值
obj.settings = {};
isUpdate = true;
} else {
if (arg.value !== obj.settings[arg.key]) {
obj.settings[arg.key] = arg.value;
isUpdate = true;
}
}
if (isUpdate) {
configOp.writeConfig(obj);
}
},true);
})
ipcMain.on('set-text', function (event, arg) {
configOp.readConfig((obj)=>{
let text = arg;
if (!obj.texts) {
obj.texts = [];
}
if ((obj.texts.length > 0 && text !== obj.texts[0]) || obj.texts.length === 0) {
obj.texts.unshift(text);
configOp.writeConfig(JSON.stringify(obj));
}
},true);
})