-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.cpu.js
52 lines (49 loc) · 1.32 KB
/
background.cpu.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
/**
CPU - background
Dependency: core, events
**/
(function() {
var modulename = "background";
var Module = (function(modulename) {
function Module(options) {
this.name = modulename;
if (!options["cpu"]) {
console.log("Can't load module \"" + this.name + "\"! You need to pass the cpu object.");
return;
}
this.cpu = options["cpu"];
this.tasks = {};
}
Module.prototype.addUpdateListener = function(listner) {
this.cpu.module("events").addEventListener(this.name + ".update", listner);
};
Module.prototype.set = function(name, state) {
this.tasks[name] = state;
this.cpu.module("events").trigger(this.name + ".update");
};
Module.prototype.get = function(name) {
if (name) {
return this.tasks[name];
}
var working = false;
for (var k in this.tasks) {
if (this.tasks.hasOwnProperty(k)) {
if (this.tasks[k] === true) {
working = true;
break;
}
}
}
return working;
};
return Module;
})(modulename);
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = Module;
} else {
if (!window.cpumodules) {
window.cpumodules = {};
}
window.cpumodules[modulename] = Module;
}
})();