From 9819194ed72723b531c1a52bc0ee12a3a3598c81 Mon Sep 17 00:00:00 2001 From: Janek Schwarz Date: Fri, 11 Aug 2023 19:56:28 +0200 Subject: [PATCH] MOD: Extracted access to Border Color's api into a javascript module. --- identitypopup/popup.js | 14 +++----------- modules/bordercolorsapi.js | 23 +++++++++++++++++++++++ options/options.js | 14 +++----------- 3 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 modules/bordercolorsapi.js diff --git a/identitypopup/popup.js b/identitypopup/popup.js index 1fe91a4..d097d71 100644 --- a/identitypopup/popup.js +++ b/identitypopup/popup.js @@ -1,5 +1,6 @@ import { Options } from '../modules/options.js'; import { IcIdentities } from '../modules/identities.js'; +import { BorderColorsApi } from '../modules/bordercolorsapi.js'; class IdentitiesPopup { @@ -16,17 +17,8 @@ class IdentitiesPopup let identities = await icIdentities.getIdentities(); let identitiesList = document.getElementById("icIdentityList"); - let borderColors = null; - try { - let resp = await browser.runtime.sendMessage("bordercolors-d@addonsdev.mozilla.org", {command: "colors.all"}); - - if(resp) { - borderColors = resp; - } - } catch(error) { - // Border Colores not installed or otherwise available; eat the - // exception - } + let borderColorsApi = new BorderColorsApi(); + let borderColors = await borderColorsApi.getAllColors(); for(const identity of identities) { if(identity.showInMenu) { diff --git a/modules/bordercolorsapi.js b/modules/bordercolorsapi.js new file mode 100644 index 0000000..492a18e --- /dev/null +++ b/modules/bordercolorsapi.js @@ -0,0 +1,23 @@ +const EXTENSION_ID = "bordercolors-d@addonsdev.mozilla.org"; + +export class BorderColorsApi { + constructor() { + + } + + async getAllColors() { + let borderColors = null; + try { + let resp = await browser.runtime.sendMessage(EXTENSION_ID, + {command: "colors.all"}); + if(resp) { + borderColors = resp; + } + } catch(error) { + // Border Colores not installed or otherwise available; eat the + // exception + } + + return borderColors; + } +} diff --git a/options/options.js b/options/options.js index e146dd0..a49806e 100644 --- a/options/options.js +++ b/options/options.js @@ -1,5 +1,6 @@ import { Options } from '../modules/options.js'; import { IcIdentities } from '../modules/identities.js'; +import { BorderColorsApi } from '../modules/bordercolorsapi.js'; class OptionsUI { constructor(options) { @@ -59,17 +60,8 @@ class OptionsUI { } } - let borderColors = null; - try { - let resp = await browser.runtime.sendMessage("bordercolors-d@addonsdev.mozilla.org", {command: "colors.all"}); - - if(resp) { - borderColors = resp; - } - } catch(error) { - // Border Colores not installed or otherwise available; eat the - // exception - } + let borderColorsApi = new BorderColorsApi(); + let borderColors = await borderColorsApi.getAllColors(); console.debug("OptionsUI#updateUI: populate identity sort list"); var icIdentities = new IcIdentities(this.optionsBackend);