From 012e55ebf87559f2d782e5400fb885df8b80a445 Mon Sep 17 00:00:00 2001 From: kytwb <412895+kytwb@users.noreply.github.com> Date: Fri, 23 Jul 2021 10:04:43 +0100 Subject: Fix hibernation mode (#1486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use hibernation strategy from settings instead of hardcoded 5 minutes * Fix conditions with isHibernationEnabled, previously disableHibernation * Make service hibernation obey global setting Also refactors hibernation to move some hibernation enablement logic into the Service model * Remove global hibernation enable switch Implements option 4 from https://github.com/getferdi/ferdi/pull/1486#issuecomment-860290992 according to https://github.com/getferdi/ferdi/pull/1486#issuecomment-876558694 * Implements #865 : Add 'hibernate service' and 'wake up service' in the sidebar context menu. * Removed 'hibernationEnabled' check on main settings screen Since this is an (imo) incongruous behavior for the first time user. They will see a message, but with no ability to choose the hibernation strategy. * Autogenerated files from conflict fixes Co-authored-by: Kristóf Marussy Co-authored-by: Vijay A --- src/models/Service.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/models/Service.js') diff --git a/src/models/Service.js b/src/models/Service.js index 397950787..162dcea65 100644 --- a/src/models/Service.js +++ b/src/models/Service.js @@ -37,8 +37,6 @@ export default class Service { @observable isMuted = false; - @observable isHibernating = false; - @observable team = ''; @observable customUrl = ''; @@ -77,7 +75,7 @@ export default class Service { @observable isHibernationEnabled = false; - @observable isHibernating = false; + @observable isHibernationRequested = false; @observable lastUsed = Date.now(); // timestamp @@ -145,14 +143,11 @@ export default class Service { this.recipe = recipe; // Check if "Hibernate on Startup" is enabled and hibernate all services except active one - const { - hibernate, - hibernateOnStartup, - } = window.ferdi.stores.settings.app; + const { hibernateOnStartup } = window.ferdi.stores.settings.app; // The service store is probably not loaded yet so we need to use localStorage data to get active service const isActive = window.localStorage.service && JSON.parse(window.localStorage.service).activeService === this.id; - if (hibernate && hibernateOnStartup && !isActive) { - this.isHibernating = true; + if (hibernateOnStartup && !isActive) { + this.isHibernationRequested = true; } autorun(() => { @@ -185,6 +180,14 @@ export default class Service { return this.recipe.id === todosStore.todoRecipeId; } + @computed get canHibernate() { + return this.isHibernationEnabled; + } + + @computed get isHibernating() { + return this.canHibernate && this.isHibernationRequested; + } + get webview() { if (this.isTodosService) { return todosStore.webview; -- cgit v1.2.3-70-g09d2