diff options
Diffstat (limited to 'src/components/services')
-rw-r--r-- | src/components/services/content/ServiceDisabled.js | 48 | ||||
-rw-r--r-- | src/components/services/content/ServiceWebview.js | 56 | ||||
-rw-r--r-- | src/components/services/content/Services.js | 9 | ||||
-rw-r--r-- | src/components/services/content/WebviewCrashHandler.js | 2 | ||||
-rw-r--r-- | src/components/services/tabs/TabBarSortableList.js | 3 | ||||
-rw-r--r-- | src/components/services/tabs/TabItem.js | 11 | ||||
-rw-r--r-- | src/components/services/tabs/Tabbar.js | 15 |
7 files changed, 117 insertions, 27 deletions
diff --git a/src/components/services/content/ServiceDisabled.js b/src/components/services/content/ServiceDisabled.js new file mode 100644 index 000000000..732b6c003 --- /dev/null +++ b/src/components/services/content/ServiceDisabled.js | |||
@@ -0,0 +1,48 @@ | |||
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.disabledHandler.headline', | ||
11 | defaultMessage: '!!!{name} is disabled', | ||
12 | }, | ||
13 | action: { | ||
14 | id: 'service.disabledHandler.action', | ||
15 | defaultMessage: '!!!Enable {name}', | ||
16 | }, | ||
17 | }); | ||
18 | |||
19 | @observer | ||
20 | export default class ServiceDisabled extends Component { | ||
21 | static propTypes = { | ||
22 | name: PropTypes.string.isRequired, | ||
23 | enable: PropTypes.func.isRequired, | ||
24 | }; | ||
25 | |||
26 | static contextTypes = { | ||
27 | intl: intlShape, | ||
28 | }; | ||
29 | |||
30 | countdownInterval = null; | ||
31 | countdownIntervalTimeout = 1000; | ||
32 | |||
33 | render() { | ||
34 | const { name, enable } = this.props; | ||
35 | const { intl } = this.context; | ||
36 | |||
37 | return ( | ||
38 | <div className="services__crash-handler"> | ||
39 | <h1>{intl.formatMessage(messages.headline, { name })}</h1> | ||
40 | <Button | ||
41 | label={intl.formatMessage(messages.action, { name })} | ||
42 | buttonType="inverted" | ||
43 | onClick={() => enable()} | ||
44 | /> | ||
45 | </div> | ||
46 | ); | ||
47 | } | ||
48 | } | ||
diff --git a/src/components/services/content/ServiceWebview.js b/src/components/services/content/ServiceWebview.js index cd59e0a8a..a71017a6e 100644 --- a/src/components/services/content/ServiceWebview.js +++ b/src/components/services/content/ServiceWebview.js | |||
@@ -8,6 +8,7 @@ import classnames from 'classnames'; | |||
8 | import ServiceModel from '../../../models/Service'; | 8 | import ServiceModel from '../../../models/Service'; |
9 | import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl'; | 9 | import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl'; |
10 | import WebviewCrashHandler from './WebviewCrashHandler'; | 10 | import WebviewCrashHandler from './WebviewCrashHandler'; |
11 | import ServiceDisabled from './ServiceDisabled'; | ||
11 | 12 | ||
12 | @observer | 13 | @observer |
13 | export default class ServiceWebview extends Component { | 14 | export default class ServiceWebview extends Component { |
@@ -15,6 +16,7 @@ export default class ServiceWebview extends Component { | |||
15 | service: PropTypes.instanceOf(ServiceModel).isRequired, | 16 | service: PropTypes.instanceOf(ServiceModel).isRequired, |
16 | setWebviewReference: PropTypes.func.isRequired, | 17 | setWebviewReference: PropTypes.func.isRequired, |
17 | reload: PropTypes.func.isRequired, | 18 | reload: PropTypes.func.isRequired, |
19 | enable: PropTypes.func.isRequired, | ||
18 | }; | 20 | }; |
19 | 21 | ||
20 | static defaultProps = { | 22 | static defaultProps = { |
@@ -56,6 +58,7 @@ export default class ServiceWebview extends Component { | |||
56 | service, | 58 | service, |
57 | setWebviewReference, | 59 | setWebviewReference, |
58 | reload, | 60 | reload, |
61 | enable, | ||
59 | } = this.props; | 62 | } = this.props; |
60 | 63 | ||
61 | const webviewClasses = classnames({ | 64 | const webviewClasses = classnames({ |
@@ -80,27 +83,38 @@ export default class ServiceWebview extends Component { | |||
80 | reload={reload} | 83 | reload={reload} |
81 | /> | 84 | /> |
82 | )} | 85 | )} |
83 | <Webview | 86 | {!service.isEnabled && ( |
84 | ref={(element) => { this.webview = element; }} | 87 | <ServiceDisabled |
85 | 88 | name={service.recipe.name} | |
86 | autosize | 89 | webview={service.webview} |
87 | src={service.url} | 90 | enable={enable} |
88 | preload="./webview/plugin.js" | 91 | /> |
89 | partition={`persist:service-${service.id}`} | 92 | )} |
90 | 93 | {service.isEnabled && ( | |
91 | onDidAttach={() => setWebviewReference({ | 94 | <div className="services__webview-wrapper"> |
92 | serviceId: service.id, | 95 | <Webview |
93 | webview: this.webview.view, | 96 | ref={(element) => { this.webview = element; }} |
94 | })} | 97 | |
95 | 98 | autosize | |
96 | onUpdateTargetUrl={this.updateTargetUrl} | 99 | src={service.url} |
97 | 100 | preload="./webview/plugin.js" | |
98 | useragent={service.userAgent} | 101 | partition={`persist:service-${service.id}`} |
99 | 102 | ||
100 | disablewebsecurity | 103 | onDidAttach={() => setWebviewReference({ |
101 | allowpopups | 104 | serviceId: service.id, |
102 | /> | 105 | webview: this.webview.view, |
103 | {statusBar} | 106 | })} |
107 | |||
108 | onUpdateTargetUrl={this.updateTargetUrl} | ||
109 | |||
110 | useragent={service.userAgent} | ||
111 | |||
112 | disablewebsecurity | ||
113 | allowpopups | ||
114 | /> | ||
115 | {statusBar} | ||
116 | </div> | ||
117 | )} | ||
104 | </div> | 118 | </div> |
105 | ); | 119 | ); |
106 | } | 120 | } |
diff --git a/src/components/services/content/Services.js b/src/components/services/content/Services.js index bad525d22..5230508f7 100644 --- a/src/components/services/content/Services.js +++ b/src/components/services/content/Services.js | |||
@@ -26,6 +26,7 @@ export default class Services extends Component { | |||
26 | handleIPCMessage: PropTypes.func.isRequired, | 26 | handleIPCMessage: PropTypes.func.isRequired, |
27 | openWindow: PropTypes.func.isRequired, | 27 | openWindow: PropTypes.func.isRequired, |
28 | reload: PropTypes.func.isRequired, | 28 | reload: PropTypes.func.isRequired, |
29 | update: PropTypes.func.isRequired, | ||
29 | }; | 30 | }; |
30 | 31 | ||
31 | static defaultProps = { | 32 | static defaultProps = { |
@@ -44,6 +45,7 @@ export default class Services extends Component { | |||
44 | setWebviewReference, | 45 | setWebviewReference, |
45 | openWindow, | 46 | openWindow, |
46 | reload, | 47 | reload, |
48 | update, | ||
47 | } = this.props; | 49 | } = this.props; |
48 | const { intl } = this.context; | 50 | const { intl } = this.context; |
49 | 51 | ||
@@ -76,6 +78,13 @@ export default class Services extends Component { | |||
76 | setWebviewReference={setWebviewReference} | 78 | setWebviewReference={setWebviewReference} |
77 | openWindow={openWindow} | 79 | openWindow={openWindow} |
78 | reload={() => reload({ serviceId: service.id })} | 80 | reload={() => reload({ serviceId: service.id })} |
81 | enable={() => update({ | ||
82 | serviceId: service.id, | ||
83 | serviceData: { | ||
84 | isEnabled: true, | ||
85 | }, | ||
86 | redirect: false, | ||
87 | })} | ||
79 | /> | 88 | /> |
80 | ))} | 89 | ))} |
81 | </div> | 90 | </div> |
diff --git a/src/components/services/content/WebviewCrashHandler.js b/src/components/services/content/WebviewCrashHandler.js index 24903f3c5..d48152c18 100644 --- a/src/components/services/content/WebviewCrashHandler.js +++ b/src/components/services/content/WebviewCrashHandler.js | |||
@@ -25,7 +25,7 @@ const messages = defineMessages({ | |||
25 | }); | 25 | }); |
26 | 26 | ||
27 | @observer | 27 | @observer |
28 | export default class ServiceWebview extends Component { | 28 | export default class WebviewCrashHandler extends Component { |
29 | static propTypes = { | 29 | static propTypes = { |
30 | name: PropTypes.string.isRequired, | 30 | name: PropTypes.string.isRequired, |
31 | reload: PropTypes.func.isRequired, | 31 | reload: PropTypes.func.isRequired, |
diff --git a/src/components/services/tabs/TabBarSortableList.js b/src/components/services/tabs/TabBarSortableList.js index e5ae36419..3340cbbbb 100644 --- a/src/components/services/tabs/TabBarSortableList.js +++ b/src/components/services/tabs/TabBarSortableList.js | |||
@@ -24,6 +24,7 @@ class TabBarSortableList extends Component { | |||
24 | toggleNotifications: PropTypes.func.isRequired, | 24 | toggleNotifications: PropTypes.func.isRequired, |
25 | deleteService: PropTypes.func.isRequired, | 25 | deleteService: PropTypes.func.isRequired, |
26 | disableService: PropTypes.func.isRequired, | 26 | disableService: PropTypes.func.isRequired, |
27 | enableService: PropTypes.func.isRequired, | ||
27 | } | 28 | } |
28 | 29 | ||
29 | static contextTypes = { | 30 | static contextTypes = { |
@@ -38,6 +39,7 @@ class TabBarSortableList extends Component { | |||
38 | toggleNotifications, | 39 | toggleNotifications, |
39 | deleteService, | 40 | deleteService, |
40 | disableService, | 41 | disableService, |
42 | enableService, | ||
41 | openSettings, | 43 | openSettings, |
42 | } = this.props; | 44 | } = this.props; |
43 | 45 | ||
@@ -58,6 +60,7 @@ class TabBarSortableList extends Component { | |||
58 | toggleNotifications={() => toggleNotifications({ serviceId: service.id })} | 60 | toggleNotifications={() => toggleNotifications({ serviceId: service.id })} |
59 | deleteService={() => deleteService({ serviceId: service.id })} | 61 | deleteService={() => deleteService({ serviceId: service.id })} |
60 | disableService={() => disableService({ serviceId: service.id })} | 62 | disableService={() => disableService({ serviceId: service.id })} |
63 | enableService={() => enableService({ serviceId: service.id })} | ||
61 | openSettings={openSettings} | 64 | openSettings={openSettings} |
62 | /> | 65 | /> |
63 | ))} | 66 | ))} |
diff --git a/src/components/services/tabs/TabItem.js b/src/components/services/tabs/TabItem.js index 9e03d2e21..638e17d95 100644 --- a/src/components/services/tabs/TabItem.js +++ b/src/components/services/tabs/TabItem.js | |||
@@ -32,6 +32,10 @@ const messages = defineMessages({ | |||
32 | id: 'tabs.item.disableService', | 32 | id: 'tabs.item.disableService', |
33 | defaultMessage: '!!!Disable Service', | 33 | defaultMessage: '!!!Disable Service', |
34 | }, | 34 | }, |
35 | enableService: { | ||
36 | id: 'tabs.item.enableService', | ||
37 | defaultMessage: '!!!Enable Service', | ||
38 | }, | ||
35 | deleteService: { | 39 | deleteService: { |
36 | id: 'tabs.item.deleteService', | 40 | id: 'tabs.item.deleteService', |
37 | defaultMessage: '!!!Delete Service', | 41 | defaultMessage: '!!!Delete Service', |
@@ -49,6 +53,7 @@ class TabItem extends Component { | |||
49 | openSettings: PropTypes.func.isRequired, | 53 | openSettings: PropTypes.func.isRequired, |
50 | deleteService: PropTypes.func.isRequired, | 54 | deleteService: PropTypes.func.isRequired, |
51 | disableService: PropTypes.func.isRequired, | 55 | disableService: PropTypes.func.isRequired, |
56 | enableService: PropTypes.func.isRequired, | ||
52 | }; | 57 | }; |
53 | 58 | ||
54 | static contextTypes = { | 59 | static contextTypes = { |
@@ -64,6 +69,7 @@ class TabItem extends Component { | |||
64 | toggleNotifications, | 69 | toggleNotifications, |
65 | deleteService, | 70 | deleteService, |
66 | disableService, | 71 | disableService, |
72 | enableService, | ||
67 | openSettings, | 73 | openSettings, |
68 | } = this.props; | 74 | } = this.props; |
69 | const { intl } = this.context; | 75 | const { intl } = this.context; |
@@ -90,8 +96,8 @@ class TabItem extends Component { | |||
90 | : intl.formatMessage(messages.enableNotifications), | 96 | : intl.formatMessage(messages.enableNotifications), |
91 | click: () => toggleNotifications(), | 97 | click: () => toggleNotifications(), |
92 | }, { | 98 | }, { |
93 | label: intl.formatMessage(messages.disableService), | 99 | label: intl.formatMessage(service.isEnabled ? messages.disableService : messages.enableService), |
94 | click: () => disableService(), | 100 | click: () => (service.isEnabled ? disableService() : enableService()), |
95 | }, { | 101 | }, { |
96 | type: 'separator', | 102 | type: 'separator', |
97 | }, { | 103 | }, { |
@@ -106,6 +112,7 @@ class TabItem extends Component { | |||
106 | 'tab-item': true, | 112 | 'tab-item': true, |
107 | 'is-active': service.isActive, | 113 | 'is-active': service.isActive, |
108 | 'has-custom-icon': service.hasCustomIcon, | 114 | 'has-custom-icon': service.hasCustomIcon, |
115 | 'is-disabled': !service.isEnabled, | ||
109 | })} | 116 | })} |
110 | onClick={clickHandler} | 117 | onClick={clickHandler} |
111 | onContextMenu={() => menu.popup(remote.getCurrentWindow())} | 118 | onContextMenu={() => menu.popup(remote.getCurrentWindow())} |
diff --git a/src/components/services/tabs/Tabbar.js b/src/components/services/tabs/Tabbar.js index fdb2c0a59..5f63aed16 100644 --- a/src/components/services/tabs/Tabbar.js +++ b/src/components/services/tabs/Tabbar.js | |||
@@ -29,20 +29,28 @@ export default class TabBar extends Component { | |||
29 | reorder({ oldIndex, newIndex }); | 29 | reorder({ oldIndex, newIndex }); |
30 | }; | 30 | }; |
31 | 31 | ||
32 | disableService = ({ serviceId }) => { | 32 | toggleService = ({ serviceId, isEnabled }) => { |
33 | const { updateService } = this.props; | 33 | const { updateService } = this.props; |
34 | 34 | ||
35 | if (serviceId) { | 35 | if (serviceId) { |
36 | updateService({ | 36 | updateService({ |
37 | serviceId, | 37 | serviceId, |
38 | serviceData: { | 38 | serviceData: { |
39 | isEnabled: false, | 39 | isEnabled, |
40 | }, | 40 | }, |
41 | redirect: false, | 41 | redirect: false, |
42 | }); | 42 | }); |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | disableService({ serviceId }) { | ||
47 | this.toggleService({ serviceId, isEnabled: false }); | ||
48 | } | ||
49 | |||
50 | enableService({ serviceId }) { | ||
51 | this.toggleService({ serviceId, isEnabled: true }); | ||
52 | } | ||
53 | |||
46 | render() { | 54 | render() { |
47 | const { | 55 | const { |
48 | services, | 56 | services, |
@@ -64,7 +72,8 @@ export default class TabBar extends Component { | |||
64 | reload={reload} | 72 | reload={reload} |
65 | toggleNotifications={toggleNotifications} | 73 | toggleNotifications={toggleNotifications} |
66 | deleteService={deleteService} | 74 | deleteService={deleteService} |
67 | disableService={this.disableService} | 75 | disableService={args => this.disableService(args)} |
76 | enableService={args => this.enableService(args)} | ||
68 | openSettings={openSettings} | 77 | openSettings={openSettings} |
69 | distance={20} | 78 | distance={20} |
70 | axis="y" | 79 | axis="y" |