-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Here we: - Add butter bar lit component - Add ButterBarService which manages alerts that should be shown in the UI New strings in[ this PR](mozilla-l10n/mozilla-vpn-extension-l10n#2) https://github.com/user-attachments/assets/a5517eaf-11ea-4a90-87ef-eb9ba416871b
- Loading branch information
1 parent
986d3b2
commit fbe06b3
Showing
10 changed files
with
425 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// @ts-check | ||
import { Component } from "./component.js"; | ||
import { PropertyType } from "../shared/ipc.js"; | ||
|
||
import { IBindable, property } from "../shared/property.js"; | ||
import { VPNController } from "./vpncontroller/vpncontroller.js"; | ||
import { ConflictObserver } from "./conflictObserver.js"; | ||
|
||
/** | ||
* | ||
* ButterBarService manages 'Butter Bar' alerts shown | ||
* in the UI. | ||
*/ | ||
|
||
export class ButterBarService extends Component { | ||
// Gets exposed to UI | ||
static properties = { | ||
butterBarList: PropertyType.Bindable, | ||
removeAlert: PropertyType.Function, | ||
}; | ||
|
||
/** @type {IBindable<Array<ButterBarAlert>>} */ | ||
// List of alerts passed to the UI | ||
butterBarList = property([]); | ||
|
||
/** @type {Array<String>} */ | ||
// List of alert IDs that have been dismissed | ||
dismissedAlerts = []; | ||
|
||
/** | ||
* | ||
* @param {*} receiver | ||
* @param {VPNController} vpnController | ||
* @param {ConflictObserver} conflictObserver | ||
*/ | ||
constructor(receiver, vpnController, conflictObserver) { | ||
super(receiver); | ||
this.vpnController = vpnController; | ||
this.conflictObserver = conflictObserver; | ||
} | ||
|
||
async init() { | ||
console.log("Initializing ButterBarService"); | ||
await this.conflictObserver.updateList(); | ||
|
||
this.vpnController.interventions.subscribe((interventions) => { | ||
const alert = new ButterBarAlert( | ||
"conflictingProgram", | ||
"alert_conflictingProgram", | ||
"howToFix", | ||
"https://support.mozilla.org/kb/program-your-computer-interferes-mozilla-vpn-exten?utm_medium=mozilla-vpn&utm_source=vpn-extension" | ||
); | ||
this.maybeCreateAlert(interventions, alert); | ||
}); | ||
|
||
this.conflictObserver.conflictingAddons.subscribe((conflictingAddons) => { | ||
const alert = new ButterBarAlert( | ||
"alert_conflictingExtensions", | ||
"alert_conflictingExtensions", | ||
"learnWhatToDo", | ||
"https://support.mozilla.org/kb/if-another-extension-interferes-mozilla-vpn?utm_medium=mozilla-vpn&utm_source=vpn-extension" | ||
); | ||
|
||
this.maybeCreateAlert(conflictingAddons, alert); | ||
}); | ||
} | ||
/** | ||
* @param {Array} list | ||
* @param {ButterBarAlert} alert | ||
*/ | ||
maybeCreateAlert(list, alert) { | ||
if (list.length == 0) { | ||
return; | ||
} | ||
const { alertId } = alert; | ||
|
||
if ( | ||
this.alertWasDismissed(alertId, this.dismissedAlerts) || | ||
this.alertInButterBarList(alertId, this.butterBarList.value) | ||
) { | ||
return; | ||
} | ||
|
||
return this.butterBarList.value.push(alert); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
* @param {Array} dismissedAlerts | ||
*/ | ||
alertWasDismissed(id, dismissedAlerts) { | ||
return dismissedAlerts.some((alertId) => alertId == id); | ||
} | ||
|
||
/** | ||
* @param {string} id | ||
* @param {Array} butterBarList | ||
*/ | ||
alertInButterBarList(id, butterBarList) { | ||
return butterBarList.some((alert) => alert.alertId == id); | ||
} | ||
|
||
removeAlert(id) { | ||
const newAlertList = this.butterBarList.value.filter( | ||
({ alertId }) => alertId !== id | ||
); | ||
this.dismissedAlerts.push(id); | ||
this.butterBarList.set(newAlertList); | ||
return; | ||
} | ||
} | ||
|
||
export class ButterBarAlert { | ||
/** | ||
* @param {string} alertId | ||
* @param {string} alertMessage | ||
* @param {string} linkText | ||
* @param {string} linkUrl | ||
*/ | ||
constructor(alertId, alertMessage, linkText, linkUrl) { | ||
(this.alertId = alertId), | ||
(this.alertMessage = alertMessage), | ||
(this.linkText = linkText), | ||
(this.linkUrl = linkUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,10 @@ export class ConflictObserver { | |
* @returns {boolean} | ||
*/ | ||
static isConflicting(addon) { | ||
return addon.enabled && addon.permissions.includes("proxy"); | ||
return ( | ||
addon.enabled && | ||
addon.permissions.includes("proxy") && | ||
addon.id !== "[email protected]" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { html, LitElement, css } from "../vendor/lit-all.min.js"; | ||
import { ghostButtonStyles } from "../components/styles.js"; | ||
import { tr } from "../shared/i18n.js"; | ||
import { butterBarService } from "../../ui/browserAction/backend.js"; | ||
|
||
export class ButterBar extends LitElement { | ||
static properties = { | ||
alertId: { type: String }, | ||
alertMessage: { type: String }, | ||
linkText: { type: String }, | ||
linkUrl: { type: String }, | ||
}; | ||
|
||
constructor() { | ||
super(); | ||
this.alertId = ""; | ||
this.alertMessage = ""; | ||
this.linkText = ""; | ||
this.linkUrl = ""; | ||
} | ||
|
||
render() { | ||
const openLink = (url) => { | ||
browser.tabs.create({ url }); | ||
window.close(); | ||
}; | ||
|
||
const removeAlert = (id) => { | ||
butterBarService.removeAlert(id); | ||
this.dispatchEvent(new CustomEvent("resize-popup", { bubbles: true })); | ||
}; | ||
|
||
return html` | ||
<div class="butter-bar"> | ||
<div class="butter-bar-text"> | ||
<p> | ||
${tr(this.alertMessage)}<a | ||
href="" | ||
@click=${() => { | ||
openLink(this.linkUrl); | ||
}} | ||
>${tr(this.linkText)}</a | ||
> | ||
</p> | ||
</div> | ||
<button | ||
@click=${() => { | ||
removeAlert(this.alertId); | ||
}} | ||
class="butter-bar-close ghost-btn" | ||
> | ||
<img aria-hidden="true" src="./../../assets/img/close.svg" /> | ||
</button> | ||
</div> | ||
`; | ||
} | ||
|
||
static styles = css` | ||
${ghostButtonStyles} | ||
.butter-bar { | ||
margin-block-end: 16px; | ||
background: var(--grey10); | ||
border-radius: 4px; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
overflow: clip; | ||
width: 320px; | ||
word-wrap: anywhere; | ||
box-sizing: border-box; | ||
} | ||
.butter-bar-text { | ||
text-align: center; | ||
flex: 1; | ||
font-size: 13px; | ||
padding: 8px 16px; | ||
box-sizing: border-box; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
justify-items: center; | ||
box-sizing: border-box; | ||
width: 280px; | ||
} | ||
button.butter-bar-close.ghost-btn { | ||
inline-size: 40px; | ||
border: none; | ||
} | ||
button.butter-bar-close.ghost-btn::before { | ||
border-radius: 0px; | ||
} | ||
a { | ||
margin-inline-start: 5px; | ||
font-family: "Inter Semi Bold"; | ||
color: inherit; | ||
} | ||
a:hover { | ||
color: #000000; | ||
opacity: 1; | ||
transition: opacity 0.2s ease-in-out; | ||
} | ||
@media (prefers-color-scheme: dark) { | ||
.butter-bar { | ||
background: rgba(255, 255, 255, 0.02); | ||
} | ||
a:hover { | ||
opacity: 0.7; | ||
color: #ffffff; | ||
} | ||
a:active { | ||
opacity: 0.5; | ||
} | ||
img { | ||
filter: invert(); | ||
} | ||
} | ||
`; | ||
} | ||
customElements.define("butter-bar", ButterBar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.