Skip to content

Commit 24de1d5

Browse files
feat: enable consent dialog for only firefox (#137)
Enables the consent dialog (again) for only firefox. Wanted to get this working with .env files, but couldn't get it working cleanly. Open to ideas, but this is also fine and a probably simpler imo. --------- Co-authored-by: Elio Di Nino <[email protected]>
1 parent e51500c commit 24de1d5

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"main": "index.js",
66
"scripts": {
77
"dev": "webpack --config webpack/webpack.dev.js",
8-
"watch": "npm run dev -- --watch",
98
"firefox-manifest": "mv dist/manifest.firefox.json dist/manifest.json",
109
"set-version": "jq --arg v \"${VERSION:-$(git describe --tags --abbrev=0)}\" '.version = $v' dist/manifest.json > dist/manifest.tmp.json && mv dist/manifest.tmp.json dist/manifest.json",
1110
"build": "webpack --config webpack/webpack.prod.js && npm run set-version",
12-
"build:firefox": "npm run build && npm run firefox-manifest && npm run set-version",
11+
"build:firefox": "IS_FIREFOX=1 npm run build && npm run firefox-manifest && npm run set-version",
1312
"start:chrome": "npm run dev && web-ext run -s dist -t chromium --start-url https://github.com",
14-
"start:firefox": "npm run dev && npm run firefox-manifest && web-ext run -s dist -t firefox-desktop --start-url https://github.com",
13+
"start:firefox": "IS_FIREFOX=1 npm run dev && npm run firefox-manifest && web-ext run -s dist -t firefox-desktop --start-url https://github.com",
1514
"lint": "prettier --write \"src/**/*.{ts,tsx}\"",
1615
"archive": "tar -czvf ../codecov-browser-extension.tar.gz --exclude node_modules --exclude dist . && mv ../codecov-browser-extension.tar.gz ./codecov-browser-extension-${VERSION:-$(git describe --tags --abbrev=0)}.tar.gz"
1716
},

src/content/github/common/consent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { consentStorageKey, consentDialogCopy } from "./constants";
44
export async function ensureConsent(
55
{ checkOnly }: { checkOnly: boolean } = { checkOnly: false }
66
): Promise<boolean> {
7+
// We only need to get consent for firefox
8+
// @ts-ignore IS_FIREFOX is populated by Webpack at build time
9+
if (!IS_FIREFOX) {
10+
return true;
11+
}
12+
713
let consent: boolean = await chrome.storage.local
814
.get(consentStorageKey)
915
.then((res) => res[consentStorageKey]);

src/content/github/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// We must update the key's version to re-request consent whenever the data we collect changes.
33
export const consentStorageKey = "codecov-consent-0.5.9";
44
export const consentDialogCopy =
5-
"By clicking OK, you are authorizing the Codecov browser extension to collect your IP address and the URLs you visit on domains you've given the extension access to. Declining this will prevent the extension from working. For more information see the Privacy Policy in the Codecov extension store listing.";
5+
"By clicking OK, you agree to the Codecov browser extension's privacy policy (https://addons.mozilla.org/en-US/firefox/addon/codecov/privacy/). This message will reappear if you click Cancel. If you do not wish to agree, please uninstall the extension.";
66

77
export const animationName = "codecov-gh-observer";
88

src/content/github/file/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from "../common/fetchers";
3333
import { print } from "src/utils";
3434
import Sentry from "../../common/sentry";
35+
import { ensureConsent } from "../common/consent";
3536

3637
const globals: {
3738
coverageReport?: FileCoverageReport;
@@ -59,6 +60,11 @@ function init(): Promise<void> {
5960

6061
async function main(): Promise<void> {
6162
try {
63+
const consent = await ensureConsent();
64+
if (!consent) {
65+
return;
66+
}
67+
6268
const urlMetadata = getMetadataFromURL();
6369
if (!urlMetadata) {
6470
print("file not detected at current URL");

src/content/github/pr/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ import { print } from "src/utils";
1515
import { getPRReport } from "../common/fetchers";
1616
import { isPrUrl } from "../common/utils";
1717
import Sentry from "src/content/common/sentry";
18+
import { ensureConsent } from "../common/consent";
1819

1920
const globals: {
2021
coverageReport?: PullCoverageReport;
2122
} = {};
2223

2324
async function main() {
2425
try {
26+
const consent = await ensureConsent({ checkOnly: true });
27+
if (!consent) {
28+
return;
29+
}
30+
2531
document.addEventListener("soft-nav:end", execute);
2632
await execute();
2733
} catch (e) {

webpack/webpack.common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ module.exports = {
4242
extensions: [".ts", ".tsx", ".js"],
4343
},
4444
plugins: [
45+
new DefinePlugin({
46+
IS_FIREFOX: process.env.IS_FIREFOX ? true : false,
47+
}),
4548
new CopyPlugin({
4649
patterns: [{ from: ".", to: "../", context: "public" }],
4750
options: {},

0 commit comments

Comments
 (0)