2020-07-14 06:46:59 +02:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the 'License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-08-25 20:58:41 +02:00
|
|
|
import type { RootDispatcher } from './dispatcher';
|
2022-04-06 23:57:14 +02:00
|
|
|
import { Dispatcher } from './dispatcher';
|
2022-04-07 07:21:27 +02:00
|
|
|
import type { Electron } from '../electron/electron';
|
|
|
|
|
import { ElectronApplication } from '../electron/electron';
|
2022-09-21 03:41:51 +02:00
|
|
|
import type * as channels from '@protocol/channels';
|
2020-07-14 06:46:59 +02:00
|
|
|
import { BrowserContextDispatcher } from './browserContextDispatcher';
|
2022-04-06 23:57:14 +02:00
|
|
|
import type { PageDispatcher } from './pageDispatcher';
|
2020-07-20 04:46:19 +02:00
|
|
|
import { parseArgument, serializeResult } from './jsHandleDispatcher';
|
2021-04-21 08:03:56 +02:00
|
|
|
import { ElementHandleDispatcher } from './elementHandlerDispatcher';
|
2020-07-14 06:46:59 +02:00
|
|
|
|
2022-08-26 18:30:27 +02:00
|
|
|
export class ElectronDispatcher extends Dispatcher<Electron, channels.ElectronChannel, RootDispatcher> implements channels.ElectronChannel {
|
2021-11-18 00:26:01 +01:00
|
|
|
_type_Electron = true;
|
2022-08-25 20:58:41 +02:00
|
|
|
|
|
|
|
|
constructor(scope: RootDispatcher, electron: Electron) {
|
2022-08-26 18:30:27 +02:00
|
|
|
super(scope, electron, 'Electron', {});
|
2020-07-14 06:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 20:25:33 +02:00
|
|
|
async launch(params: channels.ElectronLaunchParams): Promise<channels.ElectronLaunchResult> {
|
2021-02-01 20:43:26 +01:00
|
|
|
const electronApplication = await this._object.launch(params);
|
2022-08-26 18:30:27 +02:00
|
|
|
return { electronApplication: new ElectronApplicationDispatcher(this, electronApplication) };
|
2020-07-14 06:46:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 18:30:27 +02:00
|
|
|
export class ElectronApplicationDispatcher extends Dispatcher<ElectronApplication, channels.ElectronApplicationChannel, ElectronDispatcher> implements channels.ElectronApplicationChannel {
|
2021-11-18 00:26:01 +01:00
|
|
|
_type_EventTarget = true;
|
|
|
|
|
_type_ElectronApplication = true;
|
|
|
|
|
|
2022-08-25 20:58:41 +02:00
|
|
|
constructor(scope: ElectronDispatcher, electronApplication: ElectronApplication) {
|
2021-05-03 07:45:06 +02:00
|
|
|
super(scope, electronApplication, 'ElectronApplication', {
|
|
|
|
|
context: new BrowserContextDispatcher(scope, electronApplication.context())
|
2022-08-26 18:30:27 +02:00
|
|
|
});
|
2022-07-07 05:32:31 +02:00
|
|
|
this.addObjectListener(ElectronApplication.Events.Close, () => {
|
2020-07-25 01:22:20 +02:00
|
|
|
this._dispatchEvent('close');
|
|
|
|
|
this._dispose();
|
2020-07-14 06:46:59 +02:00
|
|
|
});
|
2021-05-03 07:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async browserWindow(params: channels.ElectronApplicationBrowserWindowParams): Promise<channels.ElectronApplicationBrowserWindowResult> {
|
|
|
|
|
const handle = await this._object.browserWindow((params.page as PageDispatcher).page());
|
2022-08-26 18:30:27 +02:00
|
|
|
return { handle: ElementHandleDispatcher.fromJSHandle(this, handle) };
|
2020-07-14 06:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 20:25:33 +02:00
|
|
|
async evaluateExpression(params: channels.ElectronApplicationEvaluateExpressionParams): Promise<channels.ElectronApplicationEvaluateExpressionResult> {
|
2021-05-03 07:45:06 +02:00
|
|
|
const handle = await this._object._nodeElectronHandlePromise;
|
2023-05-31 23:08:44 +02:00
|
|
|
return { value: serializeResult(await handle.evaluateExpression(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg))) };
|
2020-07-14 06:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 20:25:33 +02:00
|
|
|
async evaluateExpressionHandle(params: channels.ElectronApplicationEvaluateExpressionHandleParams): Promise<channels.ElectronApplicationEvaluateExpressionHandleResult> {
|
2021-05-03 07:45:06 +02:00
|
|
|
const handle = await this._object._nodeElectronHandlePromise;
|
2023-05-31 23:08:44 +02:00
|
|
|
const result = await handle.evaluateExpressionHandle(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg));
|
2022-08-26 18:30:27 +02:00
|
|
|
return { handle: ElementHandleDispatcher.fromJSHandle(this, result) };
|
2020-07-14 06:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async close(): Promise<void> {
|
|
|
|
|
await this._object.close();
|
|
|
|
|
}
|
|
|
|
|
}
|