Skip to content

Commit

Permalink
MOD: Extracted access to Border Color's api into a javascript module.
Browse files Browse the repository at this point in the history
  • Loading branch information
speedball2001 committed Aug 11, 2023
1 parent 4520dcd commit 9819194
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
14 changes: 3 additions & 11 deletions identitypopup/popup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Options } from '../modules/options.js';
import { IcIdentities } from '../modules/identities.js';
import { BorderColorsApi } from '../modules/bordercolorsapi.js';

class IdentitiesPopup
{
Expand All @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions modules/bordercolorsapi.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 3 additions & 11 deletions options/options.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9819194

Please sign in to comment.