2018-12-30 23:41:44 +01:00
|
|
|
import Debug from '../../conf/Debug';
|
|
|
|
import BrowserDetect from '../../conf/BrowserDetect';
|
|
|
|
|
|
|
|
class Comms {
|
|
|
|
static async sendMessage(message){
|
2019-01-20 20:36:24 +01:00
|
|
|
|
2018-12-30 23:41:44 +01:00
|
|
|
if(BrowserDetect.firefox){
|
|
|
|
return browser.runtime.sendMessage(message)
|
|
|
|
} else {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
try{
|
|
|
|
if(BrowserDetect.edge){
|
|
|
|
browser.runtime.sendMessage(message, function(response){
|
|
|
|
var r = response;
|
|
|
|
resolve(r);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
chrome.runtime.sendMessage(message, function(response){
|
|
|
|
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
|
|
|
|
var r = response;
|
|
|
|
resolve(r);
|
2019-05-09 21:07:40 +02:00
|
|
|
return true;
|
2018-12-30 23:41:44 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e){
|
|
|
|
reject(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Comms;
|