1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __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 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.ElectronWindowService = void 0;
|
28 | const electronRemote = require("../../../electron-shared/@electron/remote");
|
29 | const inversify_1 = require("inversify");
|
30 | const electron = require("../../../electron-shared/electron");
|
31 | const default_window_service_1 = require("../../browser/window/default-window-service");
|
32 | const electron_main_window_service_1 = require("../../electron-common/electron-main-window-service");
|
33 | const electron_window_preferences_1 = require("./electron-window-preferences");
|
34 | const electron_messages_1 = require("../../electron-common/messaging/electron-messages");
|
35 | let ElectronWindowService = class ElectronWindowService extends default_window_service_1.DefaultWindowService {
|
36 | constructor() {
|
37 | super(...arguments);
|
38 | |
39 |
|
40 |
|
41 | this.isUnloading = false;
|
42 | |
43 |
|
44 |
|
45 | this.closeOnUnload = false;
|
46 | }
|
47 | openNewWindow(url, { external } = {}) {
|
48 | this.delegate.openNewWindow(url, { external });
|
49 | return undefined;
|
50 | }
|
51 | openNewDefaultWindow() {
|
52 | this.delegate.openNewDefaultWindow();
|
53 | }
|
54 | init() {
|
55 |
|
56 | this.electronWindowPreferences.onPreferenceChanged(e => {
|
57 | if (e.preferenceName === 'window.zoomLevel') {
|
58 | this.updateWindowZoomLevel();
|
59 | }
|
60 | });
|
61 | }
|
62 | registerUnloadListeners() {
|
63 | electron.ipcRenderer.on(electron_messages_1.CLOSE_REQUESTED_SIGNAL, (_event, closeRequestEvent) => this.handleCloseRequestedEvent(closeRequestEvent));
|
64 | window.addEventListener('unload', () => this.onUnloadEmitter.fire());
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 | async handleCloseRequestedEvent(event) {
|
72 | const safeToClose = await this.isSafeToShutDown(event.reason);
|
73 | if (safeToClose) {
|
74 | console.debug(`Shutting down because of ${electron_messages_1.StopReason[event.reason]} request.`);
|
75 | electron.ipcRenderer.send(event.confirmChannel);
|
76 | }
|
77 | else {
|
78 | electron.ipcRenderer.send(event.cancelChannel);
|
79 | }
|
80 | }
|
81 | |
82 |
|
83 |
|
84 | updateWindowZoomLevel() {
|
85 | const preferredZoomLevel = this.electronWindowPreferences['window.zoomLevel'];
|
86 | const webContents = electronRemote.getCurrentWindow().webContents;
|
87 | if (webContents.getZoomLevel() !== preferredZoomLevel) {
|
88 | webContents.setZoomLevel(preferredZoomLevel);
|
89 | }
|
90 | }
|
91 | reload() {
|
92 | electron.ipcRenderer.send(electron_messages_1.RELOAD_REQUESTED_SIGNAL);
|
93 | }
|
94 | };
|
95 | __decorate([
|
96 | (0, inversify_1.inject)(electron_main_window_service_1.ElectronMainWindowService),
|
97 | __metadata("design:type", Object)
|
98 | ], ElectronWindowService.prototype, "delegate", void 0);
|
99 | __decorate([
|
100 | (0, inversify_1.inject)(electron_window_preferences_1.ElectronWindowPreferences),
|
101 | __metadata("design:type", Object)
|
102 | ], ElectronWindowService.prototype, "electronWindowPreferences", void 0);
|
103 | __decorate([
|
104 | (0, inversify_1.postConstruct)(),
|
105 | __metadata("design:type", Function),
|
106 | __metadata("design:paramtypes", []),
|
107 | __metadata("design:returntype", void 0)
|
108 | ], ElectronWindowService.prototype, "init", null);
|
109 | ElectronWindowService = __decorate([
|
110 | (0, inversify_1.injectable)()
|
111 | ], ElectronWindowService);
|
112 | exports.ElectronWindowService = ElectronWindowService;
|
113 |
|
\ | No newline at end of file |