From b0e0b6b66c029ae9e4aa4eaa9cbbcdf52c39e436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 29 Jan 2022 12:52:03 +0100 Subject: [PATCH 1/3] Add a console warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/MatrixChat.tsx | 33 ++++++++++++++++++++++++ src/i18n/strings/en_EN.json | 3 +++ 2 files changed, 36 insertions(+) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index e6b10aaea8d..1e0fc372551 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -447,6 +447,10 @@ export default class MatrixChat extends React.PureComponent { } } + public componentDidMount(): void { + window.addEventListener("resize", this.onWindowResized); + } + componentDidUpdate(prevProps, prevState) { if (this.shouldTrackPageChange(prevState, this.state)) { const durationMs = this.stopPageChangeTimer(); @@ -467,6 +471,7 @@ export default class MatrixChat extends React.PureComponent { this.fontWatcher.stop(); UIStore.destroy(); this.state.resizeNotifier.removeListener("middlePanelResized", this.dispatchTimelineResize); + window.removeEventListener("resize", this.onWindowResized); if (this.accountPasswordTimer !== null) clearTimeout(this.accountPasswordTimer); } @@ -501,6 +506,34 @@ export default class MatrixChat extends React.PureComponent { }); } + private onWindowResized = (): void => { + // XXX: This is a very unreliable way to detect whether or not the the devtools are open + this.warnInConsole(); + }; + + private warnInConsole(): void { + const largeFontSize = "50px"; + const normalFontSize = "15px"; + + const waitText = _t("Wait!"); + const scamText = _t( + "If someone told you to copy/paste something here, " + + "there is a high likelihood you're being scammed!", + ); + const devText = _t( + "If you know what you're doing, Element is open-source, " + + "be sure to check out our GitHub (https://github.com/vector-im/element-web/) " + + "and contribute!", + ); + + console.log( + `%c${waitText}\n%c${scamText}\n%c${devText}`, + `font-size:${largeFontSize}; color:blue;`, + `font-size:${normalFontSize}; color:red;`, + `font-size:${normalFontSize};`, + ); + } + private getFallbackHsUrl(): string { if (this.props.serverConfig?.isDefault) { return this.props.config.fallback_hs_url; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9861e92b732..7660c0f81d1 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3023,6 +3023,9 @@ "Private community": "Private community", "To view %(communityName)s, swap to communities in your preferences": "To view %(communityName)s, swap to communities in your preferences", "To join %(communityName)s, swap to communities in your preferences": "To join %(communityName)s, swap to communities in your preferences", + "Wait!": "Wait!", + "If someone told you to copy/paste something here, there is a high likelihood you're being scammed!": "If someone told you to copy/paste something here, there is a high likelihood you're being scammed!", + "If you know what you're doing, Element is open-source, be sure to check out our GitHub (https://github.com/vector-im/element-web/) and contribute!": "If you know what you're doing, Element is open-source, be sure to check out our GitHub (https://github.com/vector-im/element-web/) and contribute!", "Failed to reject invitation": "Failed to reject invitation", "Cannot create rooms in this community": "Cannot create rooms in this community", "You do not have permission to create rooms in this community.": "You do not have permission to create rooms in this community.", From a7dee16765af603e0125b9791f18abfa06f63a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 1 Feb 2022 17:54:13 +0100 Subject: [PATCH 2/3] Throttle `warnInConsole()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/MatrixChat.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 1e0fc372551..6588c521dc4 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -120,6 +120,8 @@ import AccessibleButton from "../views/elements/AccessibleButton"; import { ActionPayload } from "../../dispatcher/payloads"; import { SummarizedNotificationState } from "../../stores/notifications/SummarizedNotificationState"; +import { throttle } from "lodash"; + /** constants for MatrixChat.state.view */ export enum Views { // a special initial state which is only used at startup, while we are @@ -511,7 +513,7 @@ export default class MatrixChat extends React.PureComponent { this.warnInConsole(); }; - private warnInConsole(): void { + private warnInConsole = throttle((): void => { const largeFontSize = "50px"; const normalFontSize = "15px"; @@ -532,7 +534,7 @@ export default class MatrixChat extends React.PureComponent { `font-size:${normalFontSize}; color:red;`, `font-size:${normalFontSize};`, ); - } + }, 1000); private getFallbackHsUrl(): string { if (this.props.serverConfig?.isDefault) { From 14b7565a4b8f66c3076a54d88a8f62fd2567c38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 1 Feb 2022 17:59:21 +0100 Subject: [PATCH 3/3] Fix import order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/structures/MatrixChat.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 6588c521dc4..8327b5a3849 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -23,6 +23,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Screen as ScreenEvent } from "matrix-analytics-events/types/typescript/Screen"; import { defer, IDeferred, QueryDict } from "matrix-js-sdk/src/utils"; import { logger } from "matrix-js-sdk/src/logger"; +import { throttle } from "lodash"; // focus-visible is a Polyfill for the :focus-visible CSS pseudo-attribute used by _AccessibleButton.scss import 'focus-visible'; @@ -120,8 +121,6 @@ import AccessibleButton from "../views/elements/AccessibleButton"; import { ActionPayload } from "../../dispatcher/payloads"; import { SummarizedNotificationState } from "../../stores/notifications/SummarizedNotificationState"; -import { throttle } from "lodash"; - /** constants for MatrixChat.state.view */ export enum Views { // a special initial state which is only used at startup, while we are