Skip to content

Commit

Permalink
feat(Service): Add option to display disabled services in tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Nov 9, 2017
1 parent ae60258 commit 1839eff
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 51 deletions.
48 changes: 48 additions & 0 deletions src/components/services/content/ServiceDisabled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';

import Button from '../../ui/Button';

const messages = defineMessages({
headline: {
id: 'service.disabledHandler.headline',
defaultMessage: '!!!{name} is disabled',
},
action: {
id: 'service.disabledHandler.action',
defaultMessage: '!!!Enable {name}',
},
});

@observer
export default class ServiceDisabled extends Component {
static propTypes = {
name: PropTypes.string.isRequired,
enable: PropTypes.func.isRequired,
};

static contextTypes = {
intl: intlShape,
};

countdownInterval = null;
countdownIntervalTimeout = 1000;

render() {
const { name, enable } = this.props;
const { intl } = this.context;

return (
<div className="services__crash-handler">
<h1>{intl.formatMessage(messages.headline, { name })}</h1>
<Button
label={intl.formatMessage(messages.action, { name })}
buttonType="inverted"
onClick={() => enable()}
/>
</div>
);
}
}
56 changes: 35 additions & 21 deletions src/components/services/content/ServiceWebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import classnames from 'classnames';
import ServiceModel from '../../../models/Service';
import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl';
import WebviewCrashHandler from './WebviewCrashHandler';
import ServiceDisabled from './ServiceDisabled';

