Skip to content

Commit

Permalink
Upgrade roboto. Extension loads fonts from files instead of data URL.
Browse files Browse the repository at this point in the history
- Work around Firefox not loading font data URL sometimes due to
  respecting CSP. Instead we take advantage of the modified CSP that
  allows fetching extension resources (rather than modifying the CSP
  any further).
  • Loading branch information
killergerbah committed Apr 22, 2024
1 parent 4cc3aeb commit 0f4e056
Show file tree
Hide file tree
Showing 33 changed files with 164 additions and 68 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@craco/craco": "^6.4.3",
"@fontsource/roboto": "^4.5.0",
"@fontsource/roboto": "^5.0.13",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.57",
Expand Down
5 changes: 4 additions & 1 deletion client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import '@fontsource/roboto';
import '@fontsource/roboto/300.css';
import '@fontsource/roboto/400.css';
import '@fontsource/roboto/500.css';
import '@fontsource/roboto/700.css';
import { createRoot } from 'react-dom/client';
import reportWebVitals from './reportWebVitals';
import { HttpFetcher } from '@project/common';
Expand Down
1 change: 0 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"packageProdFirefox": "yarn buildProd --env firefox && ../scripts/package firefox"
},
"dependencies": {
"@fontsource/roboto": "^4.5.0",
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.57",
Expand Down
Binary file added extension/src/assets/Roboto-Bold.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-BoldItalic.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-Italic.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-Light.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-LightItalic.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-Medium.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-MediumItalic.woff2
Binary file not shown.
Binary file added extension/src/assets/Roboto-Regular.woff2
Binary file not shown.
63 changes: 63 additions & 0 deletions extension/src/assets/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 300;
font-display: swap;
src: url(/assets/Roboto-LightItalic.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 400;
font-display: swap;
src: url(/assets/Roboto-Italic.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 500;
font-display: swap;
src: url(/assets/Roboto-MediumItalic.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 700;
font-display: swap;
src: url(/assets/Roboto-BoldItalic.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 300;
font-display: swap;
src: url(/assets/Roboto-Light.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(/assets/Roboto-Regular.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 500;
font-display: swap;
src: url(/assets/Roboto-Medium.woff2) format('woff2');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 700;
font-display: swap;
src: url(/assets/Roboto-Bold.woff2) format('woff2');
}
31 changes: 18 additions & 13 deletions extension/src/controllers/anki-ui-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@ import { fetchLocalization } from '../services/localization-fetcher';
async function html(language: string) {
const mp3WorkerSource = await (await fetch(chrome.runtime.getURL('./mp3-encoder-worker.js'))).text();
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Anki</title>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(language))}</script>
<script id="mp3-encoder-worker" type="javascript/worker">${mp3WorkerSource}</script>
<script src="${chrome.runtime.getURL('./anki-ui.js')}"></script>
</body>
</html>`;
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Anki</title>
<style>
@import url(${chrome.runtime.getURL('./assets/fonts.css')});
</style>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(
await fetchLocalization(language)
)}</script>
<script id="mp3-encoder-worker" type="javascript/worker">${mp3WorkerSource}</script>
<script src="${chrome.runtime.getURL('./anki-ui.js')}"></script>
</body>
</html>`;
}

export default class AnkiUiController {
Expand Down
11 changes: 8 additions & 3 deletions extension/src/controllers/notification-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ export default class NotificationController {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer</title>
<style>
@import url(${chrome.runtime.getURL('./assets/fonts.css')});
</style>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(lang))}</script>
<script src="${chrome.runtime.getURL('./notification-ui.js')}"></script>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(
await fetchLocalization(lang)
)}</script>
<script src="${chrome.runtime.getURL('./notification-ui.js')}"></script>
</body>
</html>`
);
Expand Down
31 changes: 18 additions & 13 deletions extension/src/controllers/tab-anki-ui-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ import { fetchLocalization } from '../services/localization-fetcher';
async function html(language: string) {
const mp3WorkerSource = await (await fetch(chrome.runtime.getURL('./mp3-encoder-worker.js'))).text();
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Anki</title>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(language))}</script>
<script id="mp3-encoder-worker" type="javascript/worker">${mp3WorkerSource}</script>
<script src="${chrome.runtime.getURL('./anki-ui.js')}"></script>
</body>
</html>`;
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Anki</title>
<style>
@import url(${chrome.runtime.getURL('./assets/fonts.css')});
</style>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(
await fetchLocalization(language)
)}</script>
<script id="mp3-encoder-worker" type="javascript/worker">${mp3WorkerSource}</script>
<script src="${chrome.runtime.getURL('./anki-ui.js')}"></script>
</body>
</html>`;
}

export class TabAnkiUiController {
Expand Down
27 changes: 15 additions & 12 deletions extension/src/controllers/video-data-sync-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ import i18n from 'i18next';

async function html(lang: string) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Video Data Sync</title>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(lang))}</script>
<script src="${chrome.runtime.getURL('./video-data-sync-ui.js')}"></script>
</body>
</html>`;
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Video Data Sync</title>
<style>
@import url(${chrome.runtime.getURL('./assets/fonts.css')});
</style>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(lang))}</script>
<script src="${chrome.runtime.getURL('./video-data-sync-ui.js')}"></script>
</body>
</html>`;
}

interface ShowOptions {
Expand Down
9 changes: 6 additions & 3 deletions extension/src/controllers/video-select-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ export default class VideoSelectController {
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Video Select</title>
<style>
@import url(${chrome.runtime.getURL('./assets/fonts.css')});
</style>
</head>
<body>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(lang))}</script>
<script src="${chrome.runtime.getURL('./video-select-ui.js')}"></script>
<div id="root" style="width:100%;height:100vh;"></div>
<script type="application/json" id="loc">${JSON.stringify(await fetchLocalization(lang))}</script>
<script src="${chrome.runtime.getURL('./video-select-ui.js')}"></script>
</body>
</html>`
);
Expand Down
3 changes: 3 additions & 0 deletions extension/src/ftue-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Welcome</title>
<style>
@import url('assets/fonts.css');
</style>
</head>
<body style="background: rgba(0, 0, 0, 0)">
<div id="root"></div>
Expand Down
9 changes: 9 additions & 0 deletions extension/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
{
"resources": [
"assets/image.png",
"assets/fonts.css",
"assets/Roboto-Bold.woff2",
"assets/Roboto-Light.woff2",
"assets/Roboto-Medium.woff2",
"assets/Roboto-Regular.woff2",
"assets/Roboto-BoldItalic.woff2",
"assets/Roboto-LightItalic.woff2",
"assets/Roboto-MediumItalic.woff2",
"assets/Roboto-Italic.woff2",
"pages/netflix-page.js",
"pages/youtube-page.js",
"pages/tver-page.js",
Expand Down
3 changes: 3 additions & 0 deletions extension/src/mobile-video-overlay-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Mobile Video Overlay</title>
<style>
@import url('assets/fonts.css');
</style>
</head>
<body style="height: 100%">
<div id="root" style="position: absolute; left: 50%; transform: translate(-50%)"></div>
Expand Down
7 changes: 5 additions & 2 deletions extension/src/popup-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Popup</title>
<style>
@import url('assets/fonts.css');
</style>
</head>
<body style="background: rgba(0,0,0,0)">
<body style="background: rgba(0, 0, 0, 0)">
<div id="root"></div>
<script src="popup-ui.js"></script>
</body>
</html>
</html>
3 changes: 3 additions & 0 deletions extension/src/settings-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer - Settings</title>
<style>
@import url('assets/fonts.css');
</style>
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 3 additions & 0 deletions extension/src/side-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>asbplayer</title>
<style>
@import url('assets/fonts.css');
</style>
</head>
<body style="width: 100%; height: 100%">
<div id="root" style="width: 100%; height: 100%"></div>
Expand Down
1 change: 0 additions & 1 deletion extension/src/ui/anki/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@fontsource/roboto';
import React from 'react';
import { createRoot } from 'react-dom/client';
import Bridge from '../bridge';
Expand Down
1 change: 0 additions & 1 deletion extension/src/ui/ftue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@fontsource/roboto';
import { createRoot } from 'react-dom/client';
import FtueUi from '../components/FtueUi';

Expand Down
1 change: 0 additions & 1 deletion extension/src/ui/mobile-video-overlay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@fontsource/roboto';
import { createRoot } from 'react-dom/client';
import MobileVideoOverlay from '../components/MobileVideoOverlay';

Expand Down
1 change: 0 additions & 1 deletion extension/src/ui/notification/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@fontsource/roboto';
import { createRoot } from 'react-dom/client';
import Bridge from '../bridge';
import { i18nInit } from '../i18n';
Expand Down
2 changes: 0 additions & 2 deletions extension/src/ui/popup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '@fontsource/roboto';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { PopupUi } from '../components/PopupUi';
import { AsbplayerSettings } from '@project/common/settings';
Expand Down
2 changes: 0 additions & 2 deletions extension/src/ui/side-panel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';
import '@fontsource/roboto';
import { createRoot } from 'react-dom/client';
import SidePanelUi from '../components/SidePanelUi';

Expand Down
1 change: 0 additions & 1 deletion extension/src/ui/update/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@fontsource/roboto';
import { createRoot } from 'react-dom/client';
import UpdateUi from '../components/UpdateUi';

Expand Down
2 changes: 0 additions & 2 deletions extension/src/ui/video-data-sync/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '@fontsource/roboto';
import React from 'react';
import { createRoot } from 'react-dom/client';
import Bridge from '../bridge';
import VideoDataSyncUi from '../components/VideoDataSyncUi';
Expand Down
2 changes: 0 additions & 2 deletions extension/src/ui/video-select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '@fontsource/roboto';
import React from 'react';
import { createRoot } from 'react-dom/client';
import Bridge from '../bridge';
import VideoSelectUi from '../components/VideoSelectUi';
Expand Down
11 changes: 5 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2965,10 +2965,10 @@ __metadata:
languageName: node
linkType: hard

"@fontsource/roboto@npm:^4.5.0":
version: 4.5.5
resolution: "@fontsource/roboto@npm:4.5.5"
checksum: ab6675e04392ccd5def878762be67dbbf64f77c49c26030c6a1d03c34ce33045b0eb1199ad1bd3f398f362e5fa1fcbcbe25c18af8dda855ab43df45561eea569
"@fontsource/roboto@npm:^5.0.13":
version: 5.0.13
resolution: "@fontsource/roboto@npm:5.0.13"
checksum: a3ce1e090ec27ae3962c8c6fa5d53f622cee366ccd57514067e9bd612d79d7eb8440b396236e9e76bd2ea89b18cb08ab6d15dcc5cc198ccc8b92f7df0651a784
languageName: node
linkType: hard

Expand Down Expand Up @@ -3803,7 +3803,7 @@ __metadata:
resolution: "@project/client@workspace:client"
dependencies:
"@craco/craco": ^6.4.3
"@fontsource/roboto": ^4.5.0
"@fontsource/roboto": ^5.0.13
"@material-ui/core": ^4.11.3
"@material-ui/icons": ^4.11.2
"@material-ui/lab": ^4.0.0-alpha.57
Expand Down Expand Up @@ -3863,7 +3863,6 @@ __metadata:
"@babel/core": 7.14.5
"@babel/preset-env": ^7.14.5
"@babel/preset-react": ^7.14.5
"@fontsource/roboto": ^4.5.0
"@material-ui/core": ^4.11.3
"@material-ui/icons": ^4.11.2
"@material-ui/lab": ^4.0.0-alpha.57
Expand Down

0 comments on commit 0f4e056

Please sign in to comment.