Skip to content

Commit

Permalink
feat(Service): Add service hibernation to save system resources
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Feb 20, 2020
1 parent a406262 commit cb92dd7
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 47 deletions.
6 changes: 6 additions & 0 deletions src/actions/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ export default {
serviceId: PropTypes.string.isRequired,
},
openDevToolsForActiveService: {},
hibernate: {
serviceId: PropTypes.string.isRequired,
},
awake: {
serviceId: PropTypes.string.isRequired,
},
};
12 changes: 7 additions & 5 deletions src/components/services/content/ServiceView.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ export default @observer class ServiceView extends Component {
{service.recipe.id === CUSTOM_WEBSITE_ID && (
<WebControlsScreen service={service} />
)}
<ServiceWebview
service={service}
setWebviewReference={setWebviewReference}
detachService={detachService}
/>
{!service.isHibernating && (
<ServiceWebview
service={service}
setWebviewReference={setWebviewReference}
detachService={detachService}
/>
)}
</>
)}
</>
Expand Down
8 changes: 8 additions & 0 deletions src/components/settings/services/EditServiceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const messages = defineMessages({
id: 'settings.service.form.isMutedInfo',
defaultMessage: '!!!When disabled, all notification sounds and audio playback are muted',
},
isHibernationEnabledInfo: {
id: 'settings.service.form.isHibernatedEnabledInfo',
defaultMessage: '!!!When enabled, a service will be shut down after a period of time to save system resources.',
},
headlineNotifications: {
id: 'settings.service.form.headlineNotifications',
defaultMessage: '!!!Notifications',
Expand Down Expand Up @@ -333,6 +337,10 @@ export default @observer class EditServiceForm extends Component {
<Toggle field={form.$('isDarkModeEnabled')} />
)}
<Toggle field={form.$('isEnabled')} />
<Toggle field={form.$('isHibernationEnabled')} />
<p className="settings__help">
{intl.formatMessage(messages.isHibernationEnabledInfo)}
</p>
</div>
</div>
<div className="service-icon">
Expand Down
12 changes: 12 additions & 0 deletions src/containers/settings/EditServiceScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const messages = defineMessages({
id: 'settings.service.form.enableService',
defaultMessage: '!!!Enable service',
},
enableHibernation: {
id: 'settings.service.form.enableHibernation',
defaultMessage: '!!!Enable hibernation',
},
enableNotification: {
id: 'settings.service.form.enableNotification',
defaultMessage: '!!!Enable Notifications',
Expand Down Expand Up @@ -114,8 +118,11 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex

const {
stores,
router,
} = this.props;

const { action } = router.params;

let defaultSpellcheckerLanguage = SPELLCHECKER_LOCALES[stores.settings.app.spellcheckerLanguage];

if (stores.settings.app.spellcheckerLanguage === 'automatic') {
Expand All @@ -140,6 +147,11 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex
value: service.isEnabled,
default: true,
},
isHibernationEnabled: {
label: intl.formatMessage(messages.enableHibernation),
value: action !== 'edit' ? recipe.autoHibernate : service.isHibernationEnabled,
default: true,
},
isNotificationEnabled: {
label: intl.formatMessage(messages.enableNotification),
value: service.isNotificationEnabled,
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
"settings.service.form.enableAudio": "Enable audio",
"settings.service.form.enableBadge": "Show unread message badges",
"settings.service.form.enableDarkMode": "Enable Dark Mode",
"settings.service.form.enableHibernation": "Enable hibernation",
"settings.service.form.enableNotification": "Enable notifications",
"settings.service.form.enableService": "Enable service",
"settings.service.form.headlineBadges": "Unread message badges",
Expand All @@ -308,6 +309,7 @@
"settings.service.form.iconUpload": "Drop your image, or click here",
"settings.service.form.indirectMessageInfo": "You will be notified about all new messages in a channel, not just @username, @channel, @here, ...",
"settings.service.form.indirectMessages": "Show message badge for all new messages",
"settings.service.form.isHibernatedEnabledInfo": "When enabled, a service will be shut down after a period of time to save system resources.",
"settings.service.form.isMutedInfo": "When disabled, all notification sounds and audio playback are muted",
"settings.service.form.name": "Name",
"settings.service.form.proxy.headline": "HTTP/HTTPS Proxy Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,29 @@
"column": 3
}
},
{
"id": "settings.service.form.isHibernatedEnabledInfo",
"defaultMessage": "!!!When enabled, a service will be shut down after a period of time to save system resources.",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 80,
"column": 28
},
"end": {
"line": 83,
"column": 3
}
},
{
"id": "settings.service.form.headlineNotifications",
"defaultMessage": "!!!Notifications",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 80,
"line": 84,
"column": 25
},
"end": {
"line": 83,
"line": 87,
"column": 3
}
},
Expand All @@ -199,11 +212,11 @@
"defaultMessage": "!!!Unread message badges",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 84,
"line": 88,
"column": 18
},
"end": {
"line": 87,
"line": 91,
"column": 3
}
},
Expand All @@ -212,11 +225,11 @@
"defaultMessage": "!!!General",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 88,
"line": 92,
"column": 19
},
"end": {
"line": 91,
"line": 95,
"column": 3
}
},
Expand All @@ -225,11 +238,11 @@
"defaultMessage": "!!!Delete",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 92,
"line": 96,
"column": 14
},
"end": {
"line": 95,
"line": 99,
"column": 3
}
},
Expand All @@ -238,11 +251,11 @@
"defaultMessage": "!!!Drop your image, or click here",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 96,
"line": 100,
"column": 14
},
"end": {
"line": 99,
"line": 103,
"column": 3
}
},
Expand All @@ -251,11 +264,11 @@
"defaultMessage": "!!!HTTP/HTTPS Proxy Settings",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 100,
"line": 104,
"column": 17
},
"end": {
"line": 103,
"line": 107,
"column": 3
}
},
Expand All @@ -264,11 +277,11 @@
"defaultMessage": "!!!Please restart Franz after changing proxy Settings.",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 104,
"line": 108,
"column": 20
},
"end": {
"line": 107,
"line": 111,
"column": 3
}
},
Expand All @@ -277,11 +290,11 @@
"defaultMessage": "!!!Proxy settings will not be synchronized with the Franz servers.",
"file": "src/components/settings/services/EditServiceForm.js",
"start": {
"line": 108,
"line": 112,
"column": 13
},
"end": {
"line": 111,
"line": 115,
"column": 3
}
}
Expand Down
Loading

0 comments on commit cb92dd7

Please sign in to comment.