1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | 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;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var DefaultSecondaryWindowService_1;
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | exports.DefaultSecondaryWindowService = void 0;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | const inversify_1 = require("inversify");
|
30 | const window_service_1 = require("./window-service");
|
31 | let DefaultSecondaryWindowService = DefaultSecondaryWindowService_1 = class DefaultSecondaryWindowService {
|
32 | constructor() {
|
33 | |
34 |
|
35 |
|
36 |
|
37 | this.prefix = crypto.getRandomValues(new Uint32Array(1))[0];
|
38 |
|
39 | this.nextId = 0;
|
40 | this.secondaryWindows = [];
|
41 | }
|
42 | init() {
|
43 |
|
44 | this.windowService.onUnload(() => {
|
45 |
|
46 | for (let i = this.secondaryWindows.length - 1; i >= 0; i--) {
|
47 | this.secondaryWindows[i].close();
|
48 | }
|
49 | });
|
50 | }
|
51 | createSecondaryWindow(onClose) {
|
52 | const win = this.doCreateSecondaryWindow(onClose);
|
53 | if (win) {
|
54 | this.secondaryWindows.push(win);
|
55 | }
|
56 | return win;
|
57 | }
|
58 | doCreateSecondaryWindow(onClose) {
|
59 | const win = window.open(DefaultSecondaryWindowService_1.SECONDARY_WINDOW_URL, this.nextWindowId(), 'popup');
|
60 | if (win) {
|
61 |
|
62 | win.addEventListener('DOMContentLoaded', () => {
|
63 | win.addEventListener('unload', () => {
|
64 | this.handleWindowClosed(win, onClose);
|
65 | });
|
66 | });
|
67 | }
|
68 | return win !== null && win !== void 0 ? win : undefined;
|
69 | }
|
70 | handleWindowClosed(win, onClose) {
|
71 | const extIndex = this.secondaryWindows.indexOf(win);
|
72 | if (extIndex > -1) {
|
73 | this.secondaryWindows.splice(extIndex, 1);
|
74 | }
|
75 | ;
|
76 | onClose === null || onClose === void 0 ? void 0 : onClose(win);
|
77 | }
|
78 | focus(win) {
|
79 | win.focus();
|
80 | }
|
81 | nextWindowId() {
|
82 | return `${this.prefix}-secondaryWindow-${this.nextId++}`;
|
83 | }
|
84 | };
|
85 |
|
86 | DefaultSecondaryWindowService.SECONDARY_WINDOW_URL = 'secondary-window.html';
|
87 | __decorate([
|
88 | (0, inversify_1.inject)(window_service_1.WindowService),
|
89 | __metadata("design:type", Object)
|
90 | ], DefaultSecondaryWindowService.prototype, "windowService", void 0);
|
91 | __decorate([
|
92 | (0, inversify_1.postConstruct)(),
|
93 | __metadata("design:type", Function),
|
94 | __metadata("design:paramtypes", []),
|
95 | __metadata("design:returntype", void 0)
|
96 | ], DefaultSecondaryWindowService.prototype, "init", null);
|
97 | DefaultSecondaryWindowService = DefaultSecondaryWindowService_1 = __decorate([
|
98 | (0, inversify_1.injectable)()
|
99 | ], DefaultSecondaryWindowService);
|
100 | exports.DefaultSecondaryWindowService = DefaultSecondaryWindowService;
|
101 |
|
\ | No newline at end of file |