@codingame/monaco-vscode-lifecycle-service-override 3.2.3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lifecycle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
2
- import { BrowserLifecycleService } from './vscode/src/vs/workbench/services/lifecycle/browser/lifecycleService.js';
2
+ import { BrowserLifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/browser/lifecycleService';
3
3
  import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
4
4
  import { ITimerService, TimerService } from 'vscode/vscode/vs/workbench/services/timer/browser/timerService';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-lifecycle-service-override",
3
- "version": "3.2.3",
3
+ "version": "4.1.0",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,6 +18,6 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@3.2.3"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.0"
22
22
  }
23
23
  }
@@ -1,11 +0,0 @@
1
- function __decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- 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;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
- function __param(paramIndex, decorator) {
8
- return function (target, key) { decorator(target, key, paramIndex); }
9
- }
10
-
11
- export { __decorate, __param };
@@ -1,125 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
3
- import { AbstractLifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycleService';
4
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
5
- import { addDisposableListener, EventType } from 'vscode/vscode/vs/base/browser/dom';
6
- import { WillSaveStateReason, IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
7
- import { CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
8
- import { mainWindow } from 'vscode/vscode/vs/base/browser/window';
9
-
10
- let BrowserLifecycleService = class BrowserLifecycleService extends AbstractLifecycleService {
11
- constructor(logService, storageService) {
12
- super(logService, storageService);
13
- this.beforeUnloadListener = undefined;
14
- this.unloadListener = undefined;
15
- this.ignoreBeforeUnload = false;
16
- this.didUnload = false;
17
- this.registerListeners();
18
- }
19
- registerListeners() {
20
- this.beforeUnloadListener = addDisposableListener(mainWindow, EventType.BEFORE_UNLOAD, (e) => this.onBeforeUnload(e));
21
- this.unloadListener = addDisposableListener(mainWindow, EventType.PAGE_HIDE, () => this.onUnload());
22
- }
23
- onBeforeUnload(event) {
24
- if (this.ignoreBeforeUnload) {
25
- this.logService.info('[lifecycle] onBeforeUnload triggered but ignored once');
26
- this.ignoreBeforeUnload = false;
27
- }
28
- else {
29
- this.logService.info('[lifecycle] onBeforeUnload triggered and handled with veto support');
30
- this.doShutdown(() => this.vetoBeforeUnload(event));
31
- }
32
- }
33
- vetoBeforeUnload(event) {
34
- event.preventDefault();
35
- event.returnValue = ( localizeWithPath(
36
- 'vs/workbench/services/lifecycle/browser/lifecycleService',
37
- 'lifecycleVeto',
38
- "Changes that you made may not be saved. Please check press 'Cancel' and try again."
39
- ));
40
- }
41
- withExpectedShutdown(reason, callback) {
42
- if (typeof reason === 'number') {
43
- this.shutdownReason = reason;
44
- return this.storageService.flush(WillSaveStateReason.SHUTDOWN);
45
- }
46
- else {
47
- this.ignoreBeforeUnload = true;
48
- try {
49
- callback?.();
50
- }
51
- finally {
52
- this.ignoreBeforeUnload = false;
53
- }
54
- }
55
- }
56
- async shutdown() {
57
- this.logService.info('[lifecycle] shutdown triggered');
58
- this.beforeUnloadListener?.dispose();
59
- this.unloadListener?.dispose();
60
- await this.storageService.flush(WillSaveStateReason.SHUTDOWN);
61
- this.doShutdown();
62
- }
63
- doShutdown(vetoShutdown) {
64
- const logService = this.logService;
65
- this.storageService.flush(WillSaveStateReason.SHUTDOWN);
66
- let veto = false;
67
- function handleVeto(vetoResult, id) {
68
- if (typeof vetoShutdown !== 'function') {
69
- return;
70
- }
71
- if (vetoResult instanceof Promise) {
72
- logService.error(`[lifecycle] Long running operations before shutdown are unsupported in the web (id: ${id})`);
73
- veto = true;
74
- }
75
- if (vetoResult === true) {
76
- logService.info(`[lifecycle]: Unload was prevented (id: ${id})`);
77
- veto = true;
78
- }
79
- }
80
- this._onBeforeShutdown.fire({
81
- reason: 2 ,
82
- veto(value, id) {
83
- handleVeto(value, id);
84
- },
85
- finalVeto(valueFn, id) {
86
- handleVeto(valueFn(), id);
87
- }
88
- });
89
- if (veto && typeof vetoShutdown === 'function') {
90
- return vetoShutdown();
91
- }
92
- return this.onUnload();
93
- }
94
- onUnload() {
95
- if (this.didUnload) {
96
- return;
97
- }
98
- this.didUnload = true;
99
- this._register(addDisposableListener(mainWindow, EventType.PAGE_SHOW, (e) => this.onLoadAfterUnload(e)));
100
- const logService = this.logService;
101
- this._onWillShutdown.fire({
102
- reason: 2 ,
103
- joiners: () => [],
104
- token: CancellationToken.None,
105
- join(promise, joiner) {
106
- logService.error(`[lifecycle] Long running operations during shutdown are unsupported in the web (id: ${joiner.id})`);
107
- },
108
- force: () => { },
109
- });
110
- this._onDidShutdown.fire();
111
- }
112
- onLoadAfterUnload(event) {
113
- const wasRestoredFromCache = event.persisted;
114
- if (!wasRestoredFromCache) {
115
- return;
116
- }
117
- this.withExpectedShutdown({ disableShutdownHandling: true }, () => mainWindow.location.reload());
118
- }
119
- };
120
- BrowserLifecycleService = ( __decorate([
121
- ( __param(0, ILogService)),
122
- ( __param(1, IStorageService))
123
- ], BrowserLifecycleService));
124
-
125
- export { BrowserLifecycleService };