@observer
export default class ServiceWebview extends Component {
static propTypes = {
service: PropTypes.instanceOf(ServiceModel).isRequired,
setWebviewReference: PropTypes.func.isRequired,
reload: PropTypes.func.isRequired,
enable: PropTypes.func.isRequired,
};

static defaultProps = {
Expand Down Expand Up @@ -56,6 +58,7 @@ export default class ServiceWebview extends Component {
service,
setWebviewReference,
reload,
enable,
} = this.props;

const webviewClasses = classnames({
Expand All @@ -80,27 +83,38 @@ export default class ServiceWebview extends Component {
reload={reload}
/>
)}
<Webview
ref={(element) => { this.webview = element; }}

autosize
src={service.url}
preload="./webview/plugin.js"
partition={`persist:service-${service.id}`}

onDidAttach={() => setWebviewReference({
serviceId: service.id,
webview: this.webview.view,
})}

onUpdateTargetUrl={this.updateTargetUrl}

useragent={service.userAgent}

disablewebsecurity
allowpopups
/>
{statusBar}
{!service.isEnabled && (
<ServiceDisabled
name={service.recipe.name}
webview={service.webview}
enable={enable}
/>
)}
{service.isEnabled && (
<div className="services__webview-wrapper">
<Webview
ref={(element) => { this.webview = element; }}

autosize
src={service.url}
preload="./webview/plugin.js"
partition={`persist:service-${service.id}`}

onDidAttach={() => setWebviewReference({
serviceId: service.id,
webview: this.webview.view,
})}

onUpdateTargetUrl={this.updateTargetUrl}

useragent={service.userAgent}

disablewebsecurity
allowpopups
/>
{statusBar}
</div>
)}
</div>
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/components/services/content/Services.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class Services extends Component {
handleIPCMessage: PropTypes.func.isRequired,
openWindow: PropTypes.func.isRequired,
reload: PropTypes.func.isRequired,
update: PropTypes.func.isRequired,
};

static defaultProps = {
Expand All @@ -44,6 +45,7 @@ export default class Services extends Component {
setWebviewReference,
openWindow,
reload,
update,
} = this.props;
const { intl } = this.context;

Expand Down Expand Up @@ -76,6 +78,13 @@ export default class Services extends Component {
setWebviewReference={setWebviewReference}
openWindow={openWindow}
reload={() => reload({ serviceId: service.id })}
enable={() => update({
serviceId: service.id,
serviceData: {
isEnabled: true,
},
redirect: false,
})}
/>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/services/content/WebviewCrashHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const messages = defineMessages({
});

@observer
export default class ServiceWebview extends Component {
export default class WebviewCrashHandler extends Component {
static propTypes = {
name: PropTypes.string.isRequired,
reload: PropTypes.func.isRequired,
Expand Down
3 changes: 3 additions & 0 deletions src/components/services/tabs/TabBarSortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TabBarSortableList extends Component {
toggleNotifications: PropTypes.func.isRequired,
deleteService: PropTypes.func.isRequired,
disableService: PropTypes.func.isRequired,
enableService: PropTypes.func.isRequired,
}

static contextTypes = {
Expand All @@ -38,6 +39,7 @@ class TabBarSortableList extends Component {
toggleNotifications,
deleteService,
disableService,
enableService,
openSettings,
} = this.props;

Expand All @@ -58,6 +60,7 @@ class TabBarSortableList extends Component {
toggleNotifications={() => toggleNotifications({ serviceId: service.id })}
deleteService={() => deleteService({ serviceId: service.id })}
disableService={() => disableService({ serviceId: service.id })}
enableService={() => enableService({ serviceId: service.id })}
openSettings={openSettings}
/>
))}
Expand Down
11 changes: 9 additions & 2 deletions src/components/services/tabs/TabItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const messages = defineMessages({
id: 'tabs.item.disableService',
defaultMessage: '!!!Disable Service',
},
enableService: {
id: 'tabs.item.enableService',
defaultMessage: '!!!Enable Service',
},
deleteService: {
id: 'tabs.item.deleteService',
defaultMessage: '!!!Delete Service',
Expand All @@ -49,6 +53,7 @@ class TabItem extends Component {
openSettings: PropTypes.func.isRequired,
deleteService: PropTypes.func.isRequired,
disableService: PropTypes.func.isRequired,
enableService: PropTypes.func.isRequired,
};

static contextTypes = {
Expand All @@ -64,6 +69,7 @@ class TabItem extends Component {
toggleNotifications,
deleteService,
disableService,
enableService,
openSettings,
} = this.props;
const { intl } = this.context;
Expand All @@ -90,8 +96,8 @@ class TabItem extends Component {
: intl.formatMessage(messages.enableNotifications),
click: () => toggleNotifications(),
}, {
label: intl.formatMessage(messages.disableService),
click: () => disableService(),
label: intl.formatMessage(service.isEnabled ? messages.disableService : messages.enableService),
click: () => (service.isEnabled ? disableService() : enableService()),
}, {
type: 'separator',
}, {
Expand All @@ -106,6 +112,7 @@ class TabItem extends Component {
'tab-item': true,
'is-active': service.isActive,
'has-custom-icon': service.hasCustomIcon,
'is-disabled': !service.isEnabled,
})}
onClick={clickHandler}
onContextMenu={() => menu.popup(remote.getCurrentWindow())}
Expand Down
15 changes: 12 additions & 3 deletions src/components/services/tabs/Tabbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,28 @@ export default class TabBar extends Component {
reorder({ oldIndex, newIndex });
};

disableService = ({ serviceId }) => {
toggleService = ({ serviceId, isEnabled }) => {
const { updateService } = this.props;

if (serviceId) {
updateService({
serviceId,
serviceData: {
isEnabled: false,
isEnabled,
},
redirect: false,
});
}
}

disableService({ serviceId }) {
this.toggleService({ serviceId, isEnabled: false });
}

enableService({ serviceId }) {
this.toggleService({ serviceId, isEnabled: true });
}

render() {
const {
services,
Expand All @@ -64,7 +72,8 @@ export default class TabBar extends Component {
reload={reload}
toggleNotifications={toggleNotifications}
deleteService={deleteService}
disableService={this.disableService}
disableService={args => this.disableService(args)}
enableService={args => this.enableService(args)}
openSettings={openSettings}
distance={20}
axis="y"
Expand Down
6 changes: 6 additions & 0 deletions src/components/settings/settings/EditSettingsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const messages = defineMessages({
id: 'settings.app.headlineUpdates',
defaultMessage: '!!!Updates',
},
headlineAppearance: {
id: 'settings.app.headlineAppearance',
defaultMessage: '!!!Appearance',
},
buttonSearchForUpdate: {
id: 'settings.app.buttonSearchForUpdate',
defaultMessage: '!!!Check for updates',
Expand Down Expand Up @@ -119,6 +123,8 @@ export default class EditSettingsForm extends Component {
{process.platform === 'win32' && (
<Toggle field={form.$('minimizeToSystemTray')} />
)}
<h2>{intl.formatMessage(messages.headlineAppearance)}</h2>
<Toggle field={form.$('showDisabledServices')} />
<h2>{intl.formatMessage(messages.headlineLanguage)}</h2>
<Select field={form.$('locale')} showLabel={false} />
<h2>{intl.formatMessage(messages.headlineUpdates)}</h2>
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_APP_SETTINGS = {
runInBackground: false,
enableSystemTray: true,
minimizeToSystemTray: false,
locale: 'en-us', // TODO: Replace with proper solution once translations are in
showDisabledServices: true,
locale: 'en-US',
beta: false,
};
6 changes: 3 additions & 3 deletions src/containers/layout/AppLayoutContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class AppLayoutContainer extends Component {
} = this.props.actions.ui;

const { children } = this.props;
const allServices = services.enabled;

const isLoadingServices = services.allServicesRequest.isExecuting
&& services.allServicesRequest.isExecutingFirstTime;
Expand All @@ -77,7 +76,7 @@ export default class AppLayoutContainer extends Component {

const sidebar = (
<Sidebar
services={allServices}
services={services.allDisplayed}
setActive={setActive}
openSettings={openSettings}
closeSettings={closeSettings}
Expand All @@ -92,11 +91,12 @@ export default class AppLayoutContainer extends Component {

const servicesContainer = (
<Services
services={allServices}
services={services.allDisplayed}
handleIPCMessage={handleIPCMessage}
setWebviewReference={setWebviewReference}
openWindow={openWindow}
reload={reload}
update={updateService}
/>
);

Expand Down
10 changes: 10 additions & 0 deletions src/containers/settings/EditSettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const messages = defineMessages({
id: 'settings.app.form.language',
defaultMessage: '!!!Language',
},
showDisabledServices: {
id: 'settings.app.form.showDisabledServices',
defaultMessage: '!!!Display disabled services tabs',
},
beta: {
id: 'settings.app.form.beta',
defaultMessage: '!!!Include beta versions',
Expand Down Expand Up @@ -68,6 +72,7 @@ export default class EditSettingsScreen extends Component {
runInBackground: settingsData.runInBackground,
enableSystemTray: settingsData.enableSystemTray,
minimizeToSystemTray: settingsData.minimizeToSystemTray,
showDisabledServices: settingsData.showDisabledServices,
locale: settingsData.locale,
beta: settingsData.beta,
},
Expand Down Expand Up @@ -119,6 +124,11 @@ export default class EditSettingsScreen extends Component {
value: settings.all.minimizeToSystemTray,
default: DEFAULT_APP_SETTINGS.minimizeToSystemTray,
},
showDisabledServices: {
label: intl.formatMessage(messages.showDisabledServices),
value: settings.all.showDisabledServices,
default: DEFAULT_APP_SETTINGS.showDisabledServices,
},
locale: {
label: intl.formatMessage(messages.language),
value: app.locale,
Expand Down
Loading

0 comments on commit 1839eff

Please sign in to comment.