Skip to content

Commit cb92dd7

Browse files
committed
feat(Service): Add service hibernation to save system resources
1 parent a406262 commit cb92dd7

File tree

10 files changed

+175
-47
lines changed

10 files changed

+175
-47
lines changed

src/actions/service.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@ export default {
9191
serviceId: PropTypes.string.isRequired,
9292
},
9393
openDevToolsForActiveService: {},
94+
hibernate: {
95+
serviceId: PropTypes.string.isRequired,
96+
},
97+
awake: {
98+
serviceId: PropTypes.string.isRequired,
99+
},
94100
};

src/components/services/content/ServiceView.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,13 @@ export default @observer class ServiceView extends Component {
143143
{service.recipe.id === CUSTOM_WEBSITE_ID && (
144144
<WebControlsScreen service={service} />
145145
)}
146-
<ServiceWebview
147-
service={service}
148-
setWebviewReference={setWebviewReference}
149-
detachService={detachService}
150-
/>
146+
{!service.isHibernating && (
147+
<ServiceWebview
148+
service={service}
149+
setWebviewReference={setWebviewReference}
150+
detachService={detachService}
151+
/>
152+
)}
151153
</>
152154
)}
153155
</>

src/components/settings/services/EditServiceForm.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const messages = defineMessages({
7777
id: 'settings.service.form.isMutedInfo',
7878
defaultMessage: '!!!When disabled, all notification sounds and audio playback are muted',
7979
},
80+
isHibernationEnabledInfo: {
81+
id: 'settings.service.form.isHibernatedEnabledInfo',
82+
defaultMessage: '!!!When enabled, a service will be shut down after a period of time to save system resources.',
83+
},
8084
headlineNotifications: {
8185
id: 'settings.service.form.headlineNotifications',
8286
defaultMessage: '!!!Notifications',
@@ -333,6 +337,10 @@ export default @observer class EditServiceForm extends Component {
333337
<Toggle field={form.$('isDarkModeEnabled')} />
334338
)}
335339
<Toggle field={form.$('isEnabled')} />
340+
<Toggle field={form.$('isHibernationEnabled')} />
341+
<p className="settings__help">
342+
{intl.formatMessage(messages.isHibernationEnabledInfo)}
343+
</p>
336344
</div>
337345
</div>
338346
<div className="service-icon">

src/containers/settings/EditServiceScreen.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const messages = defineMessages({
3333
id: 'settings.service.form.enableService',
3434
defaultMessage: '!!!Enable service',
3535
},
36+
enableHibernation: {
37+
id: 'settings.service.form.enableHibernation',
38+
defaultMessage: '!!!Enable hibernation',
39+
},
3640
enableNotification: {
3741
id: 'settings.service.form.enableNotification',
3842
defaultMessage: '!!!Enable Notifications',
@@ -114,8 +118,11 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex
114118

115119
const {
116120
stores,
121+
router,
117122
} = this.props;
118123

124+
const { action } = router.params;
125+
119126
let defaultSpellcheckerLanguage = SPELLCHECKER_LOCALES[stores.settings.app.spellcheckerLanguage];
120127

121128
if (stores.settings.app.spellcheckerLanguage === 'automatic') {
@@ -140,6 +147,11 @@ export default @inject('stores', 'actions') @observer class EditServiceScreen ex
140147
value: service.isEnabled,
141148
default: true,
142149
},
150+
isHibernationEnabled: {
151+
label: intl.formatMessage(messages.enableHibernation),
152+
value: action !== 'edit' ? recipe.autoHibernate : service.isHibernationEnabled,
153+
default: true,
154+
},
143155
isNotificationEnabled: {
144156
label: intl.formatMessage(messages.enableNotification),
145157
value: service.isNotificationEnabled,

src/i18n/locales/en-US.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
"settings.service.form.enableAudio": "Enable audio",
299299
"settings.service.form.enableBadge": "Show unread message badges",
300300
"settings.service.form.enableDarkMode": "Enable Dark Mode",
301+
"settings.service.form.enableHibernation": "Enable hibernation",
301302
"settings.service.form.enableNotification": "Enable notifications",
302303
"settings.service.form.enableService": "Enable service",
303304
"settings.service.form.headlineBadges": "Unread message badges",
@@ -308,6 +309,7 @@
308309
"settings.service.form.iconUpload": "Drop your image, or click here",
309310
"settings.service.form.indirectMessageInfo": "You will be notified about all new messages in a channel, not just @username, @channel, @here, ...",
310311
"settings.service.form.indirectMessages": "Show message badge for all new messages",
312+
"settings.service.form.isHibernatedEnabledInfo": "When enabled, a service will be shut down after a period of time to save system resources.",
311313
"settings.service.form.isMutedInfo": "When disabled, all notification sounds and audio playback are muted",
312314
"settings.service.form.name": "Name",
313315
"settings.service.form.proxy.headline": "HTTP/HTTPS Proxy Settings",

src/i18n/messages/src/components/settings/services/EditServiceForm.json

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,29 @@
181181
"column": 3
182182
}
183183
},
184+
{
185+
"id": "settings.service.form.isHibernatedEnabledInfo",
186+
"defaultMessage": "!!!When enabled, a service will be shut down after a period of time to save system resources.",
187+
"file": "src/components/settings/services/EditServiceForm.js",
188+
"start": {
189+
"line": 80,
190+
"column": 28
191+
},
192+
"end": {
193+
"line": 83,
194+
"column": 3
195+
}
196+
},
184197
{
185198
"id": "settings.service.form.headlineNotifications",
186199
"defaultMessage": "!!!Notifications",
187200
"file": "src/components/settings/services/EditServiceForm.js",
188201
"start": {
189-
"line": 80,
202+
"line": 84,
190203
"column": 25
191204
},
192205
"end": {
193-
"line": 83,
206+
"line": 87,
194207
"column": 3
195208
}
196209
},
@@ -199,11 +212,11 @@
199212
"defaultMessage": "!!!Unread message badges",
200213
"file": "src/components/settings/services/EditServiceForm.js",
201214
"start": {
202-
"line": 84,
215+
"line": 88,
203216
"column": 18
204217
},
205218
"end": {
206-
"line": 87,
219+
"line": 91,
207220
"column": 3
208221
}
209222
},
@@ -212,11 +225,11 @@
212225
"defaultMessage": "!!!General",
213226
"file": "src/components/settings/services/EditServiceForm.js",
214227
"start": {
215-
"line": 88,
228+
"line": 92,
216229
"column": 19
217230
},
218231
"end": {
219-
"line": 91,
232+
"line": 95,
220233
"column": 3
221234
}
222235
},
@@ -225,11 +238,11 @@
225238
"defaultMessage": "!!!Delete",
226239
"file": "src/components/settings/services/EditServiceForm.js",
227240
"start": {
228-
"line": 92,
241+
"line": 96,
229242
"column": 14
230243
},
231244
"end": {
232-
"line": 95,
245+
"line": 99,
233246
"column": 3
234247
}
235248
},
@@ -238,11 +251,11 @@
238251
"defaultMessage": "!!!Drop your image, or click here",
239252
"file": "src/components/settings/services/EditServiceForm.js",
240253
"start": {
241-
"line": 96,
254+
"line": 100,
242255
"column": 14
243256
},
244257
"end": {
245-
"line": 99,
258+
"line": 103,
246259
"column": 3
247260
}
248261
},
@@ -251,11 +264,11 @@
251264
"defaultMessage": "!!!HTTP/HTTPS Proxy Settings",
252265
"file": "src/components/settings/services/EditServiceForm.js",
253266
"start": {
254-
"line": 100,
267+
"line": 104,
255268
"column": 17
256269
},
257270
"end": {
258-
"line": 103,
271+
"line": 107,
259272
"column": 3
260273
}
261274
},
@@ -264,11 +277,11 @@
264277
"defaultMessage": "!!!Please restart Franz after changing proxy Settings.",
265278
"file": "src/components/settings/services/EditServiceForm.js",
266279
"start": {
267-
"line": 104,
280+
"line": 108,
268281
"column": 20
269282
},
270283
"end": {
271-
"line": 107,
284+
"line": 111,
272285
"column": 3
273286
}
274287
},
@@ -277,11 +290,11 @@
277290
"defaultMessage": "!!!Proxy settings will not be synchronized with the Franz servers.",
278291
"file": "src/components/settings/services/EditServiceForm.js",
279292
"start": {
280-
"line": 108,
293+
"line": 112,
281294
"column": 13
282295
},
283296
"end": {
284-
"line": 111,
297+
"line": 115,
285298
"column": 3
286299
}
287300
}

0 commit comments

Comments
 (0)