diff options
Diffstat (limited to 'lib/main.js')
-rw-r--r-- | lib/main.js | 66 |
1 files changed, 63 insertions, 3 deletions
diff --git a/lib/main.js b/lib/main.js index fbabd41..35d7d60 100644 --- a/lib/main.js +++ b/lib/main.js @@ -13,10 +13,11 @@ "use strict"; var logger = require("logger"); var browser = require("tab-browser"); -var selfMod = require("self"); +var self = require("self"); var Request = require("request").Request; var preferences = require("preferences-service"); -var BTSPrefNS = require("bzpage").BTSPrefNS; +var pageMod = require("page-mod"); +// var BTSPrefNS = require("bzpage").BTSPrefNS; // Use my JSON for now before it is fixed for general public var JSONURLDefault = "https://fedorahosted.org/released"+ "/bugzilla-triage-scripts/Config_data.json"; @@ -87,7 +88,7 @@ function initialize(callback) { }, this); } - config.logger = new logger.Logger(JSON.parse(selfMod.data.load("bugzillalabelAbbreviations.json"))); + config.logger = new logger.Logger(JSON.parse(self.data.load("bugzillalabelAbbreviations.json"))); config.matches = config.gJSONData.configData.matches; config.skipMatches = config.matches.map(function(x) { @@ -108,6 +109,7 @@ function initialize(callback) { }).get(); } +/* exports.main = function main(options, callbacks) { initialize(function (config) { browser.whenContentLoaded( @@ -132,3 +134,61 @@ exports.main = function main(options, callbacks) { ); }); }; + +*/ +var messageHandler = exports.messageHandler = function messageHandler(worker, msg) { + switch (msg.cmd) { + case "LogMessage": + console.log(msg.data); + break; + case "GetDuplicatorID": + getDuplicatorID(msg.data.host, msg.data.bugID, function (msgObj) { + worker.postMessage(msgObj); + }); + break; + case "GetPassword": + getPassword(msg.data.login, msg.data.hostname, function (pass) { + worker.postMessage(pass); + }); + break; + case "DeDeduplicateQueue": + LoginData = { + queue: msg.data.bugs, + host: msg.data.hostname, + login: msg.data.login, + pass: msg.data.password, + dupID: msg.data.duplicator, + finalCallback: function (msgObj) { + worker.postMessage(msgObj); + } + }; + processReqQueue(); + break; + case "testReady": + // we ignore it here, interesting only in unit test + break; + default: + console.error(msg.toSource()); + } +}; + +var contentScriptLibraries = { + "bugzilla.redhat.com": [ + self.data.url("bzpage.js"), + self.data.url("rhbzpage.js") + ] +}; + +pageMod.PageMod({ + include: [ + "https://bugzilla.redhat.com/show_bug.cgi?id=*" + ], + contentScriptWhen: 'ready', + // contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"], + onAttach: function onAttach(worker, msg) { + console.log("worker: " + worker); + worker.on('message', function (msg) { + messageHandler(worker, msg); + }); + } +}); |