Skip to content

Commit

Permalink
Add observable XH.environmentService.serverVersion (#3156)
Browse files Browse the repository at this point in the history
+ And `serverBuild` for good measure since we poll both anyway and both can factor into pre-existing upgrade prompt.
+ Fixes #3035
  • Loading branch information
amcclain authored Oct 7, 2022
1 parent ac25412 commit 837cb04
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
TabContainer.
* The Admin Console diff tool for Configs, Prefs, and JSONBlobs now displays who updated each value
and when.
* Added new observable `XH.environmentService.serverVersion` property. Regularly updated via
pre-existing `xhAppVersionCheckSecs` config. Note this does not replace or change the built-in
upgrade prompt banner, but allows apps to take their own actions (e.g. reload immediately) when
they detect an update on the server.
* New "Hoist Inspector" tool available in Desktop apps for displaying and querying Models,
Services, and Stores within a running application.
* Powered by a new method `XH.activeModels()`, which supports listing and querying all models
Expand Down
32 changes: 30 additions & 2 deletions svc/EnvironmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
import bpPkg from '@blueprintjs/core/package.json';
import {HoistService, XH} from '@xh/hoist/core';
import {agGridVersion} from '@xh/hoist/kit/ag-grid';
import {observable} from '@xh/hoist/mobx';
import hoistPkg from '@xh/hoist/package.json';
import {Timer} from '@xh/hoist/utils/async';
import {MINUTES, SECONDS} from '@xh/hoist/utils/datetime';
import {deepFreeze} from '@xh/hoist/utils/js';
import {defaults} from 'lodash';
import {action, makeObservable} from 'mobx';
import mobxPkg from 'mobx/package.json';
import {version as reactVersion} from 'react';

export class EnvironmentService extends HoistService {

/**
* @member {string} - version of this application currently running on the Hoist UI server.
* Unlike all other EnvironmentService state, this is refreshed by default on a configured
* interval and is observable to allow apps to take actions (e.g. reload immediately) when
* they detect an update on the server.
*/
@observable serverVersion;

/** @member {string} - build of this application currently running on the Hoist UI server. */
@observable serverBuild;

_data = {};

async initAsync() {
Expand All @@ -42,6 +55,8 @@ export class EnvironmentService extends HoistService {

deepFreeze(this._data);

this.setServerVersion(serverEnv.appVersion, serverEnv.appBuild);

this.addReaction({
when: () => XH.appIsRunning,
run: this.startVersionChecking
Expand All @@ -63,15 +78,20 @@ export class EnvironmentService extends HoistService {
//------------------------------
// Implementation
//------------------------------
constructor() {
super();
makeObservable(this);
}

startVersionChecking() {
Timer.create({
runFn: this.checkAppVersionAsync,
runFn: this.checkServerVersionAsync,
interval: 'xhAppVersionCheckSecs',
intervalUnits: SECONDS
});
}

checkAppVersionAsync = async () => {
checkServerVersionAsync = async () => {
const data = await XH.fetchJson({url: 'xh/version'}),
{appVersion, appBuild, shouldUpdate} = data;

Expand All @@ -95,5 +115,13 @@ export class EnvironmentService extends HoistService {
if (appVersion !== clientVersion) {
console.warn(`Version mismatch detected between client and server - ${clientVersion} vs ${appVersion}`);
}

this.setServerVersion(appVersion, appBuild);
};

@action
setServerVersion(serverVersion, serverBuild) {
this.serverVersion = serverVersion;
this.serverBuild = serverBuild;
}
}

0 comments on commit 837cb04

Please sign in to comment.