From f71a4cca866336b1b1b3fb940ea0a72b6e6ef62a Mon Sep 17 00:00:00 2001 From: jocs Date: Thu, 24 Oct 2024 14:21:36 +0800 Subject: [PATCH] fix: undefined error when call permission query --- .../docs/layout/shaping-engine/font-library.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts b/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts index a165e674a90..19b4fb44413 100644 --- a/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts +++ b/packages/engine-render/src/components/docs/layout/shaping-engine/font-library.ts @@ -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 {