diff options
author | 2017-11-08 09:56:59 +0100 | |
---|---|---|
committer | 2017-11-08 09:56:59 +0100 | |
commit | 46d70c093c315386ea20b9c6e88af099508fb522 (patch) | |
tree | 9e1148d98476f864903900e819b509dfe12a7f14 /src/components/services/content/WebviewCrashHandler.js | |
parent | fix(App): Prevent app from redirecting when dropping link (diff) | |
parent | feature(Service): Add webview crash handler to display a user friendly message (diff) | |
download | ferdium-app-46d70c093c315386ea20b9c6e88af099508fb522.tar.gz ferdium-app-46d70c093c315386ea20b9c6e88af099508fb522.tar.zst ferdium-app-46d70c093c315386ea20b9c6e88af099508fb522.zip |
feat(Service): Add crash handler to display a user friendly message
(@dannyqiu)
Diffstat (limited to 'src/components/services/content/WebviewCrashHandler.js')
-rw-r--r-- | src/components/services/content/WebviewCrashHandler.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/components/services/content/WebviewCrashHandler.js b/src/components/services/content/WebviewCrashHandler.js new file mode 100644 index 000000000..24903f3c5 --- /dev/null +++ b/src/components/services/content/WebviewCrashHandler.js | |||
@@ -0,0 +1,81 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { observer } from 'mobx-react'; | ||
4 | import { defineMessages, intlShape } from 'react-intl'; | ||
5 | |||
6 | import Button from '../../ui/Button'; | ||
7 | |||
8 | const messages = defineMessages({ | ||
9 | headline: { | ||
10 | id: 'service.crashHandler.headline', | ||
11 | defaultMessage: '!!!Oh no!', | ||
12 | }, | ||
13 | text: { | ||
14 | id: 'service.crashHandler.text', | ||
15 | defaultMessage: '!!!{name} has caused an error.', | ||
16 | }, | ||
17 | action: { | ||
18 | id: 'service.crashHandler.action', | ||
19 | defaultMessage: '!!!Reload {name}', | ||
20 | }, | ||
21 | autoReload: { | ||
22 | id: 'service.crashHandler.autoReload', | ||
23 | defaultMessage: '!!!Trying to automatically restore {name} in {seconds} seconds', | ||
24 | }, | ||
25 | }); | ||
26 | |||
27 | @observer | ||
28 | export default class ServiceWebview extends Component { | ||
29 | static propTypes = { | ||
30 | name: PropTypes.string.isRequired, | ||
31 | reload: PropTypes.func.isRequired, | ||
32 | }; | ||
33 | |||
34 | static contextTypes = { | ||
35 | intl: intlShape, | ||
36 | }; | ||
37 | |||
38 | state = { | ||
39 | countdown: 10000, | ||
40 | } | ||
41 | |||
42 | componentDidMount() { | ||
43 | const { reload } = this.props; | ||
44 | |||
45 | this.countdownInterval = setInterval(() => { | ||
46 | this.setState({ | ||
47 | countdown: this.state.countdown - this.countdownIntervalTimeout, | ||
48 | }); | ||
49 | |||
50 | if (this.state.countdown <= 0) { | ||
51 | reload(); | ||
52 | clearInterval(this.countdownInterval); | ||
53 | } | ||
54 | }, this.countdownIntervalTimeout); | ||
55 | } | ||
56 | |||
57 | countdownInterval = null; | ||
58 | countdownIntervalTimeout = 1000; | ||
59 | |||
60 | render() { | ||
61 | const { name, reload } = this.props; | ||
62 | const { intl } = this.context; | ||
63 | |||
64 | return ( | ||
65 | <div className="services__crash-handler"> | ||
66 | <h1>{intl.formatMessage(messages.headline)}</h1> | ||
67 | <p>{intl.formatMessage(messages.text, { name })}</p> | ||
68 | <Button | ||
69 | // label={`Reload ${name}`} | ||
70 | label={intl.formatMessage(messages.action, { name })} | ||
71 | buttonType="inverted" | ||
72 | onClick={() => reload()} | ||
73 | /> | ||
74 | <p className="footnote">{intl.formatMessage(messages.autoReload, { | ||
75 | name, | ||
76 | seconds: this.state.countdown / 1000, | ||
77 | })}</p> | ||
78 | </div> | ||
79 | ); | ||
80 | } | ||
81 | } | ||