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);