-
Notifications
You must be signed in to change notification settings - Fork 9
/
HoistAppModel.ts
110 lines (103 loc) · 4.55 KB
/
HoistAppModel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2024 Extremely Heavy Industries Inc.
*/
import {webSocketIndicator} from '@xh/hoist/cmp/websocket';
import {AppOptionSpec, HoistModel, Thunkable} from './';
import {Route} from 'router5';
import {ReactNode} from 'react';
/**
* Specialized base class for defining the central model for a Hoist app as specified by its
* See the {@link AppSpec.modelClass} config, which should reference a concrete implementation class
* extending this base. Hoist will create and then initialize an instance of that class after
* the framework has successfully initialized and will make it available to all app code via the
* `XH.appModel` getter.
*
* Applications should specify this class to provide application level state and services and
* customize important metadata. Initialization of all resources (e.g. application level services)
* should be done in `initAsync()`.
*
* Hoist will load/reload this Model during the global refresh process. This will occur before the
* application's global `XH.refreshContextModel` has been refreshed (when all mounted and 'owned'
* HoistModels in the application are refreshed). AppModels should implement `doLoadAsync()` if
* required to refresh all other app-wide services and models, respecting any ordering and phasing
* requirements specific to its needs.
*/
export class HoistAppModel extends HoistModel {
/**
* Hoist will call this method after Hoist services have initialized and the application
* has mounted. Use to trigger initialization of the app and any app-specific services.
*
* Applications will typically use this method to install and initialize app-specific
* services using one or more phased calls to XH.installServicesAsync().
*/
async initAsync() {}
/**
* Should the version bar be shown in this application?.
* Applications for which a version bar might not be appropriate (e.g. a mini-app
* being shown in a frame or modal) may override this getter and return false
*/
get supportsVersionBar(): boolean {
return true;
}
/**
* Provide the initial set of Router5 Routes to be used by this application.
*/
getRoutes(): Route[] {
return [];
}
/**
* Provide a list of app-wide options to be displayed in the App's built-in Options
* dialog, accessible from the default AppBar menu when this method returns non-empty.
* @see AppOption
*/
getAppOptions(): AppOptionSpec[] {
return [];
}
/**
* Provide a list of app-wide metadata and version information to be displayed in the
* App's built-in About dialog.
*/
getAboutDialogItems(): AboutDialogItem[] {
const XH = window['XH'],
svc = XH.environmentService;
return [
{label: 'App', value: `${svc.get('appName')} (${svc.get('appCode')})`},
{label: 'Current User', value: XH.identityService.username},
{label: 'Environment', value: svc.get('appEnvironment')},
{label: 'Instance', value: svc.serverInstance},
{label: 'Server', value: `${svc.get('appVersion')} (build ${svc.get('appBuild')})`},
{
label: 'Client',
value: `${svc.get('clientVersion')} (build ${svc.get('clientBuild')})`
},
{label: 'Hoist Core', value: svc.get('hoistCoreVersion')},
{label: 'Hoist React', value: svc.get('hoistReactVersion')},
{label: 'User Agent', value: window.navigator.userAgent},
{label: 'WebSockets', value: webSocketIndicator()}
];
}
/**
* Resets user preferences and any persistent local application state.
*
* The default implementation for this method will clear *all* preferences and local storage.
*
* Applications may wish to override this method to do a more targeted clearing of state.
* This is important for complex applications with smaller sub-applications, and/or device
* specific applications. These applications will typically want to perform a custom clearing
* that is more targeted, and includes any additional app-specific state.
*/
async restoreDefaultsAsync() {
const XH = window['XH'];
await XH.prefService.clearAllAsync();
XH.localStorageService.clear();
}
}
/** Object Describing an entry in the AboutDialog. */
export interface AboutDialogItem {
label: ReactNode;
value: ReactNode;
omit?: Thunkable<boolean>;
}