Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Allow disconnect from 'Connecting', with limits. #147

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/background/extensionController/extensionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ExtensionController extends Component {
static properties = {
state: PropertyType.Bindable,
toggleConnectivity: PropertyType.Function,
allowDisconnect: PropertyType.Bindable,
};

/**
Expand All @@ -51,6 +52,14 @@ export class ExtensionController extends Component {
async init() {}

toggleConnectivity() {
if (
this.#mState.value.state === "Connecting" &&
this.clientState.state === "Disabled"
) {
this.#mState.set(new StateFirefoxVPNDisabled(true));
this.vpnController.postToApp("deactivate");
return;
}
if (this.#mState.value.enabled) {
// We are turning off the extension

Expand All @@ -73,6 +82,12 @@ export class ExtensionController extends Component {
}

this.#mState.set(new StateFirefoxVPNConnecting());

this.#mAllowDisconnect.value = false;
setTimeout(() => {
this.#mAllowDisconnect.value = true;
}, 10000);

// Send activation to client and wait for response
this.vpnController.postToApp("activate");
}
Expand All @@ -81,6 +96,10 @@ export class ExtensionController extends Component {
return this.#mState.readOnly;
}

get allowDisconnect() {
return this.#mAllowDisconnect.readOnly;
}

/**
*
* @param {VPNState} newClientState
Expand Down Expand Up @@ -137,5 +156,6 @@ export class ExtensionController extends Component {
}

#mState = property(new FirefoxVPNState());
#mAllowDisconnect = property(false);
mKeepAliveConnection = false;
}
12 changes: 12 additions & 0 deletions src/components/vpncard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class VPNCard extends LitElement {
stability: { type: String },
hasContext: { type: Boolean },
connecting: { type: Boolean },
allowDisconnect: { type: Boolean },
};

constructor() {
Expand All @@ -41,6 +42,7 @@ export class VPNCard extends LitElement {
this.connectedSince = 0;
this.stability = VPNState.Stable;
this.connecting = false;
this.allowDisconnect = false;
}
#intervalHandle = null;
#shieldElement = createRef();
Expand Down Expand Up @@ -79,6 +81,7 @@ export class VPNCard extends LitElement {
box: true,
on: this.enabled,
connecting: this.connecting,
allowDisconnect: this.allowDisconnect,
unstable: this.enabled && this.stability === VPNState.Unstable,
noSignal: this.enabled && this.stability === VPNState.NoSignal,
stable:
Expand Down Expand Up @@ -223,6 +226,15 @@ export class VPNCard extends LitElement {
background: var(--main-card-background);
box-shadow: var(--box-shadow-on);
}

.box.connecting .pill {
pointer-events: none;
}

.box.connecting.allowDisconnect .pill {
pointer-events: all;
opacity: 1;
}
main,
footer {
display: flex;
Expand Down
5 changes: 5 additions & 0 deletions src/ui/browserAction/popupPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class BrowserActionPopup extends LitElement {
_siteContext: { type: Object },
hasSiteContext: { type: Boolean },
_siteContexts: { type: Array },
allowDisconnect: { type: Boolean },
};

constructor() {
Expand All @@ -79,6 +80,9 @@ export class BrowserActionPopup extends LitElement {
this.updatePage();
});
this.updatePage();
extController.allowDisconnect.subscribe((s) => {
this.allowDisconnect = s;
});
}
updatePage() {
Utils.getCurrentTab().then(async (tab) => {
Expand Down Expand Up @@ -182,6 +186,7 @@ export class BrowserActionPopup extends LitElement {
.stability=${this.vpnState?.connectionHealth}
.hasContext=${this._siteContext}
.connecting=${this.extState?.connecting}
.allowDisconnect=${this.allowDisconnect}
></vpn-card>
${this.locationSettings()}
</main>
Expand Down
Loading