Skip to content

Commit

Permalink
fix(app): startup due to lacking FontFace implementation in Firefox
Browse files Browse the repository at this point in the history
Source: #2432
Closes #2432
  • Loading branch information
ferferga committed Aug 21, 2024
1 parent 5849830 commit 2b8f533
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { createApp } from 'vue';
import { routes } from 'vue-router/auto-routes';
import { getFontFaces } from '@/utils/data-manipulation';
import Root from '@/App.vue';
import { hideDirective } from '@/plugins/directives';
import { vuePlugin as i18n } from '@/plugins/i18n';
Expand Down Expand Up @@ -44,7 +45,7 @@ app.directive('hide', hideDirective);
*/
await Promise.all([
router.isReady(),
...[...document.fonts.keys()].map(font => font.load())
...getFontFaces().map(font => font.load())
]);
await document.fonts.ready;

Expand Down
22 changes: 22 additions & 0 deletions frontend/src/utils/data-manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ export function mergeExcludingUnknown<T extends object, K extends keyof T>(
export function upperFirst<T extends string>(str: T): Capitalize<T> {
return (str[0].toUpperCase() + str.slice(1)) as Capitalize<T>;
}

/**
* Get the font faces present in the document.
*
* Instead of using a normal iterable (like `...[...document.fonts.keys()]`),
* we need this for Firefox compatibility.
*
* See https://github.com/jellyfin/jellyfin-vue/issues/2432
*/
export function getFontFaces() {
const iterable = document.fonts.keys();
const results = [];
let iterator = iterable.next();

while (iterator.done === false) {
results.push(iterator.value);

iterator = iterable.next();
}

return results;
}

0 comments on commit 2b8f533

Please sign in to comment.