electronDispatcher.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ElectronDispatcher = exports.ElectronApplicationDispatcher = void 0;
  6. var _dispatcher = require("./dispatcher");
  7. var _electron = require("../electron/electron");
  8. var _browserContextDispatcher = require("./browserContextDispatcher");
  9. var _jsHandleDispatcher = require("./jsHandleDispatcher");
  10. var _elementHandlerDispatcher = require("./elementHandlerDispatcher");
  11. /**
  12. * Copyright (c) Microsoft Corporation.
  13. *
  14. * Licensed under the Apache License, Version 2.0 (the 'License");
  15. * you may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at
  17. *
  18. * http://www.apache.org/licenses/LICENSE-2.0
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. */
  26. class ElectronDispatcher extends _dispatcher.Dispatcher {
  27. constructor(scope, electron) {
  28. super(scope, electron, 'Electron', {});
  29. this._type_Electron = true;
  30. }
  31. async launch(params) {
  32. const electronApplication = await this._object.launch(params);
  33. return {
  34. electronApplication: new ElectronApplicationDispatcher(this, electronApplication)
  35. };
  36. }
  37. }
  38. exports.ElectronDispatcher = ElectronDispatcher;
  39. class ElectronApplicationDispatcher extends _dispatcher.Dispatcher {
  40. constructor(scope, electronApplication) {
  41. super(scope, electronApplication, 'ElectronApplication', {
  42. context: new _browserContextDispatcher.BrowserContextDispatcher(scope, electronApplication.context())
  43. });
  44. this._type_EventTarget = true;
  45. this._type_ElectronApplication = true;
  46. this.addObjectListener(_electron.ElectronApplication.Events.Close, () => {
  47. this._dispatchEvent('close');
  48. this._dispose();
  49. });
  50. }
  51. async browserWindow(params) {
  52. const handle = await this._object.browserWindow(params.page.page());
  53. return {
  54. handle: _elementHandlerDispatcher.ElementHandleDispatcher.fromJSHandle(this, handle)
  55. };
  56. }
  57. async evaluateExpression(params) {
  58. const handle = await this._object._nodeElectronHandlePromise;
  59. return {
  60. value: (0, _jsHandleDispatcher.serializeResult)(await handle.evaluateExpression(params.expression, {
  61. isFunction: params.isFunction
  62. }, (0, _jsHandleDispatcher.parseArgument)(params.arg)))
  63. };
  64. }
  65. async evaluateExpressionHandle(params) {
  66. const handle = await this._object._nodeElectronHandlePromise;
  67. const result = await handle.evaluateExpressionHandle(params.expression, {
  68. isFunction: params.isFunction
  69. }, (0, _jsHandleDispatcher.parseArgument)(params.arg));
  70. return {
  71. handle: _elementHandlerDispatcher.ElementHandleDispatcher.fromJSHandle(this, result)
  72. };
  73. }
  74. async close() {
  75. await this._object.close();
  76. }
  77. }
  78. exports.ElectronApplicationDispatcher = ElectronApplicationDispatcher;