UNPKG

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