From 6a1ece3c6036c9b9ff5fd303a7a5bb304cc1ec5d Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Thu, 13 Apr 2023 00:55:34 +0530 Subject: [PATCH 1/2] #21451 Fix WebGl disabled error message --- src/components/views/location/LocationPicker.tsx | 11 +++++++---- src/i18n/strings/en_EN.json | 1 + src/utils/location/LocationShareErrors.ts | 3 +++ .../views/location/LocationPicker-test.tsx | 12 ++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index c012a1ab786..a12fb9b5eeb 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -119,10 +119,13 @@ class LocationPicker extends React.Component { } } catch (e) { logger.error("Failed to render map", e); - const errorType = - (e as Error)?.message === LocationShareError.MapStyleUrlNotConfigured - ? LocationShareError.MapStyleUrlNotConfigured - : LocationShareError.Default; + const errorMessage = (e as Error)?.message; + let errorType; + if(errorMessage === LocationShareError.MapStyleUrlNotConfigured) + errorType = LocationShareError.MapStyleUrlNotConfigured; + else if(errorMessage.includes('Failed to initialize WebGL')) + errorType = LocationShareError.WebGLNotEnabled; + else errorType = LocationShareError.Default; this.setState({ error: errorType }); } } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index dbf812d79a0..3e09f0d703b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -784,6 +784,7 @@ "You may need to manually permit %(brand)s to access your microphone/webcam": "You may need to manually permit %(brand)s to access your microphone/webcam", "This homeserver is not configured to display maps.": "This homeserver is not configured to display maps.", "This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.": "This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.", + "WebGL is required for this site, please enable it in your browser settings.": "WebGL is required for this site, please enable it in your browser settings.", "Toggle attribution": "Toggle attribution", "Map feedback": "Map feedback", "Enter fullscreen": "Enter fullscreen", diff --git a/src/utils/location/LocationShareErrors.ts b/src/utils/location/LocationShareErrors.ts index a7f34b42217..20e547d8e2e 100644 --- a/src/utils/location/LocationShareErrors.ts +++ b/src/utils/location/LocationShareErrors.ts @@ -19,6 +19,7 @@ import { _t } from "../../languageHandler"; export enum LocationShareError { MapStyleUrlNotConfigured = "MapStyleUrlNotConfigured", MapStyleUrlNotReachable = "MapStyleUrlNotReachable", + WebGLNotEnabled = "WebGLNotEnabled", Default = "Default", } @@ -27,6 +28,8 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st case LocationShareError.MapStyleUrlNotConfigured: return _t("This homeserver is not configured to display maps."); case LocationShareError.MapStyleUrlNotReachable: + case LocationShareError.WebGLNotEnabled: + return _t("WebGL is required for this site, please enable it in your browser settings.") default: return _t( `This homeserver is not configured correctly to display maps, ` + diff --git a/test/components/views/location/LocationPicker-test.tsx b/test/components/views/location/LocationPicker-test.tsx index 50b5af248f7..f51292eb8ea 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -118,6 +118,18 @@ describe("LocationPicker", () => { expect(getByText("This homeserver is not configured to display maps.")).toBeInTheDocument(); }); + it("displays error when WebGl is not enabled", () => { + // suppress expected error log + jest.spyOn(logger, "error").mockImplementation(() => {}); + mocked(findMapStyleUrl).mockImplementation(() => { + throw new Error("Failed to initialize WebGL"); + }); + + const { getByText } = getComponent(); + + expect(getByText("WebGL is required for this site, please enable it in your browser settings.")).toBeInTheDocument(); + }); + it("displays error when map setup throws", () => { // suppress expected error log jest.spyOn(logger, "error").mockImplementation(() => {}); From aef848b565fcba83320e25c83dcf53236b798d9f Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Thu, 13 Apr 2023 00:55:34 +0530 Subject: [PATCH 2/2] #21451 Fix WebGl disabled error message Signed-off-by: Rashmit Pankhania Signed-off-by: Rashmit Pankhania --- src/components/views/location/LocationPicker.tsx | 11 +++++++---- src/i18n/strings/en_EN.json | 1 + src/utils/location/LocationShareErrors.ts | 3 +++ .../views/location/LocationPicker-test.tsx | 12 ++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index c012a1ab786..a12fb9b5eeb 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -119,10 +119,13 @@ class LocationPicker extends React.Component { } } catch (e) { logger.error("Failed to render map", e); - const errorType = - (e as Error)?.message === LocationShareError.MapStyleUrlNotConfigured - ? LocationShareError.MapStyleUrlNotConfigured - : LocationShareError.Default; + const errorMessage = (e as Error)?.message; + let errorType; + if(errorMessage === LocationShareError.MapStyleUrlNotConfigured) + errorType = LocationShareError.MapStyleUrlNotConfigured; + else if(errorMessage.includes('Failed to initialize WebGL')) + errorType = LocationShareError.WebGLNotEnabled; + else errorType = LocationShareError.Default; this.setState({ error: errorType }); } } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index dbf812d79a0..3e09f0d703b 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -784,6 +784,7 @@ "You may need to manually permit %(brand)s to access your microphone/webcam": "You may need to manually permit %(brand)s to access your microphone/webcam", "This homeserver is not configured to display maps.": "This homeserver is not configured to display maps.", "This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.": "This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.", + "WebGL is required for this site, please enable it in your browser settings.": "WebGL is required for this site, please enable it in your browser settings.", "Toggle attribution": "Toggle attribution", "Map feedback": "Map feedback", "Enter fullscreen": "Enter fullscreen", diff --git a/src/utils/location/LocationShareErrors.ts b/src/utils/location/LocationShareErrors.ts index a7f34b42217..20e547d8e2e 100644 --- a/src/utils/location/LocationShareErrors.ts +++ b/src/utils/location/LocationShareErrors.ts @@ -19,6 +19,7 @@ import { _t } from "../../languageHandler"; export enum LocationShareError { MapStyleUrlNotConfigured = "MapStyleUrlNotConfigured", MapStyleUrlNotReachable = "MapStyleUrlNotReachable", + WebGLNotEnabled = "WebGLNotEnabled", Default = "Default", } @@ -27,6 +28,8 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st case LocationShareError.MapStyleUrlNotConfigured: return _t("This homeserver is not configured to display maps."); case LocationShareError.MapStyleUrlNotReachable: + case LocationShareError.WebGLNotEnabled: + return _t("WebGL is required for this site, please enable it in your browser settings.") default: return _t( `This homeserver is not configured correctly to display maps, ` + diff --git a/test/components/views/location/LocationPicker-test.tsx b/test/components/views/location/LocationPicker-test.tsx index 50b5af248f7..f51292eb8ea 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -118,6 +118,18 @@ describe("LocationPicker", () => { expect(getByText("This homeserver is not configured to display maps.")).toBeInTheDocument(); }); + it("displays error when WebGl is not enabled", () => { + // suppress expected error log + jest.spyOn(logger, "error").mockImplementation(() => {}); + mocked(findMapStyleUrl).mockImplementation(() => { + throw new Error("Failed to initialize WebGL"); + }); + + const { getByText } = getComponent(); + + expect(getByText("WebGL is required for this site, please enable it in your browser settings.")).toBeInTheDocument(); + }); + it("displays error when map setup throws", () => { // suppress expected error log jest.spyOn(logger, "error").mockImplementation(() => {});