UNPKG

7.31 kBTypeScriptView Raw
1import { ContributionProvider, CommandRegistry, MenuModelRegistry, BackendStopwatch, Stopwatch } from '../common';
2import { MaybePromise } from '../common/types';
3import { KeybindingRegistry } from './keybinding';
4import { ApplicationShell } from './shell/application-shell';
5import { ShellLayoutRestorer } from './shell/shell-layout-restorer';
6import { FrontendApplicationStateService } from './frontend-application-state';
7import { CorePreferences } from './core-preferences';
8import { WindowService } from './window/window-service';
9import { TooltipService } from './tooltip-service';
10import { StopReason } from '../common/frontend-application-state';
11/**
12 * Clients can implement to get a callback for contributing widgets to a shell on start.
13 */
14export declare const FrontendApplicationContribution: unique symbol;
15export interface FrontendApplicationContribution {
16 /**
17 * Called on application startup before configure is called.
18 */
19 initialize?(): void;
20 /**
21 * Called before commands, key bindings and menus are initialized.
22 * Should return a promise if it runs asynchronously.
23 */
24 configure?(app: FrontendApplication): MaybePromise<void>;
25 /**
26 * Called when the application is started. The application shell is not attached yet when this method runs.
27 * Should return a promise if it runs asynchronously.
28 */
29 onStart?(app: FrontendApplication): MaybePromise<void>;
30 /**
31 * Called on `beforeunload` event, right before the window closes.
32 * Return `true` or an OnWillStopAction in order to prevent exit.
33 * Note: No async code allowed, this function has to run on one tick.
34 */
35 onWillStop?(app: FrontendApplication): boolean | undefined | OnWillStopAction<unknown>;
36 /**
37 * Called when an application is stopped or unloaded.
38 *
39 * Note that this is implemented using `window.beforeunload` which doesn't allow any asynchronous code anymore.
40 * I.e. this is the last tick.
41 */
42 onStop?(app: FrontendApplication): void;
43 /**
44 * Called after the application shell has been attached in case there is no previous workbench layout state.
45 * Should return a promise if it runs asynchronously.
46 */
47 initializeLayout?(app: FrontendApplication): MaybePromise<void>;
48 /**
49 * An event is emitted when a layout is initialized, but before the shell is attached.
50 */
51 onDidInitializeLayout?(app: FrontendApplication): MaybePromise<void>;
52}
53export interface OnWillStopAction<T = unknown> {
54 /**
55 * @resolves to a prepared value to be passed into the `action` function.
56 */
57 prepare?: (stopReason?: StopReason) => MaybePromise<T>;
58 /**
59 * @resolves to `true` if it is safe to close the application; `false` otherwise.
60 */
61 action: (prepared: T, stopReason?: StopReason) => MaybePromise<boolean>;
62 /**
63 * A descriptive string for the reason preventing close.
64 */
65 reason: string;
66 /**
67 * A number representing priority. Higher priority items are run later.
68 * High priority implies that some options of this check will have negative impacts if
69 * the user subsequently cancels the shutdown.
70 */
71 priority?: number;
72}
73export declare namespace OnWillStopAction {
74 function is(candidate: unknown): candidate is OnWillStopAction;
75}
76/**
77 * Default frontend contribution that can be extended by clients if they do not want to implement any of the
78 * methods from the interface but still want to contribute to the frontend application.
79 */
80export declare abstract class DefaultFrontendApplicationContribution implements FrontendApplicationContribution {
81 initialize(): void;
82}
83export declare class FrontendApplication {
84 protected readonly commands: CommandRegistry;
85 protected readonly menus: MenuModelRegistry;
86 protected readonly keybindings: KeybindingRegistry;
87 protected readonly layoutRestorer: ShellLayoutRestorer;
88 protected readonly contributions: ContributionProvider<FrontendApplicationContribution>;
89 protected readonly _shell: ApplicationShell;
90 protected readonly stateService: FrontendApplicationStateService;
91 protected readonly corePreferences: CorePreferences;
92 protected readonly windowsService: WindowService;
93 protected readonly tooltipService: TooltipService;
94 protected readonly stopwatch: Stopwatch;
95 protected readonly backendStopwatch: BackendStopwatch;
96 constructor(commands: CommandRegistry, menus: MenuModelRegistry, keybindings: KeybindingRegistry, layoutRestorer: ShellLayoutRestorer, contributions: ContributionProvider<FrontendApplicationContribution>, _shell: ApplicationShell, stateService: FrontendApplicationStateService);
97 get shell(): ApplicationShell;
98 /**
99 * Start the frontend application.
100 *
101 * Start up consists of the following steps:
102 * - start frontend contributions
103 * - attach the application shell to the host element
104 * - initialize the application shell layout
105 * - reveal the application shell if it was hidden by a startup indicator
106 */
107 start(): Promise<void>;
108 /**
109 * Return a promise to the host element to which the application shell is attached.
110 */
111 protected getHost(): Promise<HTMLElement>;
112 /**
113 * Return an HTML element that indicates the startup phase, e.g. with an animation or a splash screen.
114 */
115 protected getStartupIndicator(host: HTMLElement): HTMLElement | undefined;
116 /**
117 * Register global event listeners.
118 */
119 protected registerEventListeners(): void;
120 /**
121 * Attach the application shell to the host element. If a startup indicator is present, the shell is
122 * inserted before that indicator so it is not visible yet.
123 */
124 protected attachShell(host: HTMLElement): void;
125 /**
126 * Attach the tooltip container to the host element.
127 */
128 protected attachTooltip(host: HTMLElement): void;
129 /**
130 * If a startup indicator is present, it is first hidden with the `theia-hidden` CSS class and then
131 * removed after a while. The delay until removal is taken from the CSS transition duration.
132 */
133 protected revealShell(host: HTMLElement): Promise<void>;
134 /**
135 * Initialize the shell layout either using the layout restorer service or, if no layout has
136 * been stored, by creating the default layout.
137 */
138 protected initializeLayout(): Promise<void>;
139 /**
140 * Try to restore the shell layout from the storage service. Resolves to `true` if successful.
141 */
142 protected restoreLayout(): Promise<boolean>;
143 /**
144 * Let the frontend application contributions initialize the shell layout. Override this
145 * method in order to create an application-specific custom layout.
146 */
147 protected createDefaultLayout(): Promise<void>;
148 protected fireOnDidInitializeLayout(): Promise<void>;
149 /**
150 * Initialize and start the frontend application contributions.
151 */
152 protected startContributions(): Promise<void>;
153 /**
154 * Stop the frontend application contributions. This is called when the window is unloaded.
155 */
156 protected stopContributions(): void;
157 protected measure<T>(name: string, fn: () => MaybePromise<T>, message?: string, threshold?: boolean): Promise<T>;
158}
159//# sourceMappingURL=frontend-application.d.ts.map
\No newline at end of file