UNPKG

3.84 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2022 STMicroelectronics, Ericsson, ARM, EclipseSource and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21 return c > 3 && r && Object.defineProperty(target, key, r), r;
22};
23Object.defineProperty(exports, "__esModule", { value: true });
24exports.ElectronSecondaryWindowService = void 0;
25const electronRemote = require("../../../electron-shared/@electron/remote");
26const inversify_1 = require("inversify");
27const default_secondary_window_service_1 = require("../../browser/window/default-secondary-window-service");
28let ElectronSecondaryWindowService = class ElectronSecondaryWindowService extends default_secondary_window_service_1.DefaultSecondaryWindowService {
29 constructor() {
30 super(...arguments);
31 this.electronWindows = new Map();
32 }
33 doCreateSecondaryWindow(onClose) {
34 const id = this.nextWindowId();
35 electronRemote.getCurrentWindow().webContents.once('did-create-window', newElectronWindow => {
36 newElectronWindow.setMenuBarVisibility(false);
37 this.electronWindows.set(id, newElectronWindow);
38 newElectronWindow.on('closed', () => {
39 this.electronWindows.delete(id);
40 const browserWin = this.secondaryWindows.find(w => w.name === id);
41 if (browserWin) {
42 this.handleWindowClosed(browserWin, onClose);
43 }
44 else {
45 console.warn(`Could not execute proper close handling for secondary window '${id}' because its frontend window could not be found.`);
46 }
47 ;
48 });
49 });
50 const win = window.open(default_secondary_window_service_1.DefaultSecondaryWindowService.SECONDARY_WINDOW_URL, id);
51 return win !== null && win !== void 0 ? win : undefined;
52 }
53 focus(win) {
54 // window.name is the target name given to the window.open call as the second parameter.
55 const electronWindow = this.electronWindows.get(win.name);
56 if (electronWindow) {
57 if (electronWindow.isMinimized()) {
58 electronWindow.restore();
59 }
60 electronWindow.focus();
61 }
62 else {
63 console.warn(`There is no known secondary window '${win.name}'. Thus, the window could not be focussed.`);
64 }
65 }
66};
67ElectronSecondaryWindowService = __decorate([
68 (0, inversify_1.injectable)()
69], ElectronSecondaryWindowService);
70exports.ElectronSecondaryWindowService = ElectronSecondaryWindowService;
71//# sourceMappingURL=electron-secondary-window-service.js.map
\No newline at end of file