Skip to content

Commit

Permalink
FXVPN-200: Fix missing connection health info (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleyjanenorton authored Nov 25, 2024
1 parent 2715649 commit 113fc40
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class Main {
this.proxyHandler,
this.vpnController
);
toolbarIconHandler = new ToolbarIconHandler(this, this.extController);
toolbarIconHandler = new ToolbarIconHandler(
this,
this.extController,
this.vpnController
);
tabReloader = new TabReloader(this, this.extController, this.proxyHandler);

async init() {
Expand Down
41 changes: 32 additions & 9 deletions src/background/toolbarIconHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,57 @@ export class ToolbarIconHandler extends Component {
* @param {*} receiver
* @param {ExtensionController} extController
*/
constructor(receiver, extController) {
constructor(receiver, extController, vpnController) {
super(receiver);
this.extController = extController;
this.vpnController = vpnController;
}

/** @type {FirefoxVPNState | undefined} */
extState;

vpnState;

async init() {
this.extController.state.subscribe((s) => {
this.extState = s;
this.maybeUpdateBrowserActionIcon();
});

this.vpnController.state.subscribe((s) => {
this.vpnState = s;
this.maybeUpdateBrowserActionIcon();
});

// Listen for darkmode/lightmode changes and update the browserAction icon
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
this.maybeUpdateBrowserActionIcon();
});

// Catch changes between private and non-private browsing windows
browser.windows.onFocusChanged.addListener(
this.maybeUpdateBrowserActionIcon.bind(this)
);

// Catch changes between private and non-private browsing modes
// when a new window is opened.
browser.windows.onCreated.addListener(
this.maybeUpdateBrowserActionIcon.bind(this)
);
}

setIcon(scheme, status, id) {
browser.browserAction.setIcon({
path: {
16: `./../assets/logos/browserAction/logo-${scheme}-${status}.svg`,
32: `./../assets/logos/browserAction/logo-${scheme}-${status}.svg`,
},
windowId: id,
});
}

async maybeUpdateBrowserActionIcon() {
const windowInfo = await browser.windows.getCurrent();
if (!windowInfo) {
Expand All @@ -61,16 +82,18 @@ export class ToolbarIconHandler extends Component {

const scheme = darkMode || windowInfo.incognito ? "light" : "dark";

const status = ["Connecting", "Enabled"].includes(this.extState.state)
let status = ["Connecting", "Enabled"].includes(this.extState.state)
? "enabled"
: "disabled";

browser.browserAction.setIcon({
path: {
16: `./../assets/logos/browserAction/logo-${scheme}-${status}.svg`,
32: `./../assets/logos/browserAction/logo-${scheme}-${status}.svg`,
},
windowId: windowInfo.id,
});
const stability = this.vpnState?.connectionHealth;

if (!stability || stability == "Stable") {
return this.setIcon(scheme, status, windowInfo.id);
}

status = stability === "Unstable" ? "unstable" : "disabled";

return this.setIcon(scheme, status, windowInfo.id);
}
}
4 changes: 2 additions & 2 deletions src/background/vpncontroller/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export class VPNState {
// True if it is authenticated
authenticated = false;
// Can be "Stable", "Unstable", "NoSignal"
connectionStability = "Stable";
connectionHealth = "Stable";

// True if the client version is post v2.23 but not latest
needsUpdate = false;

/**
* A socks:// url to connect to
* to bypass the vpn.
Expand Down
3 changes: 2 additions & 1 deletion src/background/vpncontroller/vpncontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ export function fromVPNStatusResponse(
return new StateVPNOnPartial(
exitServerCity,
exitServerCountry,
status.localProxy?.url
status.localProxy?.url,
status.connectionHealth
);
}
if (
Expand Down
2 changes: 1 addition & 1 deletion src/ui/browserAction/popupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class BrowserActionPopup extends LitElement {
.cityName=${this.vpnState?.exitServerCity?.name}
.countryFlag=${this.vpnState?.exitServerCountry?.code}
.connectedSince=${this.extState?.connectedSince}
.stability=${this.vpnState?.connectionStability}
.stability=${this.vpnState?.connectionHealth}
.hasContext=${this._siteContext}
.connecting=${this.extState?.connecting}
></vpn-card>
Expand Down

0 comments on commit 113fc40

Please sign in to comment.