Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IdleService #427

Merged
merged 11 commits into from
Jul 11, 2018
Merged

IdleService #427

merged 11 commits into from
Jul 11, 2018

Conversation

gportela85
Copy link
Contributor

@gportela85 gportela85 requested a review from lbwexler July 3, 2018 01:29
@lbwexler
Copy link
Member

lbwexler commented Jul 5, 2018

Was looking for a default display of this (app overrideable) more like what we have in Hoist Sencha.
See App.showIdleWindow()

This looks like a start, but really need that bit in order to merge things.

Also, the Hoist Sencha version had the ability to change this per user via preference. Seems like for consistency we really just want to mirror everything we have in Hoist Sencha.

@TomTirapani
Copy link
Member

Took a look at this.

I like how the app can specify any idleComponent, allowing us to override the alert to do something different / more elaborate should the app call for it.

We're missing a few features that we need to reach parity with Hoist Sencha:

  • A way for Apps to disable idle detection generally.
  • A way to disable per user using preferences.
  • We should stop any timer based tasks when the app becomes idle. I think we may be able to use Timer.cancelAll() for this.
  • We should also fire an appSuspended event, so that other parts of the app can react if necessary. Alternatively, rather than an event, this could be an observable on App itself.

See https://github.com/exhi/hoist-sencha/blob/develop/grails-app/assets/src/xh/all/svc/IdleService.js for how these features are implemented in Hoist Sencha

@@ -58,7 +59,8 @@ export class AppContainer extends Component {
render() {
return div(
this.renderContent(),
exceptionDialog() // Always render the exception dialog -- might need it :-(
exceptionDialog(), // Always render the exception dialog -- might need it :-(
idleWrapper()
Copy link
Member

@lbwexler lbwexler Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinks this belongs more properly down around line 90. Is not analogous to the exceptionDialog in needing to be rendered in all states. Can we call it idleDialog for symmetry? Also, can we perhaps trigger this with a LoadState.IDLE. Think it makes more sense to handle that way, since this is a terminal state. It will be easier to reason about, and we can avoid the extra wrapper component.

import {Component} from 'react';
import {XH, HoistComponent, elemFactory} from '@xh/hoist/core';

@HoistComponent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry -- you made those last changes so quickly, I hadn't finished my comments. Don't think we need this wrapper component. This null check can be just made inline in the main renderer.

core/HoistApp.js Outdated
@@ -62,6 +63,21 @@ export function HoistApp(C) {
};
},

/**
* App must implement this method with appropriate logic to display a message when the app
* has been idle for the amount of minutes defined by the `xhxhIdleTimeoutMins` config.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling mistake here....

core/HoistApp.js Outdated
@@ -62,6 +63,21 @@ export function HoistApp(C) {
};
},

/**
* App must implement this method with appropriate logic to display a message when the app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'may override' instead of 'must implement'

core/HoistApp.js Outdated
* has been idle for the amount of minutes defined by the `xhxhIdleTimeoutMins` config.
* @param {Function} callback - A callback function to be handled by the showIdleDialog
*/
showIdleDialog(callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this should be named 'renderIdleDialog()' if its job is to return a react element that can be rendered.


window.dispatchEvent(new CustomEvent('appSuspended'));
XH.idleComponent = XH.app.showIdleDialog(() => {
window.location.reload();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the flag for reload (e.g. reload(true)) missing?? This is clearly in the sencha source, and we spent a long time troubleshooting problems related to that...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the initial idleService PR (https://github.com/exhi/hoist/pull/250/files) as source for these changes so I would be able to take compare the whole implementation instead of just looking at the final code in IdleService.js. That's why some things were missing like using an app config or user config to disable the service. I'll add the flag to disable cache.

this.destroyAppListener();
Timer.cancelAll();

window.dispatchEvent(new CustomEvent('appSuspended'));
Copy link
Member

@lbwexler lbwexler Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use window.dispatchEvent, or anything like window events. Realize we are trying to mimic the sencha implementation here, but not sure we need this. Also, the term suspended is just a new word -- if we were going to have such an event would probably want something with the word 'idle' in it

@lbwexler
Copy link
Member

lbwexler commented Jul 9, 2018 via email

gportela85 and others added 5 commits July 9, 2018 14:27
@lbwexler
Copy link
Member

I refactored this a bit, and it led to a larger refactor to create a new notion of AppState, which includes AppState.SUSPENDED.

Also simplified the implementation of IdleService and its timers, and also the way in which applications override the default component.

Also some unrelated file moves from '/app' package to '/impl'.

cr: atm (partially, IdleService review still pending)

@lbwexler lbwexler merged commit 4b7d9ec into develop Jul 11, 2018
@lbwexler lbwexler deleted the idleService branch July 11, 2018 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants