diff options
Diffstat (limited to 'src/components/services/content/ServiceView.js')
-rw-r--r-- | src/components/services/content/ServiceView.js | 73 |
1 files changed, 11 insertions, 62 deletions
diff --git a/src/components/services/content/ServiceView.js b/src/components/services/content/ServiceView.js index d91016c71..444d5fea4 100644 --- a/src/components/services/content/ServiceView.js +++ b/src/components/services/content/ServiceView.js | |||
@@ -1,6 +1,6 @@ | |||
1 | import React, { Component, Fragment } from 'react'; | 1 | import React, { Component, Fragment } from 'react'; |
2 | import PropTypes from 'prop-types'; | 2 | import PropTypes from 'prop-types'; |
3 | import { autorun, reaction } from 'mobx'; | 3 | import { autorun } from 'mobx'; |
4 | import { observer, inject } from 'mobx-react'; | 4 | import { observer, inject } from 'mobx-react'; |
5 | import classnames from 'classnames'; | 5 | import classnames from 'classnames'; |
6 | 6 | ||
@@ -27,11 +27,7 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
27 | stores: PropTypes.shape({ | 27 | stores: PropTypes.shape({ |
28 | settings: PropTypes.instanceOf(SettingsStore).isRequired, | 28 | settings: PropTypes.instanceOf(SettingsStore).isRequired, |
29 | }).isRequired, | 29 | }).isRequired, |
30 | actions: PropTypes.shape({ | 30 | isSpellcheckerEnabled: PropTypes.bool.isRequired, |
31 | service: PropTypes.shape({ | ||
32 | setHibernation: PropTypes.func.isRequired, | ||
33 | }).isRequired, | ||
34 | }).isRequired, | ||
35 | }; | 31 | }; |
36 | 32 | ||
37 | static defaultProps = { | 33 | static defaultProps = { |
@@ -50,12 +46,6 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
50 | 46 | ||
51 | forceRepaintTimeout = null; | 47 | forceRepaintTimeout = null; |
52 | 48 | ||
53 | constructor(props) { | ||
54 | super(props); | ||
55 | |||
56 | this.startHibernationTimer = this.startHibernationTimer.bind(this); | ||
57 | } | ||
58 | |||
59 | componentDidMount() { | 49 | componentDidMount() { |
60 | this.autorunDisposer = autorun(() => { | 50 | this.autorunDisposer = autorun(() => { |
61 | if (this.props.service.isActive) { | 51 | if (this.props.service.isActive) { |
@@ -65,32 +55,6 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
65 | }, 100); | 55 | }, 100); |
66 | } | 56 | } |
67 | }); | 57 | }); |
68 | |||
69 | reaction( | ||
70 | () => this.props.service.isActive, | ||
71 | () => { | ||
72 | if (!this.props.service.isActive && this.props.stores.settings.all.app.hibernate) { | ||
73 | // Service is inactive - start hibernation countdown | ||
74 | this.startHibernationTimer(); | ||
75 | } else { | ||
76 | if (this.hibernationTimer) { | ||
77 | // Service is active but we have an active hibernation timer: Clear timeout | ||
78 | clearTimeout(this.hibernationTimer); | ||
79 | } | ||
80 | |||
81 | // Service is active, wake up service from hibernation | ||
82 | this.props.actions.service.setHibernation({ | ||
83 | serviceId: this.props.service.id, | ||
84 | hibernating: false, | ||
85 | }); | ||
86 | } | ||
87 | }, | ||
88 | ); | ||
89 | |||
90 | // Start hibernation counter if we are in background | ||
91 | if (!this.props.service.isActive && this.props.stores.settings.all.app.hibernate) { | ||
92 | this.startHibernationTimer(); | ||
93 | } | ||
94 | } | 58 | } |
95 | 59 | ||
96 | componentWillUnmount() { | 60 | componentWillUnmount() { |
@@ -110,19 +74,6 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
110 | }); | 74 | }); |
111 | }; | 75 | }; |
112 | 76 | ||
113 | startHibernationTimer() { | ||
114 | const timerDuration = (Number(this.props.stores.settings.all.app.hibernationStrategy) || 300) * 1000; | ||
115 | |||
116 | const hibernationTimer = setTimeout(() => { | ||
117 | this.props.actions.service.setHibernation({ | ||
118 | serviceId: this.props.service.id, | ||
119 | hibernating: true, | ||
120 | }); | ||
121 | }, timerDuration); | ||
122 | |||
123 | this.hibernationTimer = hibernationTimer; | ||
124 | } | ||
125 | |||
126 | render() { | 77 | render() { |
127 | const { | 78 | const { |
128 | detachService, | 79 | detachService, |
@@ -132,6 +83,7 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
132 | edit, | 83 | edit, |
133 | enable, | 84 | enable, |
134 | stores, | 85 | stores, |
86 | isSpellcheckerEnabled, | ||
135 | } = this.props; | 87 | } = this.props; |
136 | 88 | ||
137 | const { | 89 | const { |
@@ -193,22 +145,19 @@ export default @inject('stores', 'actions') @observer class ServiceView extends | |||
193 | </Fragment> | 145 | </Fragment> |
194 | ) : ( | 146 | ) : ( |
195 | <> | 147 | <> |
196 | {(!service.isHibernating || service.disableHibernation) ? ( | 148 | {(!service.isHibernating || service.isHibernationEnabled) ? ( |
197 | <> | 149 | <> |
198 | {showNavBar && ( | 150 | {showNavBar && ( |
199 | <WebControlsScreen service={service} /> | 151 | <WebControlsScreen service={service} /> |
200 | )} | 152 | )} |
201 | <ServiceWebview | 153 | {!service.isHibernating && ( |
202 | service={service} | 154 | <ServiceWebview |
203 | setWebviewReference={setWebviewReference} | 155 | service={service} |
204 | detachService={detachService} | 156 | setWebviewReference={setWebviewReference} |
205 | /> | 157 | detachService={detachService} |
206 | {/* {service.lostRecipeConnection && ( | 158 | isSpellcheckerEnabled={isSpellcheckerEnabled} |
207 | <ConnectionLostBanner | ||
208 | name={service.name} | ||
209 | reload={reload} | ||
210 | /> | 159 | /> |
211 | )} */} | 160 | )} |
212 | </> | 161 | </> |
213 | ) : ( | 162 | ) : ( |
214 | <div> | 163 | <div> |