UNPKG

8.14 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BrowserWindow, WebContents, Event as ElectronEvent } from '../../electron-shared/electron';
3import { ForkOptions } from 'child_process';
4import { FrontendApplicationConfig } from '@theia/application-package/lib/application-props';
5import URI from '../common/uri';
6import { Deferred } from '../common/promise-util';
7import { MaybePromise } from '../common/types';
8import { ContributionProvider } from '../common/contribution-provider';
9import { ElectronSecurityTokenService } from './electron-security-token-service';
10import { ElectronSecurityToken } from '../electron-common/electron-token';
11import Storage = require('electron-store');
12import { WindowSearchParams } from '../common/window';
13import { TheiaBrowserWindowOptions, TheiaElectronWindow, TheiaElectronWindowFactory } from './theia-electron-window';
14import { ElectronMainApplicationGlobals } from './electron-main-constants';
15export { ElectronMainApplicationGlobals };
16/**
17 * Options passed to the main/default command handler.
18 */
19export interface ElectronMainCommandOptions {
20 /**
21 * By default, the first positional argument. Should be either a relative or absolute file-system path pointing to a file or a folder.
22 */
23 readonly file?: string;
24}
25/**
26 * Fields related to a launch event.
27 *
28 * This kind of event is triggered in two different contexts:
29 * 1. The app is launched for the first time, `secondInstance` is false.
30 * 2. The app is already running but user relaunches it, `secondInstance` is true.
31 */
32export interface ElectronMainExecutionParams {
33 readonly secondInstance: boolean;
34 readonly argv: string[];
35 readonly cwd: string;
36}
37/**
38 * The default entrypoint will handle a very rudimentary CLI to open workspaces by doing `app path/to/workspace`. To override this behavior, you can extend and rebind the
39 * `ElectronMainApplication` class and overriding the `launch` method.
40 * A JSON-RPC communication between the Electron Main Process and the Renderer Processes is available: You can bind services using the `ElectronConnectionHandler` and
41 * `ElectronIpcConnectionProvider` APIs, example:
42 *
43 * From an `electron-main` module:
44 *
45 * bind(ElectronConnectionHandler).toDynamicValue(context =>
46 * new RpcConnectionHandler(electronMainWindowServicePath,
47 * () => context.container.get(ElectronMainWindowService))
48 * ).inSingletonScope();
49 *
50 * And from the `electron-browser` module:
51 *
52 * bind(ElectronMainWindowService).toDynamicValue(context =>
53 * ElectronIpcConnectionProvider.createProxy(context.container, electronMainWindowServicePath)
54 * ).inSingletonScope();
55 */
56export declare const ElectronMainApplicationContribution: unique symbol;
57export interface ElectronMainApplicationContribution {
58 /**
59 * The application is ready and is starting. This is the time to initialize
60 * services global to this process.
61 *
62 * Invoked when the electron-main process starts for the first time.
63 */
64 onStart?(application: ElectronMainApplication): MaybePromise<void>;
65 /**
66 * The application is stopping. Contributions must perform only synchronous operations.
67 */
68 onStop?(application: ElectronMainApplication): void;
69}
70export declare class ElectronMainProcessArgv {
71 protected get processArgvBinIndex(): number;
72 protected get isBundledElectronApp(): boolean;
73 protected get isElectronApp(): boolean;
74 getProcessArgvWithoutBin(argv?: string[]): Array<string>;
75 getProcessArgvBin(argv?: string[]): string;
76}
77export declare namespace ElectronMainProcessArgv {
78 interface ElectronMainProcess extends NodeJS.Process {
79 readonly defaultApp: boolean;
80 readonly versions: NodeJS.ProcessVersions & {
81 readonly electron: string;
82 };
83 }
84}
85export declare class ElectronMainApplication {
86 protected readonly contributions: ContributionProvider<ElectronMainApplicationContribution>;
87 protected readonly globals: ElectronMainApplicationGlobals;
88 protected processArgv: ElectronMainProcessArgv;
89 protected electronSecurityTokenService: ElectronSecurityTokenService;
90 protected readonly electronSecurityToken: ElectronSecurityToken;
91 protected readonly windowFactory: TheiaElectronWindowFactory;
92 protected readonly electronStore: Storage<{
93 windowstate?: TheiaBrowserWindowOptions | undefined;
94 }>;
95 protected readonly _backendPort: Deferred<number>;
96 readonly backendPort: Promise<number>;
97 protected _config: FrontendApplicationConfig | undefined;
98 protected useNativeWindowFrame: boolean;
99 protected customBackgroundColor?: string;
100 protected didUseNativeWindowFrameOnStart: Map<number, boolean>;
101 protected windows: Map<number, TheiaElectronWindow>;
102 protected restarting: boolean;
103 protected initialWindow?: BrowserWindow;
104 get config(): FrontendApplicationConfig;
105 start(config: FrontendApplicationConfig): Promise<void>;
106 protected getTitleBarStyle(config: FrontendApplicationConfig): 'native' | 'custom';
107 setTitleBarStyle(webContents: WebContents, style: string): void;
108 setBackgroundColor(webContents: WebContents, backgroundColor: string): void;
109 protected saveState(webContents: Electron.WebContents): void;
110 /**
111 * @param id the id of the WebContents of the BrowserWindow in question
112 * @returns 'native' or 'custom'
113 */
114 getTitleBarStyleAtStartup(webContents: WebContents): 'native' | 'custom';
115 protected showInitialWindow(): void;
116 protected launch(params: ElectronMainExecutionParams): Promise<void>;
117 /**
118 * Use this rather than creating `BrowserWindow` instances from scratch, since some security parameters need to be set, this method will do it.
119 *
120 * @param options
121 */
122 createWindow(asyncOptions?: MaybePromise<TheiaBrowserWindowOptions>): Promise<BrowserWindow>;
123 getLastWindowOptions(): Promise<TheiaBrowserWindowOptions>;
124 protected avoidOverlap(options: TheiaBrowserWindowOptions): TheiaBrowserWindowOptions;
125 protected getDefaultOptions(): TheiaBrowserWindowOptions;
126 openDefaultWindow(params?: WindowSearchParams): Promise<BrowserWindow>;
127 protected openWindowWithWorkspace(workspacePath: string): Promise<BrowserWindow>;
128 protected reuseOrCreateWindow(asyncOptions: MaybePromise<TheiaBrowserWindowOptions>): Promise<BrowserWindow>;
129 /** Configures native window creation, i.e. using window.open or links with target "_blank" in the frontend. */
130 protected configureNativeSecondaryWindowCreation(electronWindow: BrowserWindow): void;
131 /**
132 * "Gently" close all windows, application will not stop if a `beforeunload` handler returns `false`.
133 */
134 requestStop(): void;
135 protected handleMainCommand(params: ElectronMainExecutionParams, options: ElectronMainCommandOptions): Promise<void>;
136 protected createWindowUri(params?: WindowSearchParams): Promise<URI>;
137 protected getDefaultTheiaWindowOptions(): TheiaBrowserWindowOptions;
138 protected getDefaultTheiaWindowBounds(): TheiaBrowserWindowOptions;
139 /**
140 * Save the window geometry state on every change.
141 */
142 protected attachSaveWindowState(electronWindow: BrowserWindow): void;
143 protected saveWindowState(electronWindow: BrowserWindow): void;
144 /**
145 * Return a string unique to the current display layout.
146 */
147 protected getCurrentScreenLayout(): string;
148 /**
149 * Start the NodeJS backend server.
150 *
151 * @return Running server's port promise.
152 */
153 protected startBackend(): Promise<number>;
154 protected getForkOptions(): Promise<ForkOptions>;
155 protected attachElectronSecurityToken(port: number): Promise<void>;
156 protected hookApplicationEvents(): void;
157 protected onWillQuit(event: ElectronEvent): void;
158 protected onSecondInstance(event: ElectronEvent, argv: string[], cwd: string): Promise<void>;
159 protected onWindowAllClosed(event: ElectronEvent): void;
160 restart(webContents: WebContents): Promise<void>;
161 protected startContributions(): Promise<void>;
162 protected stopContributions(): void;
163}
164//# sourceMappingURL=electron-main-application.d.ts.map
\No newline at end of file