2021-03-06 09:30:16 +01:00
|
|
|
import Logger from "common/logger";
|
|
|
|
import {React, IPC} from "modules";
|
2020-11-03 02:47:08 +01:00
|
|
|
|
2020-07-16 07:42:56 +02:00
|
|
|
export default class ErrorBoundary extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {hasError: false};
|
|
|
|
}
|
|
|
|
|
2020-07-23 22:51:58 +02:00
|
|
|
componentDidCatch() {
|
2020-07-16 07:42:56 +02:00
|
|
|
this.setState({hasError: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-03-06 09:30:16 +01:00
|
|
|
if (this.state.hasError) return <div onClick={() => IPC.openDevTools()} className="react-error">There was an unexpected Error. Click to open console for more details.</div>;
|
2020-07-16 07:42:56 +02:00
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const originalRender = ErrorBoundary.prototype.render;
|
|
|
|
Object.defineProperty(ErrorBoundary.prototype, "render", {
|
|
|
|
enumerable: false,
|
|
|
|
configurable: false,
|
|
|
|
set: function() {Logger.warn("ErrorBoundary", "Addon policy for plugins #5 https://github.com/rauenzi/BetterDiscordApp/wiki/Addon-Policies#plugins");},
|
|
|
|
get: () => originalRender
|
|
|
|
});
|