-
Notifications
You must be signed in to change notification settings - Fork 3
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
Butter bar alerts! 🧈 #146
Merged
Merged
Butter bar alerts! 🧈 #146
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
00f780a
Add butter bars and WIP alerts
lesleyjanenorton 8cc1131
Format
lesleyjanenorton b7ccb70
Consolidate/refactor
lesleyjanenorton 01d9f95
Format
lesleyjanenorton 870cf28
Type thangs
lesleyjanenorton 8f5d951
Update SUMO links
lesleyjanenorton 3aac7b8
Add tests
lesleyjanenorton ac74ba3
Update in-product butter bar links
lesleyjanenorton 328334c
Review fixes ++
lesleyjanenorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,129 @@ | ||
/* 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); | ||
return this.butterBarList.set(newAlertList); | ||
} | ||
} | ||
|
||
export class ButterBarAlert { | ||
/** | ||
* @param {string} alertId | ||
* @param {string} alertMessage | ||
* @param {string} linkText | ||
* @param {string} linkUrl | ||
*/ | ||
constructor(alertId, alertMessage, linkText, linkUrl) { | ||
(this.alertId = alertId), | ||
lesleyjanenorton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(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]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q__q oh wow how could i miss that. |
||
); | ||
} | ||
} |
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,120 @@ | ||
/* 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; | ||
} | ||
|
||
.butter-bar-text { | ||
text-align: center; | ||
flex: 1; | ||
font-size: 13px; | ||
padding: 8px 16px; | ||
} | ||
|
||
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property.set
returns void. Should this return a value?