-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
43 lines (37 loc) · 1.32 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
/**
* index.js - Loads the macrozilla adapter and api-handler.
*/
'use strict';
const jsonDefaults = require('json-schema-defaults');
const Database = require('gateway-addon').Database;
const DBHandler = require('./lib/db-handler');
const MacroHandler = require('./lib/macro-handler');
const EventHandler = require('./lib/event-handler');
const APIHandler = require('./lib/api-handler');
const Adapter = require('./lib/adapter');
const manifest = require('./manifest.json');
class Macrozilla {
constructor(addonManager) {
this.packageName = manifest.id;
this.addonManager = addonManager;
this.eventhandler = new EventHandler(this);
this.addondb = new Database(this.packageName);
this.addondb.open().then(() => {
return this.addondb.loadConfig();
}).then((config) => {
this.config = Object.assign({}, jsonDefaults(manifest.options), config);
this.dbhandler = new DBHandler(this);
return this.dbhandler.open();
}).then(() => {
return this.dbhandler.init();
}).then(() => {
this.apihandler = new APIHandler(addonManager, this);
this.adapter = new Adapter(addonManager, this);
this.macrohandler = new MacroHandler(this);
return this.macrohandler.init();
}).catch(console.error);
}
}
module.exports = (addonManager) => {
new Macrozilla(addonManager);
};