2020-07-03 23:32:39 +02:00
|
|
|
import * as React from 'react';
|
2020-11-07 17:59:37 +02:00
|
|
|
import versionInfo from '@joplin/lib/versionInfo';
|
2021-04-24 19:30:48 +02:00
|
|
|
import PluginService from '@joplin/lib/services/plugins/PluginService';
|
|
|
|
import Setting from '@joplin/lib/models/Setting';
|
2021-04-24 20:23:33 +02:00
|
|
|
import bridge from '../services/bridge';
|
2020-08-02 17:21:30 +02:00
|
|
|
const packageInfo = require('../packageInfo.js');
|
|
|
|
const ipcRenderer = require('electron').ipcRenderer;
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2021-04-24 19:30:48 +02:00
|
|
|
interface ErrorInfo {
|
|
|
|
componentStack: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PluginInfo {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
enabled: boolean;
|
|
|
|
version: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
error: Error;
|
|
|
|
errorInfo: ErrorInfo;
|
|
|
|
pluginInfos: PluginInfo[];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Props {}
|
|
|
|
|
|
|
|
export default class ErrorBoundary extends React.Component<Props, State> {
|
|
|
|
|
|
|
|
public state: State = { error: null, errorInfo: null, pluginInfos: [] };
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2021-04-24 19:30:48 +02:00
|
|
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
|
|
const pluginInfos: PluginInfo[] = [];
|
|
|
|
try {
|
|
|
|
const service = PluginService.instance();
|
|
|
|
const pluginSettings = service.unserializePluginSettings(Setting.value('plugins.states'));
|
|
|
|
for (const pluginId in pluginSettings) {
|
|
|
|
const plugin = PluginService.instance().pluginById(pluginId);
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2021-04-24 19:30:48 +02:00
|
|
|
pluginInfos.push({
|
|
|
|
id: pluginId,
|
|
|
|
name: plugin.manifest.name,
|
|
|
|
enabled: pluginSettings[pluginId].enabled,
|
|
|
|
version: plugin.manifest.version,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Could not get plugin info:', error);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ error, errorInfo, pluginInfos });
|
2020-07-03 23:32:39 +02:00
|
|
|
}
|
|
|
|
|
2020-08-02 17:21:30 +02:00
|
|
|
componentDidMount() {
|
|
|
|
const onAppClose = () => {
|
|
|
|
ipcRenderer.send('asynchronous-message', 'appCloseReply', {
|
|
|
|
canClose: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ipcRenderer.on('appClose', onAppClose);
|
|
|
|
}
|
|
|
|
|
2020-07-03 23:32:39 +02:00
|
|
|
render() {
|
|
|
|
if (this.state.error) {
|
2021-04-24 20:23:33 +02:00
|
|
|
const safeMode_click = async () => {
|
|
|
|
Setting.setValue('isSafeMode', true);
|
|
|
|
await Setting.saveAll();
|
|
|
|
bridge().restart();
|
|
|
|
};
|
|
|
|
|
2020-07-03 23:32:39 +02:00
|
|
|
try {
|
|
|
|
const output = [];
|
2020-08-02 17:21:30 +02:00
|
|
|
|
|
|
|
output.push(
|
|
|
|
<section key="message">
|
|
|
|
<h2>Message</h2>
|
|
|
|
<p>{this.state.error.message}</p>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
|
|
|
|
output.push(
|
|
|
|
<section key="versionInfo">
|
|
|
|
<h2>Version info</h2>
|
|
|
|
<pre>{versionInfo(packageInfo).message}</pre>
|
|
|
|
</section>
|
|
|
|
);
|
2020-07-03 23:32:39 +02:00
|
|
|
|
2021-04-24 19:30:48 +02:00
|
|
|
if (this.state.pluginInfos.length) {
|
|
|
|
output.push(
|
|
|
|
<section key="pluginSettings">
|
|
|
|
<h2>Plugins</h2>
|
|
|
|
<pre>{JSON.stringify(this.state.pluginInfos, null, 4)}</pre>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-07-03 23:32:39 +02:00
|
|
|
if (this.state.error.stack) {
|
2020-08-02 17:21:30 +02:00
|
|
|
output.push(
|
|
|
|
<section key="stacktrace">
|
|
|
|
<h2>Stack trace</h2>
|
|
|
|
<pre>{this.state.error.stack}</pre>
|
|
|
|
</section>
|
|
|
|
);
|
2020-07-03 23:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.errorInfo) {
|
|
|
|
if (this.state.errorInfo.componentStack) {
|
2020-08-02 17:21:30 +02:00
|
|
|
output.push(
|
|
|
|
<section key="componentStack">
|
|
|
|
<h2>Component stack</h2>
|
|
|
|
<pre>{this.state.errorInfo.componentStack}</pre>
|
|
|
|
</section>
|
|
|
|
);
|
2020-07-03 23:32:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ overflow: 'auto', fontFamily: 'sans-serif', padding: '5px 20px' }}>
|
|
|
|
<h1>Error</h1>
|
|
|
|
<p>Joplin encountered a fatal error and could not continue. To report the error, please copy the *entire content* of this page and post it on Joplin forum or GitHub.</p>
|
2021-04-24 20:23:33 +02:00
|
|
|
<p>To continue you may close the app. Alternatively, if the error persists you may try to <a href="#" onClick={safeMode_click}>restart in safe mode</a>, which will temporarily disable all plugins.</p>
|
2020-07-03 23:32:39 +02:00
|
|
|
{output}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{JSON.stringify(this.state)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
}
|