This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced.js
136 lines (117 loc) · 3.39 KB
/
advanced.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
/* eslint-disable no-empty */
/* eslint-disable no-console */
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
const remote = require('electron').remote;
const ipc = require('electron').ipcRenderer;
const fs = require('fs');
setTimeout(() => {
setInterval(() => {
let cacheSize = ipc.sendSync('session', 1);
document.getElementById('cacheSize').value = cacheSize;
mdui.mutation();
}, 500);
}, 1000);
setInterval(() => {
saveConfig();
}, 10000);
var hei;
var mode;
ipc.on('resize', function (event, data) {
if (!data[2]) {
document.getElementById('config-w').value = data[0];
document.getElementById('config-h').value = data[1];
}
hei = data[1];
});
fs.readFile(`./config.json`, (err, data) => {
if (!err) {
let obj = JSON.parse(data.toString());
console.log(obj);
let w = obj.window.w;
let h = obj.window.h;
let r = obj.window.r;
hei = h;
document.getElementById('config-w').value = w;
document.getElementById('config-h').value = h;
}
});
fs.readFile('login.json', (err, data) => {
if (!err) {
let j = JSON.parse(data);
let login = j.login;
let roomid = j.roomid;
document.getElementById('login').value = login;
document.getElementById('roomid').value = roomid;
}
});
setTimeout(() => {
document.getElementById('sendmessage').addEventListener('keypress', function (event) {
console.log(event);
if (event.keyCode == 13) {
sendMsg(document.getElementById('sendmessage').value);
document.getElementById('sendmessage').value = '';
}
});
document.getElementById('senddanmu').addEventListener('keypress', function (event) {
console.log(event);
if (event.keyCode == 13) {
sendDanmu(document.getElementById('senddanmu').value);
document.getElementById('senddanmu').value = '';
}
});
}, 1000);
function reload() {
ipc.send('reload', 1);
}
function switchWindow(name) {
mode = name;
saveConfig(true);
reload();
}
function savelogin() {
let login = document.getElementById('login').value;
let password = hex_md5(document.getElementById('password').value);
let roomid = document.getElementById('roomid').value;
fs.writeFileSync('login.json', JSON.stringify({
login: login,
password: password,
roomid: roomid
}));
}
function saveConfig(isSync) {
let w = document.getElementById('config-w').value;
let h = document.getElementById('config-h').value;
w = Number(w);
h = Number(h);
let data = JSON.stringify({
window: {
w: w,
h: h
},
mode: mode
});
if (!isSync) {
fs.writeFile('./config.json', data, (err) => {
if (err) {
mdui.snackbar({
message: '保存失败',
position: 'right-bottom',
timeout: 5000
});
} else { }
});
} else fs.writeFileSync('./config.json', data);
}
function close() {
var window = remote.getCurrentWindow();
window.close();
}
function min() {
var window = remote.getCurrentWindow();
window.minimize();
}
mdui.mutation();
function about() {
mdui.alert(`<div class="mdui-typo">GitHub: <p>irose-tools/electron-iirose</p></div>`, '关于');
}