Browse Source

fix: Fixed issue with icon font with safari

pull/6490/head
Muhammed Mustafa 1 year ago
parent
commit
8926a9d7de
  1. 30
      packages/nc-gui/plugins/font.ts

30
packages/nc-gui/plugins/font.ts

@ -10,12 +10,12 @@ export default defineNuxtPlugin(() => {
const fontFaces = [...document.fonts.values()]
const materialFont = fontFaces.find((fontFace) => fontFace.family === 'Material Symbols')
if (!materialFont || !materialFont?.loaded) {
if (!materialFont || !materialFont.loaded) {
document.documentElement?.classList.remove('nc-fonts-not-loaded')
return
}
materialFont?.loaded
materialFont.loaded
.then(function () {
document.documentElement?.classList.remove('nc-fonts-not-loaded')
})
@ -23,6 +23,32 @@ export default defineNuxtPlugin(() => {
document.documentElement?.classList.remove('nc-fonts-not-loaded')
console.error(error)
})
// Safari issue where loaded promise is always in pending state.
// So we need to poll for font status to be 'unloaded'
let intervalId: any
function poll() {
const fontFaces = [...document.fonts.values()]
const materialFont = fontFaces.find((fontFace) => fontFace.family === 'Material Symbols')
if (materialFont?.status === 'unloaded') {
document.documentElement?.classList.remove('nc-fonts-not-loaded')
stopPolling()
} else if (materialFont?.status === 'loaded') {
stopPolling()
}
}
function startPolling(interval: number) {
intervalId = setInterval(poll, interval)
}
function stopPolling() {
clearInterval(intervalId)
}
startPolling(200)
} catch (error) {
document.documentElement?.classList.remove('nc-fonts-not-loaded')
console.error(error)

Loading…
Cancel
Save