This repository has been archived by the owner on Feb 4, 2018. It is now read-only.
forked from zsxsoft/danmu-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
66 lines (58 loc) · 2.22 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
'use strict';
(() => {
const electron = require('electron');
const windows = electron.remote.getGlobal('windows');
// const coordinator = electron.remote.getGlobal('coordinator');
const {shell} = electron;
const path = require('path');
const fs = require('fs');
const danmu = require("./lib/danmu");
const listener = require("./lib/listener");
const penetrate = require("./lib/penetrate");
const crypto = require('crypto');
const packageJson = require("./package.json");
let isStart = false;
let config = null;
try {
config = eval(fs.readFileSync(path.resolve('config.js'), "utf-8"));
} catch (e) {
alert("你的config.js修改有误,解析出错:\n" + e.stack.toString());
windows.mainWindow.openDevTools({detach: true});
throw e;
}
global.config = config;
function initFunction() {
windows.mainWindow.setResizable(false); // Electron doesn't support both resizable and transparency
document.getElementById("message").remove();
document.querySelector(".border").remove();
document.querySelector("body").style.background = "transparent";
listener.init(config);
danmu.init(config, listener, document.getElementById("main-canvas"));
penetrate.init();
isStart = true;
}
function keydownFunction(e) {
switch (e.keyCode) {
case 13:
if (!isStart) {
initFunction();
isStart = true;
}
break;
case 116:
e.preventDefault();
break;
case 112:
shell.openExternal(packageJson.homepage);
break;
case 123:
windows.mainWindow.webContents.openDevTools({detach: true});
break;
}
}
document.getElementById("client-version").innerHTML = packageJson.version;
document.getElementById("client-homepage").innerHTML = packageJson.homepage;
document.getElementById("client-author").innerHTML = packageJson.author;
document.title = "DANMU Client - Client ID = " + crypto.createHash('md5').update(Math.random().toString()).digest('hex');
window.addEventListener("keydown", keydownFunction, true);
})();