From 9e052a79b186547efd8eebc13cd96d8257352e78 Mon Sep 17 00:00:00 2001 From: Xander Frangos <33106561+xanderfrangos@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:25:46 -0500 Subject: [PATCH] Improved Settings window error handling, fixed minor errors --- src/components/SafeRender.jsx | 29 ++ src/components/SettingsWindow.jsx | 752 +++++++++++++++--------------- src/css/page.scss | 6 +- src/html/settings.html | 10 + 4 files changed, 418 insertions(+), 379 deletions(-) create mode 100644 src/components/SafeRender.jsx diff --git a/src/components/SafeRender.jsx b/src/components/SafeRender.jsx new file mode 100644 index 00000000..05a1f10e --- /dev/null +++ b/src/components/SafeRender.jsx @@ -0,0 +1,29 @@ +import React from "react"; + +export default class SafeRender extends React.Component { + constructor(props) { + super(props); + this.state = { hasError: false, error: "" }; + } + + static getDerivedStateFromError(error) { + return { hasError: true, error: error }; + } + + componentDidCatch(error, errorInfo) { + console.log(error) + this.setState({ + hasError: true, + error: error, + errorInfo: errorInfo?.componentStack + }) + } + + render() { + if (this.state.hasError) { + return (
Error: {JSON.stringify(this.state.error)}); + } + + return <>{this.props?.children}>; + } + } \ No newline at end of file diff --git a/src/components/SettingsWindow.jsx b/src/components/SettingsWindow.jsx index ebd960e7..8b76c077 100644 --- a/src/components/SettingsWindow.jsx +++ b/src/components/SettingsWindow.jsx @@ -17,6 +17,7 @@ import TranslateReact from "../TranslateReact" import MonitorInfo from "./MonitorInfo" import MonitorFeatures from "./MonitorFeatures" import { SettingsOption, SettingsChild } from "./SettingsOption"; +import SafeRender from "./SafeRender"; import DefaultIcon from "../assets/tray-icons/dark/icon@4x.png" import MDL2Icon from "../assets/tray-icons/dark/mdl2@4x.png" @@ -167,7 +168,7 @@ export default class SettingsWindow extends PureComponent { componentDidMount() { window.addEventListener("monitorsUpdated", this.recievedMonitors) window.addEventListener("settingsUpdated", this.recievedSettings) - window.addEventListener("localizationUpdated", (e) => { this.setState({ languages: e.detail.languages }); console.log(e.detail); T.setLocalizationData(e.detail.desired, e.detail.default) }) + window.addEventListener("localizationUpdated", (e) => { this.setState({ languages: e.detail.languages }); T.setLocalizationData(e.detail.desired, e.detail.default)}); window.addEventListener("windowHistory", e => this.setState({ windowHistory: e.detail })) if (window.isAppX === false) { @@ -197,6 +198,7 @@ export default class SettingsWindow extends PureComponent { } + onDragEnd(result) { // dropped outside the list if (!result.destination) { @@ -242,7 +244,6 @@ export default class SettingsWindow extends PureComponent { minMaxChanged = (value, slider) => { - console.log(value, slider, this.state.remaps) const name = slider.props.monitorID let remaps = Object.assign({}, this.state.remaps) @@ -544,7 +545,6 @@ export default class SettingsWindow extends PureComponent { return this.state.adjustmentTimes.map((time, index) => { let timeElem = ( { - console.log("OUTVAL", e.target.value) this.setAdjustmentTimeValue(index, e.target.value) }} value={time.time}> ) @@ -621,7 +621,6 @@ export default class SettingsWindow extends PureComponent { this.state.adjustmentTimes[index].monitors = {} } this.state.adjustmentTimes[index].monitors[monitor.id] = value - console.log(this.state.adjustmentTimes[index].monitors) this.forceUpdate(); this.adjustmentTimesUpdated() } @@ -629,7 +628,6 @@ export default class SettingsWindow extends PureComponent { setAdjustmentTimeValue = (index, arr) => { for (let i in arr) { - console.log(arr[i]) if (i < 2 && isNaN(arr[i])) return false; } this.state.adjustmentTimes[index].time = arr @@ -657,7 +655,6 @@ export default class SettingsWindow extends PureComponent { { e.preventDefault() - console.log(e.keyCode) let key = cleanUpKeyboardKeys(e.key, e.keyCode) if (this.downKeys[key] === undefined) { this.downKeys[key] = true; @@ -679,8 +676,8 @@ export default class SettingsWindow extends PureComponent { }> { hotkey.actions?.map((action, actionIdx) => { return ( -
{this.state.errorInfo}
+ Disabled: Do not show overlay.
+ Safe: The overlay will display over most windows, but will not force itself above apps that are marked as "always on top".
+ Aggressive: Always try to show the overlay on top of other windows. This can cause issues with exclusive fullscreen games and other fullscreen apps. It can also trigger anti-cheat in some games.
+
{T.t("SETTINGS_TIME_DESC")}
+
- Disabled: Do not show overlay.
- Safe: The overlay will display over most windows, but will not force itself above apps that are marked as "always on top".
- Aggressive: Always try to show the overlay on top of other windows. This can cause issues with exclusive fullscreen games and other fullscreen apps. It can also trigger anti-cheat in some games.
-
{T.t("SETTINGS_TIME_DESC")}
-{T.t("SETTINGS_MONITORS_NORMALIZE_DESC")}
- {this.getMinMaxMonitors()} -{T.t("SETTINGS_MONITORS_NORMALIZE_DESC")}
+ {this.getMinMaxMonitors()} +{T.t("SETTINGS_FEATURES_DESCRIPTION")}
- {this.getFeaturesMonitors()} -{T.t("SETTINGS_FEATURES_DESCRIPTION")}
+ {this.getFeaturesMonitors()} +{T.t("SETTINGS_HOTKEYS_DESC")}
+{T.t("SETTINGS_HOTKEYS_DESC")}
- -Automatically adjust the brightness or shortcut overlay behavior depending on the focused app. You can also add profiles to the right-click menu in the system tray to quickly change the brightness to pre-defined profiles.
+Automatically adjust the brightness or shortcut overlay behavior depending on the focused app. You can also add profiles to the right-click menu in the system tray to quickly change the brightness to pre-defined profiles.
-{T.h("SETTINGS_UPDATES_VERSION", '' + (window.version || "not available") + '')}
- {this.getUpdate()} -{JSON.stringify(this.state.rawSettings, undefined, 2)}
-{JSON.stringify(window.allMonitors, undefined, 2)}-
{T.h("SETTINGS_UPDATES_VERSION", '' + (window.version || "not available") + '')}
+ {this.getUpdate()} +{JSON.stringify(this.state.rawSettings, undefined, 2)}
+{JSON.stringify(window.allMonitors, undefined, 2)}+
Enter the VCP code for the feature you would like to add to your display. Please note that Twinkle Tray does not validate if your display actually supports this VCP code. Use at your own risk.
- - this.setState({ addFeatureValue: e.target.value })} onKeyUp={e => { - console.log(e) - if (e.which === 13 && this.state.addFeatureValue) { - // Enter - this.addFeatureOKRef.current.click() - } else if (e.which === 27) { - // Escape - this.addFeatureCancelRef.current.click() +Enter the VCP code for the feature you would like to add to your display. Please note that Twinkle Tray does not validate if your display actually supports this VCP code. Use at your own risk.
+ + this.setState({ addFeatureValue: e.target.value })} onKeyUp={e => { + if (e.which === 13 && this.state.addFeatureValue) { + // Enter + this.addFeatureOKRef.current.click() + } else if (e.which === 27) { + // Escape + this.addFeatureCancelRef.current.click() + } + }} /> +This feature is already active.
+This feature is already active.
-