From 6a1ece3c6036c9b9ff5fd303a7a5bb304cc1ec5d Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Thu, 13 Apr 2023 00:55:34 +0530 Subject: [PATCH 1/8] #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/8] #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(() => {}); From e984c2d6157a99140d31fa5809440d364490a673 Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 00:06:10 +0530 Subject: [PATCH 3/8] Fix message Signed-off-by: Rashmit Pankhania --- src/i18n/strings/en_EN.json | 2 +- src/utils/location/LocationShareErrors.ts | 2 +- test/components/views/location/LocationPicker-test.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 3e09f0d703b..96b9c5400bf 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -784,7 +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.", + "WebGL is requiredto display maps, please enable it in your browser settings.": "WebGL is requiredto display maps, 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 20e547d8e2e..dbbd8344d5e 100644 --- a/src/utils/location/LocationShareErrors.ts +++ b/src/utils/location/LocationShareErrors.ts @@ -29,7 +29,7 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st 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.") + return _t("WebGL is requiredto display maps, 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 f51292eb8ea..46a2f4898d2 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -127,7 +127,7 @@ describe("LocationPicker", () => { const { getByText } = getComponent(); - expect(getByText("WebGL is required for this site, please enable it in your browser settings.")).toBeInTheDocument(); + expect(getByText("WebGL is requiredto display maps, please enable it in your browser settings.")).toBeInTheDocument(); }); it("displays error when map setup throws", () => { From 64eac37c7940c1b9c8cdb52680cd96571ff8f060 Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 02:15:32 +0530 Subject: [PATCH 4/8] Fix ordering of cases in LocationShareErrors.ts Signed-off-by: Rashmit Pankhania --- src/i18n/strings/en_EN.json | 2 +- src/utils/location/LocationShareErrors.ts | 4 ++-- src/utils/location/map.ts | 2 ++ test/components/views/location/LocationPicker-test.tsx | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 20d437b46c8..9ea207a9148 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -784,7 +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 requiredto display maps, please enable it in your browser settings.": "WebGL is requiredto display maps, please enable it in your browser settings.", + "WebGL is required to display maps, please enable it in your browser settings.": "WebGL is required to display maps, 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 dbbd8344d5e..3c477842b2c 100644 --- a/src/utils/location/LocationShareErrors.ts +++ b/src/utils/location/LocationShareErrors.ts @@ -27,9 +27,9 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st switch (errorType) { case LocationShareError.MapStyleUrlNotConfigured: return _t("This homeserver is not configured to display maps."); - case LocationShareError.MapStyleUrlNotReachable: case LocationShareError.WebGLNotEnabled: - return _t("WebGL is requiredto display maps, please enable it in your browser settings.") + return _t("WebGL is required to display maps, please enable it in your browser settings.") + case LocationShareError.MapStyleUrlNotReachable: default: return _t( `This homeserver is not configured correctly to display maps, ` + diff --git a/src/utils/location/map.ts b/src/utils/location/map.ts index 8c8271f9c42..efaf2083187 100644 --- a/src/utils/location/map.ts +++ b/src/utils/location/map.ts @@ -57,6 +57,8 @@ export const createMap = (interactive: boolean, bodyId: string, onError?: (error return map; } catch (e) { logger.error("Failed to render map", e); + if (e.message.includes('Failed to initialize WebGL')) + throw new Error(LocationShareError.WebGLNotEnabled); throw e; } }; diff --git a/test/components/views/location/LocationPicker-test.tsx b/test/components/views/location/LocationPicker-test.tsx index 46a2f4898d2..c35d4d5a24f 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -127,7 +127,7 @@ describe("LocationPicker", () => { const { getByText } = getComponent(); - expect(getByText("WebGL is requiredto display maps, please enable it in your browser settings.")).toBeInTheDocument(); + expect(getByText("WebGL is required to display maps, please enable it in your browser settings.")).toBeInTheDocument(); }); it("displays error when map setup throws", () => { From 7ccdc717b7bf9fd11aaaf318a1b25e85001dcc37 Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 02:20:30 +0530 Subject: [PATCH 5/8] Fix linting LocationPicker.tsx Signed-off-by: Rashmit Pankhania --- src/components/views/location/LocationPicker.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index a12fb9b5eeb..783ac0fa7da 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -121,12 +121,12 @@ class LocationPicker extends React.Component { logger.error("Failed to render map", e); const errorMessage = (e as Error)?.message; let errorType; - if(errorMessage === LocationShareError.MapStyleUrlNotConfigured) + if (errorMessage === LocationShareError.MapStyleUrlNotConfigured) errorType = LocationShareError.MapStyleUrlNotConfigured; - else if(errorMessage.includes('Failed to initialize WebGL')) + else if (errorMessage.includes('Failed to initialize WebGL')) errorType = LocationShareError.WebGLNotEnabled; else errorType = LocationShareError.Default; - this.setState({ error: errorType }); + this.setState({error: errorType}); } } From ab1ab6910d4fc9c478c9bc5637b7e4050a484818 Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 14:49:40 +0530 Subject: [PATCH 6/8] Fix eslint Signed-off-by: Rashmit Pankhania --- src/components/views/location/LocationPicker.tsx | 4 ++-- src/utils/location/LocationShareErrors.ts | 2 +- src/utils/location/map.ts | 3 +-- test/components/views/location/LocationPicker-test.tsx | 4 +++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/views/location/LocationPicker.tsx b/src/components/views/location/LocationPicker.tsx index 783ac0fa7da..9660457099a 100644 --- a/src/components/views/location/LocationPicker.tsx +++ b/src/components/views/location/LocationPicker.tsx @@ -123,10 +123,10 @@ class LocationPicker extends React.Component { let errorType; if (errorMessage === LocationShareError.MapStyleUrlNotConfigured) errorType = LocationShareError.MapStyleUrlNotConfigured; - else if (errorMessage.includes('Failed to initialize WebGL')) + else if (errorMessage.includes("Failed to initialize WebGL")) errorType = LocationShareError.WebGLNotEnabled; else errorType = LocationShareError.Default; - this.setState({error: errorType}); + this.setState({ error: errorType }); } } diff --git a/src/utils/location/LocationShareErrors.ts b/src/utils/location/LocationShareErrors.ts index 3c477842b2c..a59c9295924 100644 --- a/src/utils/location/LocationShareErrors.ts +++ b/src/utils/location/LocationShareErrors.ts @@ -28,7 +28,7 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st case LocationShareError.MapStyleUrlNotConfigured: return _t("This homeserver is not configured to display maps."); case LocationShareError.WebGLNotEnabled: - return _t("WebGL is required to display maps, please enable it in your browser settings.") + return _t("WebGL is required to display maps, please enable it in your browser settings."); case LocationShareError.MapStyleUrlNotReachable: default: return _t( diff --git a/src/utils/location/map.ts b/src/utils/location/map.ts index efaf2083187..07dfcfa0974 100644 --- a/src/utils/location/map.ts +++ b/src/utils/location/map.ts @@ -57,8 +57,7 @@ export const createMap = (interactive: boolean, bodyId: string, onError?: (error return map; } catch (e) { logger.error("Failed to render map", e); - if (e.message.includes('Failed to initialize WebGL')) - throw new Error(LocationShareError.WebGLNotEnabled); + if (e.message.includes("Failed to initialize WebGL")) throw new Error(LocationShareError.WebGLNotEnabled); throw e; } }; diff --git a/test/components/views/location/LocationPicker-test.tsx b/test/components/views/location/LocationPicker-test.tsx index c35d4d5a24f..ed6dba95f06 100644 --- a/test/components/views/location/LocationPicker-test.tsx +++ b/test/components/views/location/LocationPicker-test.tsx @@ -127,7 +127,9 @@ describe("LocationPicker", () => { const { getByText } = getComponent(); - expect(getByText("WebGL is required to display maps, please enable it in your browser settings.")).toBeInTheDocument(); + expect( + getByText("WebGL is required to display maps, please enable it in your browser settings."), + ).toBeInTheDocument(); }); it("displays error when map setup throws", () => { From 7a937f4e0c7b96e1013548fd846dc0c18d7f4b8e Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 20:45:32 +0530 Subject: [PATCH 7/8] Fix file encoding for i18n CI issue Signed-off-by: Rashmit Pankhania --- src/i18n/strings/en_EN.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9ea207a9148..c163342f590 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -783,8 +783,8 @@ "No media permissions": "No media permissions", "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 to display maps, please enable it in your browser settings.": "WebGL is required to display maps, please enable it in your browser settings.", + "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.", "Toggle attribution": "Toggle attribution", "Map feedback": "Map feedback", "Enter fullscreen": "Enter fullscreen", From 37faa3721f9fda9bd89908ccc47940c62a6dde52 Mon Sep 17 00:00:00 2001 From: Rashmit Pankhania Date: Fri, 14 Apr 2023 21:09:47 +0530 Subject: [PATCH 8/8] Fix ts strict CI issue Signed-off-by: Rashmit Pankhania --- src/utils/location/map.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/location/map.ts b/src/utils/location/map.ts index 07dfcfa0974..061f5068c0d 100644 --- a/src/utils/location/map.ts +++ b/src/utils/location/map.ts @@ -57,7 +57,8 @@ export const createMap = (interactive: boolean, bodyId: string, onError?: (error return map; } catch (e) { logger.error("Failed to render map", e); - if (e.message.includes("Failed to initialize WebGL")) throw new Error(LocationShareError.WebGLNotEnabled); + const errorMessage = (e as Error)?.message; + if (errorMessage.includes("Failed to initialize WebGL")) throw new Error(LocationShareError.WebGLNotEnabled); throw e; } };