|
| 1 | +import { |
| 2 | + FrontendApplicationState, |
| 3 | + FrontendApplicationStateService, |
| 4 | +} from '@theia/core/lib/browser/frontend-application-state'; |
1 | 5 | import { CompositeTreeNode } from '@theia/core/lib/browser/tree/tree';
|
2 |
| -import { injectable } from '@theia/core/shared/inversify'; |
| 6 | +import { inject, injectable } from '@theia/core/shared/inversify'; |
3 | 7 | import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from '@theia/preferences/lib/browser/util/preference-tree-generator';
|
4 | 8 |
|
5 | 9 | @injectable()
|
6 | 10 | export class PreferenceTreeGenerator extends TheiaPreferenceTreeGenerator {
|
| 11 | + private shouldHandleChangedSchemaOnReady = false; |
| 12 | + private state: FrontendApplicationState | undefined; |
| 13 | + |
| 14 | + @inject(FrontendApplicationStateService) |
| 15 | + private readonly appStateService: FrontendApplicationStateService; |
| 16 | + |
7 | 17 | protected override async init(): Promise<void> {
|
8 |
| - // The IDE2 does not use the default Theia preferences UI. |
9 |
| - // There is no need to create and keep the the tree model synchronized when there is no UI for it. |
| 18 | + this.appStateService.onStateChanged((state) => { |
| 19 | + this.state = state; |
| 20 | + // manually trigger a model (and UI) refresh if it was requested during the startup phase. |
| 21 | + if (this.state === 'ready' && this.shouldHandleChangedSchemaOnReady) { |
| 22 | + this.doHandleChangedSchema(); |
| 23 | + } |
| 24 | + }); |
| 25 | + return super.init(); |
| 26 | + } |
| 27 | + |
| 28 | + override doHandleChangedSchema(): void { |
| 29 | + if (this.state === 'ready') { |
| 30 | + super.doHandleChangedSchema(); |
| 31 | + } |
| 32 | + // don't do anything until the app is `ready`, then invoke `doHandleChangedSchema`. |
| 33 | + this.shouldHandleChangedSchemaOnReady = true; |
10 | 34 | }
|
11 | 35 |
|
12 |
| - // Just returns with the empty root. |
13 | 36 | override generateTree(): CompositeTreeNode {
|
| 37 | + if (this.state === 'ready') { |
| 38 | + return super.generateTree(); |
| 39 | + } |
| 40 | + // always create an empty root when the app is not ready. |
14 | 41 | this._root = this.createRootNode();
|
15 | 42 | return this._root;
|
16 | 43 | }
|
|
0 commit comments