-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.js
130 lines (105 loc) · 3.41 KB
/
render.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
const remote = require('electron').remote;
var temp = temp || {};
class scrd {
constructor(pWin) {
this.win = pWin;
this.currentApp = [];
this.intervals = [];
}
get app() {
return this.currentApp;
}
get io() {
return remote.getGlobal('io');
}
call(pFuncString) {
var self = this;
return function() {
var args = [];
for (var i = 0; i < arguments.length; i++)
args[i] = arguments[i];
self.io.emit('exeFunction', { call: pFuncString, arg: args });
};
}
callAjax(url, callback) {
var xmlhttp;
// compatible with IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
try {
var json = JSON.parse(xmlhttp.responseText);
callback(json);
} catch (e) {
callback(xmlhttp.responseText);
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
userConnected() {
this.startApp(Home);
}
createWin() {
this.win.getElementById("window").classList = "";
return this.win.getElementById("window");
}
startApp(pApp, pName) {
var id = window.setInterval(function() {}, 0);
while (id--) {
window.clearTimeout(id); // will do nothing if no timeout with id is present
}
if (typeof pApp !== 'undefined') {
this.currentApp = new pApp(this.createWin());
} else {
if (document.querySelectorAll('script[src="microapps/' + pName + '.js"]').length == 0) {
loadJS("microapps/" + pName + ".js", function(pName) { this.startApp(window[pName], pName); }.bind(this, pName));
}
}
}
setTheme(pSrc) {
var themeIMG = document.getElementsByClassName("themeIMG");
for (var i = 0; i < themeIMG.length; i++) {
themeIMG[i].src = pSrc;
}
}
exeFunction(pObj) {
this.app[pObj.call].apply(this.app, pObj.arg);
}
setInterval(func, interval) {
this.intervals.push(setInterval(func, interval));
}
}
function makeQR(pURL) {
document.getElementById("window").innerHTML += "<br><b>" + pURL + "</b>";
new QRCode(document.getElementById("qrcode"), pURL);
}
function connected() {
setTimeout(function(){remote.getGlobal('io').emit('openHome', '');},200);
//s.userConnected();
}
function startApp(pName) {
console.log("pName:");
console.log(pName);
s.startApp(window[pName], pName);
}
document.addEventListener("keydown", function(e) {
if (e.which === 123) {
remote.getCurrentWindow().toggleDevTools();
} else if (e.which === 116) {
location.reload();
}
});
var loadJS = function(url, implementationCode, location) {
//url is URL of external file, implementationCode is the code
//to be called from the file, location is the location to
//insert the <script> element
var scriptTag = document.createElement('script');
scriptTag.src = url;
scriptTag.onload = implementationCode;
scriptTag.onreadystatechange = implementationCode;
document.body.appendChild(scriptTag);
};
var s;
loadJS('microapps/Home.js', function() { s = new scrd(document); });