/// <reference types="node" />
import { BrowserWindow, WebContents, Event as ElectronEvent } from '../../electron-shared/electron';
import { ForkOptions } from 'child_process';
import { FrontendApplicationConfig } from '@theia/application-package/lib/application-props';
import URI from '../common/uri';
import { Deferred } from '../common/promise-util';
import { MaybePromise } from '../common/types';
import { ContributionProvider } from '../common/contribution-provider';
import { ElectronSecurityTokenService } from './electron-security-token-service';
import { ElectronSecurityToken } from '../electron-common/electron-token';
import Storage = require('electron-store');
import { TheiaBrowserWindowOptions, TheiaElectronWindow, TheiaElectronWindowFactory } from './theia-electron-window';
import { ElectronMainApplicationGlobals } from './electron-main-constants';
export { ElectronMainApplicationGlobals };
/**
 * Options passed to the main/default command handler.
 */
export interface ElectronMainCommandOptions {
    /**
     * By default, the first positional argument. Should be either a relative or absolute file-system path pointing to a file or a folder.
     */
    readonly file?: string;
}
/**
 * Fields related to a launch event.
 *
 * This kind of event is triggered in two different contexts:
 *  1. The app is launched for the first time, `secondInstance` is false.
 *  2. The app is already running but user relaunches it, `secondInstance` is true.
 */
export interface ElectronMainExecutionParams {
    readonly secondInstance: boolean;
    readonly argv: string[];
    readonly cwd: string;
}
/**
 * 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
 * `ElectronMainApplication` class and overriding the `launch` method.
 * A JSON-RPC communication between the Electron Main Process and the Renderer Processes is available: You can bind services using the `ElectronConnectionHandler` and
 * `ElectronIpcConnectionProvider` APIs, example:
 *
 * From an `electron-main` module:
 *
 *     bind(ElectronConnectionHandler).toDynamicValue(context =>
 *          new RpcConnectionHandler(electronMainWindowServicePath,
 *          () => context.container.get(ElectronMainWindowService))
 *     ).inSingletonScope();
 *
 * And from the `electron-browser` module:
 *
 *     bind(ElectronMainWindowService).toDynamicValue(context =>
 *          ElectronIpcConnectionProvider.createProxy(context.container, electronMainWindowServicePath)
 *     ).inSingletonScope();
 */
export declare const ElectronMainApplicationContribution: unique symbol;
export interface ElectronMainApplicationContribution {
    /**
     * The application is ready and is starting. This is the time to initialize
     * services global to this process.
     *
     * Invoked when the electron-main process starts for the first time.
     */
    onStart?(application: ElectronMainApplication): MaybePromise<void>;
    /**
     * The application is stopping. Contributions must perform only synchronous operations.
     */
    onStop?(application: ElectronMainApplication): void;
}
export declare class ElectronMainProcessArgv {
    protected get processArgvBinIndex(): number;
    protected get isBundledElectronApp(): boolean;
    protected get isElectronApp(): boolean;
    getProcessArgvWithoutBin(argv?: string[]): Array<string>;
    getProcessArgvBin(argv?: string[]): string;
}
export declare namespace ElectronMainProcessArgv {
    interface ElectronMainProcess extends NodeJS.Process {
        readonly defaultApp: boolean;
        readonly versions: NodeJS.ProcessVersions & {
            readonly electron: string;
        };
    }
}
export declare class ElectronMainApplication {
    protected readonly contributions: ContributionProvider<ElectronMainApplicationContribution>;
    protected readonly globals: ElectronMainApplicationGlobals;
    protected processArgv: ElectronMainProcessArgv;
    protected electronSecurityTokenService: ElectronSecurityTokenService;
    protected readonly electronSecurityToken: ElectronSecurityToken;
    protected readonly windowFactory: TheiaElectronWindowFactory;
    protected readonly electronStore: Storage<{
        windowstate?: TheiaBrowserWindowOptions | undefined;
    }>;
    protected readonly _backendPort: Deferred<number>;
    readonly backendPort: Promise<number>;
    protected _config: FrontendApplicationConfig | undefined;
    protected useNativeWindowFrame: boolean;
    protected customBackgroundColor?: string;
    protected didUseNativeWindowFrameOnStart: Map<number, boolean>;
    protected windows: Map<number, TheiaElectronWindow>;
    protected restarting: boolean;
    protected initialWindow?: BrowserWindow;
    get config(): FrontendApplicationConfig;
    start(config: FrontendApplicationConfig): Promise<void>;
    protected getTitleBarStyle(config: FrontendApplicationConfig): 'native' | 'custom';
    setTitleBarStyle(webContents: WebContents, style: string): void;
    setBackgroundColor(webContents: WebContents, backgroundColor: string): void;
    protected saveState(webContents: Electron.WebContents): void;
    /**
     * @param id the id of the WebContents of the BrowserWindow in question
     * @returns 'native' or 'custom'
     */
    getTitleBarStyleAtStartup(webContents: WebContents): 'native' | 'custom';
    protected showInitialWindow(): void;
    protected launch(params: ElectronMainExecutionParams): Promise<void>;
    /**
     * Use this rather than creating `BrowserWindow` instances from scratch, since some security parameters need to be set, this method will do it.
     *
     * @param options
     */
    createWindow(asyncOptions?: MaybePromise<TheiaBrowserWindowOptions>): Promise<BrowserWindow>;
    getLastWindowOptions(): Promise<TheiaBrowserWindowOptions>;
    protected avoidOverlap(options: TheiaBrowserWindowOptions): TheiaBrowserWindowOptions;
    protected getDefaultOptions(): TheiaBrowserWindowOptions;
    openDefaultWindow(): Promise<BrowserWindow>;
    protected openWindowWithWorkspace(workspacePath: string): Promise<BrowserWindow>;
    protected reuseOrCreateWindow(asyncOptions: MaybePromise<TheiaBrowserWindowOptions>): Promise<BrowserWindow>;
    /** Configures native window creation, i.e. using window.open or links with target "_blank" in the frontend. */
    protected configureNativeSecondaryWindowCreation(electronWindow: BrowserWindow): void;
    /**
     * "Gently" close all windows, application will not stop if a `beforeunload` handler returns `false`.
     */
    requestStop(): void;
    protected handleMainCommand(params: ElectronMainExecutionParams, options: ElectronMainCommandOptions): Promise<void>;
    protected createWindowUri(): Promise<URI>;
    protected getDefaultTheiaWindowOptions(): TheiaBrowserWindowOptions;
    protected getDefaultTheiaWindowBounds(): TheiaBrowserWindowOptions;
    /**
     * Save the window geometry state on every change.
     */
    protected attachSaveWindowState(electronWindow: BrowserWindow): void;
    protected saveWindowState(electronWindow: BrowserWindow): void;
    /**
     * Return a string unique to the current display layout.
     */
    protected getCurrentScreenLayout(): string;
    /**
     * Start the NodeJS backend server.
     *
     * @return Running server's port promise.
     */
    protected startBackend(): Promise<number>;
    protected getForkOptions(): Promise<ForkOptions>;
    protected attachElectronSecurityToken(port: number): Promise<void>;
    protected hookApplicationEvents(): void;
    protected onWillQuit(event: ElectronEvent): void;
    protected onSecondInstance(event: ElectronEvent, argv: string[], cwd: string): Promise<void>;
    protected onWindowAllClosed(event: ElectronEvent): void;
    restart(webContents: WebContents): Promise<void>;
    protected startContributions(): Promise<void>;
    protected stopContributions(): void;
}
//# sourceMappingURL=electron-main-application.d.ts.map