From 006c9ef975ed57aea8eb37c17e9c22be48f8bc02 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 6 Mar 2021 01:23:58 +0100 Subject: [PATCH] Move comms to ts (1/3) --- src/ext/lib/comms/Comms.js | 31 ------------------------------- src/ext/lib/comms/Comms.ts | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 31 deletions(-) delete mode 100644 src/ext/lib/comms/Comms.js create mode 100644 src/ext/lib/comms/Comms.ts diff --git a/src/ext/lib/comms/Comms.js b/src/ext/lib/comms/Comms.js deleted file mode 100644 index 1c5428b..0000000 --- a/src/ext/lib/comms/Comms.js +++ /dev/null @@ -1,31 +0,0 @@ -import Debug from '../../conf/Debug'; -import BrowserDetect from '../../conf/BrowserDetect'; - -if (process.env.CHANNEL !== 'stable'){ - console.info("Loading Comms"); -} - -class Comms { - static async sendMessage(message){ - - if(BrowserDetect.firefox){ - return browser.runtime.sendMessage(message); - } else { - return new Promise((resolve, reject) => { - 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); - return true; - }); - }); - } - } - -} - -if (process.env.CHANNEL !== 'stable'){ - console.info("Comms loaded"); -} - -export default Comms; diff --git a/src/ext/lib/comms/Comms.ts b/src/ext/lib/comms/Comms.ts new file mode 100644 index 0000000..a174d3c --- /dev/null +++ b/src/ext/lib/comms/Comms.ts @@ -0,0 +1,19 @@ +import Debug from '../../conf/Debug'; +import BrowserDetect from '../../conf/BrowserDetect'; +import { browser } from 'webextension-polyfill-ts'; + +if (process.env.CHANNEL !== 'stable'){ + console.info("Loading Comms"); +} + +class Comms { + static async sendMessage(message){ + browser.runtime.sendMessage(message); + } +} + +if (process.env.CHANNEL !== 'stable'){ + console.info("Comms loaded"); +} + +export default Comms;