Skip to content

Commit

Permalink
fix: undefined error when call permission query
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Oct 24, 2024
1 parent 3e3e795 commit f71a4cc
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,24 @@ function compareFontInfoDistance(a: FontDistance, b: FontDistance) {

async function checkLocalFontsPermission() {
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
return;
return false;
}

if (typeof window === 'undefined') {
return;
return false;
}
if (window.navigator == null || window.navigator?.permissions == null) {
return false;
}

const status = await window.navigator.permissions.query({ name: 'local-fonts' as PermissionName });
try {
const status = await window.navigator.permissions.query({ name: 'local-fonts' as PermissionName });

return status.state === 'granted';
return status.state === 'granted';
// eslint-disable-next-line unused-imports/no-unused-vars
} catch (_err) {
return false;
}
}

class FontLibrary {
Expand Down

0 comments on commit f71a4cc

Please sign in to comment.