aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/services
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-09-25 11:54:21 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-09-25 11:54:21 +0200
commit666ec21ac9e905ac4e56c177d84f5716de9eb0fd (patch)
tree219ff3a5cbad4b06cddfc0df03848304ffbc67f7 /src/components/services
parentMerge branch 'master' of https://github.com/getferdi/ferdi (diff)
downloadferdium-app-666ec21ac9e905ac4e56c177d84f5716de9eb0fd.tar.gz
ferdium-app-666ec21ac9e905ac4e56c177d84f5716de9eb0fd.tar.zst
ferdium-app-666ec21ac9e905ac4e56c177d84f5716de9eb0fd.zip
Implement #75
Diffstat (limited to 'src/components/services')
-rw-r--r--src/components/services/content/ServiceView.js74
1 files changed, 66 insertions, 8 deletions
diff --git a/src/components/services/content/ServiceView.js b/src/components/services/content/ServiceView.js
index 59d1c1dc3..c45acc961 100644
--- a/src/components/services/content/ServiceView.js
+++ b/src/components/services/content/ServiceView.js
@@ -1,8 +1,9 @@
1import React, { Component, Fragment } from 'react'; 1import React, { Component, Fragment } from 'react';
2import PropTypes from 'prop-types'; 2import PropTypes from 'prop-types';
3import { autorun } from 'mobx'; 3import { autorun, reaction } from 'mobx';
4import { observer } from 'mobx-react'; 4import { observer, inject } from 'mobx-react';
5import classnames from 'classnames'; 5import classnames from 'classnames';
6import ms from 'ms';
6 7
7import ServiceModel from '../../../models/Service'; 8import ServiceModel from '../../../models/Service';
8import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl'; 9import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl';
@@ -11,8 +12,9 @@ import WebviewCrashHandler from './WebviewCrashHandler';
11import WebviewErrorHandler from './ErrorHandlers/WebviewErrorHandler'; 12import WebviewErrorHandler from './ErrorHandlers/WebviewErrorHandler';
12import ServiceDisabled from './ServiceDisabled'; 13import ServiceDisabled from './ServiceDisabled';
13import ServiceWebview from './ServiceWebview'; 14import ServiceWebview from './ServiceWebview';
15import SettingsStore from '../../../stores/SettingsStore';
14 16
15export default @observer class ServiceView extends Component { 17export default @observer @inject('stores') class ServiceView extends Component {
16 static propTypes = { 18 static propTypes = {
17 service: PropTypes.instanceOf(ServiceModel).isRequired, 19 service: PropTypes.instanceOf(ServiceModel).isRequired,
18 setWebviewReference: PropTypes.func.isRequired, 20 setWebviewReference: PropTypes.func.isRequired,
@@ -21,6 +23,9 @@ export default @observer class ServiceView extends Component {
21 edit: PropTypes.func.isRequired, 23 edit: PropTypes.func.isRequired,
22 enable: PropTypes.func.isRequired, 24 enable: PropTypes.func.isRequired,
23 isActive: PropTypes.bool, 25 isActive: PropTypes.bool,
26 stores: PropTypes.shape({
27 settings: PropTypes.instanceOf(SettingsStore).isRequired,
28 }).isRequired,
24 }; 29 };
25 30
26 static defaultProps = { 31 static defaultProps = {
@@ -31,12 +36,20 @@ export default @observer class ServiceView extends Component {
31 forceRepaint: false, 36 forceRepaint: false,
32 targetUrl: '', 37 targetUrl: '',
33 statusBarVisible: false, 38 statusBarVisible: false,
39 hibernate: false,
40 hibernationTimer: null,
34 }; 41 };
35 42
36 autorunDisposer = null; 43 autorunDisposer = null;
37 44
38 forceRepaintTimeout = null; 45 forceRepaintTimeout = null;
39 46
47 constructor(props) {
48 super(props);
49
50 this.startHibernationTimer = this.startHibernationTimer.bind(this);
51 }
52
40 componentDidMount() { 53 componentDidMount() {
41 this.autorunDisposer = autorun(() => { 54 this.autorunDisposer = autorun(() => {
42 if (this.props.service.isActive) { 55 if (this.props.service.isActive) {
@@ -46,6 +59,31 @@ export default @observer class ServiceView extends Component {
46 }, 100); 59 }, 100);
47 } 60 }
48 }); 61 });
62
63 reaction(
64 () => this.props.service.isActive,
65 () => {
66 if (!this.props.service.isActive && this.props.stores.settings.all.app.hibernate) {
67 // Service is inactive - start hibernation countdown
68 this.startHibernationTimer();
69 } else {
70 if (this.state.hibernationTimer) {
71 // Service is active but we have an active hibernation timer: Clear timeout
72 clearTimeout(this.state.hibernationTimer);
73 }
74
75 // Service is active, wake up service from hibernation
76 this.setState({
77 hibernate: false,
78 });
79 }
80 },
81 );
82
83 // Start hibernation counter if we are in background
84 if (!this.props.service.isActive && this.props.stores.settings.all.app.hibernate) {
85 this.startHibernationTimer();
86 }
49 } 87 }
50 88
51 componentWillUnmount() { 89 componentWillUnmount() {
@@ -64,6 +102,18 @@ export default @observer class ServiceView extends Component {
64 }); 102 });
65 }; 103 };
66 104
105 startHibernationTimer() {
106 const hibernationTimer = setTimeout(() => {
107 this.setState({
108 hibernate: true,
109 });
110 }, ms('5m'));
111
112 this.setState({
113 hibernationTimer,
114 });
115 }
116
67 render() { 117 render() {
68 const { 118 const {
69 detachService, 119 detachService,
@@ -127,11 +177,19 @@ export default @observer class ServiceView extends Component {
127 </Fragment> 177 </Fragment>
128 ) : ( 178 ) : (
129 <> 179 <>
130 <ServiceWebview 180 {!this.state.hibernate ? (
131 service={service} 181 <ServiceWebview
132 setWebviewReference={setWebviewReference} 182 service={service}
133 detachService={detachService} 183 setWebviewReference={setWebviewReference}
134 /> 184 detachService={detachService}
185 />
186 ) : (
187 <div>
188 <span role="img" aria-label="Sleeping Emoji">😴</span>
189 {' '}
190This service is currently hibernating. If this page doesn&#x27;t close soon, please try reloading Ferdi.
191 </div>
192 )}
135 </> 193 </>
136 )} 194 )}
137 {statusBar} 195 {statusBar}