@codingame/monaco-vscode-notifications-service-override 4.1.0 → 4.1.1

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.
@@ -0,0 +1,11 @@
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 };
package/notifications.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { NotificationsToasts } from 'vscode/vscode/vs/workbench/browser/parts/notifications/notificationsToasts';
2
2
  import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
3
- import { NotificationService } from 'vscode/vscode/vs/workbench/services/notification/common/notificationService';
3
+ import { NotificationService } from './vscode/src/vs/workbench/services/notification/common/notificationService.js';
4
4
  import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
5
5
  import { getClientArea } from 'vscode/vscode/vs/base/browser/dom';
6
6
  import { registerNotificationCommands } from 'vscode/vscode/vs/workbench/browser/parts/notifications/notificationsCommands';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-notifications-service-override",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
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@4.1.0"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.1"
22
22
  }
23
23
  }
@@ -0,0 +1,253 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
3
+ import { isNotificationSource, NotificationsFilter, Severity, NoOpNotification, NeverShowAgainScope } from 'vscode/vscode/vs/platform/notification/common/notification';
4
+ import { NotificationsModel, ChoiceAction } from 'vscode/vscode/vs/workbench/common/notifications';
5
+ import { Disposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
6
+ import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
7
+ import { Action } from 'vscode/vscode/vs/base/common/actions';
8
+ import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
9
+
10
+ var NotificationService_1;
11
+ let NotificationService = class NotificationService extends Disposable {
12
+ static { NotificationService_1 = this; }
13
+ constructor(storageService) {
14
+ super();
15
+ this.storageService = storageService;
16
+ this.model = this._register(( new NotificationsModel()));
17
+ this._onDidAddNotification = this._register(( new Emitter()));
18
+ this.onDidAddNotification = this._onDidAddNotification.event;
19
+ this._onDidRemoveNotification = this._register(( new Emitter()));
20
+ this.onDidRemoveNotification = this._onDidRemoveNotification.event;
21
+ this._onDidChangeFilter = this._register(( new Emitter()));
22
+ this.onDidChangeFilter = this._onDidChangeFilter.event;
23
+ this.globalFilterEnabled = this.storageService.getBoolean(NotificationService_1.GLOBAL_FILTER_SETTINGS_KEY, -1 , false);
24
+ this.mapSourceToFilter = (() => {
25
+ const map = ( new Map());
26
+ for (const sourceFilter of this.storageService.getObject(NotificationService_1.PER_SOURCE_FILTER_SETTINGS_KEY, -1 , [])) {
27
+ map.set(sourceFilter.id, sourceFilter);
28
+ }
29
+ return map;
30
+ })();
31
+ this.updateFilters();
32
+ this.registerListeners();
33
+ }
34
+ registerListeners() {
35
+ this._register(this.model.onDidChangeNotification(e => {
36
+ switch (e.kind) {
37
+ case 0 :
38
+ case 3 : {
39
+ const source = typeof e.item.sourceId === 'string' && typeof e.item.source === 'string' ? { id: e.item.sourceId, label: e.item.source } : e.item.source;
40
+ const notification = {
41
+ message: e.item.message.original,
42
+ severity: e.item.severity,
43
+ source,
44
+ priority: e.item.priority
45
+ };
46
+ if (e.kind === 0 ) {
47
+ if (isNotificationSource(source)) {
48
+ if (!( this.mapSourceToFilter.has(source.id))) {
49
+ this.setFilter({ ...source, filter: NotificationsFilter.OFF });
50
+ }
51
+ else {
52
+ this.updateSourceFilter(source);
53
+ }
54
+ }
55
+ this._onDidAddNotification.fire(notification);
56
+ }
57
+ if (e.kind === 3 ) {
58
+ this._onDidRemoveNotification.fire(notification);
59
+ }
60
+ break;
61
+ }
62
+ }
63
+ }));
64
+ }
65
+ static { this.GLOBAL_FILTER_SETTINGS_KEY = 'notifications.doNotDisturbMode'; }
66
+ static { this.PER_SOURCE_FILTER_SETTINGS_KEY = 'notifications.perSourceDoNotDisturbMode'; }
67
+ setFilter(filter) {
68
+ if (typeof filter === 'number') {
69
+ if (this.globalFilterEnabled === (filter === NotificationsFilter.ERROR)) {
70
+ return;
71
+ }
72
+ this.globalFilterEnabled = filter === NotificationsFilter.ERROR;
73
+ this.storageService.store(NotificationService_1.GLOBAL_FILTER_SETTINGS_KEY, this.globalFilterEnabled, -1 , 1 );
74
+ this.updateFilters();
75
+ this._onDidChangeFilter.fire();
76
+ }
77
+ else {
78
+ const existing = this.mapSourceToFilter.get(filter.id);
79
+ if (existing?.filter === filter.filter && existing.label === filter.label) {
80
+ return;
81
+ }
82
+ this.mapSourceToFilter.set(filter.id, { id: filter.id, label: filter.label, filter: filter.filter });
83
+ this.saveSourceFilters();
84
+ this.updateFilters();
85
+ }
86
+ }
87
+ getFilter(source) {
88
+ if (source) {
89
+ return this.mapSourceToFilter.get(source.id)?.filter ?? NotificationsFilter.OFF;
90
+ }
91
+ return this.globalFilterEnabled ? NotificationsFilter.ERROR : NotificationsFilter.OFF;
92
+ }
93
+ updateSourceFilter(source) {
94
+ const existing = this.mapSourceToFilter.get(source.id);
95
+ if (!existing) {
96
+ return;
97
+ }
98
+ if (existing.label !== source.label) {
99
+ this.mapSourceToFilter.set(source.id, { id: source.id, label: source.label, filter: existing.filter });
100
+ this.saveSourceFilters();
101
+ }
102
+ }
103
+ saveSourceFilters() {
104
+ this.storageService.store(NotificationService_1.PER_SOURCE_FILTER_SETTINGS_KEY, JSON.stringify([...( this.mapSourceToFilter.values())]), -1 , 1 );
105
+ }
106
+ getFilters() {
107
+ return [...( this.mapSourceToFilter.values())];
108
+ }
109
+ updateFilters() {
110
+ this.model.setFilter({
111
+ global: this.globalFilterEnabled ? NotificationsFilter.ERROR : NotificationsFilter.OFF,
112
+ sources: ( new Map(( [...( this.mapSourceToFilter.values())].map(source => [source.id, source.filter]))))
113
+ });
114
+ }
115
+ removeFilter(sourceId) {
116
+ if (this.mapSourceToFilter.delete(sourceId)) {
117
+ this.saveSourceFilters();
118
+ this.updateFilters();
119
+ }
120
+ }
121
+ info(message) {
122
+ if (Array.isArray(message)) {
123
+ for (const messageEntry of message) {
124
+ this.info(messageEntry);
125
+ }
126
+ return;
127
+ }
128
+ this.model.addNotification({ severity: Severity.Info, message });
129
+ }
130
+ warn(message) {
131
+ if (Array.isArray(message)) {
132
+ for (const messageEntry of message) {
133
+ this.warn(messageEntry);
134
+ }
135
+ return;
136
+ }
137
+ this.model.addNotification({ severity: Severity.Warning, message });
138
+ }
139
+ error(message) {
140
+ if (Array.isArray(message)) {
141
+ for (const messageEntry of message) {
142
+ this.error(messageEntry);
143
+ }
144
+ return;
145
+ }
146
+ this.model.addNotification({ severity: Severity.Error, message });
147
+ }
148
+ notify(notification) {
149
+ const toDispose = ( new DisposableStore());
150
+ if (notification.neverShowAgain) {
151
+ const scope = this.toStorageScope(notification.neverShowAgain);
152
+ const id = notification.neverShowAgain.id;
153
+ if (this.storageService.getBoolean(id, scope)) {
154
+ return ( new NoOpNotification());
155
+ }
156
+ const neverShowAgainAction = toDispose.add(( new Action('workbench.notification.neverShowAgain', ( localizeWithPath(
157
+ 'vs/workbench/services/notification/common/notificationService',
158
+ 'neverShowAgain',
159
+ "Don't Show Again"
160
+ )), undefined, true, async () => {
161
+ handle.close();
162
+ this.storageService.store(id, true, scope, 0 );
163
+ })));
164
+ const actions = {
165
+ primary: notification.actions?.primary || [],
166
+ secondary: notification.actions?.secondary || []
167
+ };
168
+ if (!notification.neverShowAgain.isSecondary) {
169
+ actions.primary = [neverShowAgainAction, ...actions.primary];
170
+ }
171
+ else {
172
+ actions.secondary = [...actions.secondary, neverShowAgainAction];
173
+ }
174
+ notification.actions = actions;
175
+ }
176
+ const handle = this.model.addNotification(notification);
177
+ Event.once(handle.onDidClose)(() => toDispose.dispose());
178
+ return handle;
179
+ }
180
+ toStorageScope(options) {
181
+ switch (options.scope) {
182
+ case NeverShowAgainScope.APPLICATION:
183
+ return -1 ;
184
+ case NeverShowAgainScope.PROFILE:
185
+ return 0 ;
186
+ case NeverShowAgainScope.WORKSPACE:
187
+ return 1 ;
188
+ default:
189
+ return -1 ;
190
+ }
191
+ }
192
+ prompt(severity, message, choices, options) {
193
+ const toDispose = ( new DisposableStore());
194
+ if (options?.neverShowAgain) {
195
+ const scope = this.toStorageScope(options.neverShowAgain);
196
+ const id = options.neverShowAgain.id;
197
+ if (this.storageService.getBoolean(id, scope)) {
198
+ return ( new NoOpNotification());
199
+ }
200
+ const neverShowAgainChoice = {
201
+ label: ( localizeWithPath(
202
+ 'vs/workbench/services/notification/common/notificationService',
203
+ 'neverShowAgain',
204
+ "Don't Show Again"
205
+ )),
206
+ run: () => this.storageService.store(id, true, scope, 0 ),
207
+ isSecondary: options.neverShowAgain.isSecondary
208
+ };
209
+ if (!options.neverShowAgain.isSecondary) {
210
+ choices = [neverShowAgainChoice, ...choices];
211
+ }
212
+ else {
213
+ choices = [...choices, neverShowAgainChoice];
214
+ }
215
+ }
216
+ let choiceClicked = false;
217
+ const primaryActions = [];
218
+ const secondaryActions = [];
219
+ choices.forEach((choice, index) => {
220
+ const action = ( new ChoiceAction(`workbench.dialog.choice.${index}`, choice));
221
+ if (!choice.isSecondary) {
222
+ primaryActions.push(action);
223
+ }
224
+ else {
225
+ secondaryActions.push(action);
226
+ }
227
+ toDispose.add(action.onDidRun(() => {
228
+ choiceClicked = true;
229
+ if (!choice.keepOpen) {
230
+ handle.close();
231
+ }
232
+ }));
233
+ toDispose.add(action);
234
+ });
235
+ const actions = { primary: primaryActions, secondary: secondaryActions };
236
+ const handle = this.notify({ severity, message, actions, sticky: options?.sticky, priority: options?.priority });
237
+ Event.once(handle.onDidClose)(() => {
238
+ toDispose.dispose();
239
+ if (options && typeof options.onCancel === 'function' && !choiceClicked) {
240
+ options.onCancel();
241
+ }
242
+ });
243
+ return handle;
244
+ }
245
+ status(message, options) {
246
+ return this.model.showStatusMessage(message, options);
247
+ }
248
+ };
249
+ NotificationService = NotificationService_1 = ( __decorate([
250
+ ( __param(0, IStorageService))
251
+ ], NotificationService));
252
+
253
+ export { NotificationService };