@theia/messages 1.48.1 → 1.48.2

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.
Files changed (37) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/messages-frontend-module.d.ts +4 -4
  3. package/lib/browser/messages-frontend-module.js +41 -41
  4. package/lib/browser/notification-center-component.d.ts +18 -18
  5. package/lib/browser/notification-center-component.js +67 -67
  6. package/lib/browser/notification-component.d.ts +15 -15
  7. package/lib/browser/notification-component.js +88 -88
  8. package/lib/browser/notification-content-renderer.d.ts +5 -5
  9. package/lib/browser/notification-content-renderer.js +35 -35
  10. package/lib/browser/notification-content-renderer.spec.d.ts +1 -1
  11. package/lib/browser/notification-content-renderer.spec.js +41 -41
  12. package/lib/browser/notification-preferences.d.ts +11 -11
  13. package/lib/browser/notification-preferences.js +46 -46
  14. package/lib/browser/notification-toasts-component.d.ts +18 -18
  15. package/lib/browser/notification-toasts-component.js +48 -48
  16. package/lib/browser/notifications-commands.d.ts +7 -7
  17. package/lib/browser/notifications-commands.js +47 -47
  18. package/lib/browser/notifications-contribution.d.ts +21 -21
  19. package/lib/browser/notifications-contribution.js +203 -203
  20. package/lib/browser/notifications-manager.d.ts +71 -71
  21. package/lib/browser/notifications-manager.js +274 -274
  22. package/lib/browser/notifications-renderer.d.ts +13 -13
  23. package/lib/browser/notifications-renderer.js +67 -67
  24. package/package.json +4 -4
  25. package/src/browser/messages-frontend-module.ts +42 -42
  26. package/src/browser/notification-center-component.tsx +95 -95
  27. package/src/browser/notification-component.tsx +128 -128
  28. package/src/browser/notification-content-renderer.spec.ts +73 -73
  29. package/src/browser/notification-content-renderer.ts +31 -31
  30. package/src/browser/notification-preferences.ts +58 -58
  31. package/src/browser/notification-toasts-component.tsx +67 -67
  32. package/src/browser/notifications-commands.ts +50 -50
  33. package/src/browser/notifications-contribution.ts +218 -218
  34. package/src/browser/notifications-manager.ts +305 -305
  35. package/src/browser/notifications-renderer.tsx +61 -61
  36. package/src/browser/style/index.css +17 -17
  37. package/src/browser/style/notifications.css +283 -283
@@ -1,128 +1,128 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as React from '@theia/core/shared/react';
18
- import * as DOMPurify from '@theia/core/shared/dompurify';
19
- import { NotificationManager, Notification } from './notifications-manager';
20
- import { codicon } from '@theia/core/lib/browser';
21
- import { nls } from '@theia/core/lib/common/nls';
22
-
23
- export interface NotificationComponentProps {
24
- readonly manager: NotificationManager;
25
- readonly notification: Notification;
26
- }
27
-
28
- export class NotificationComponent extends React.Component<NotificationComponentProps> {
29
-
30
- constructor(props: NotificationComponentProps) {
31
- super(props);
32
- this.state = {};
33
- }
34
-
35
- protected onClear = (event: React.MouseEvent) => {
36
- if (event.target instanceof HTMLElement) {
37
- const messageId = event.target.dataset.messageId;
38
- if (messageId) {
39
- this.props.manager.clear(messageId);
40
- }
41
- }
42
- };
43
-
44
- protected onToggleExpansion = (event: React.MouseEvent) => {
45
- if (event.target instanceof HTMLElement) {
46
- const messageId = event.target.dataset.messageId;
47
- if (messageId) {
48
- this.props.manager.toggleExpansion(messageId);
49
- }
50
- }
51
- };
52
-
53
- protected onAction = (event: React.MouseEvent) => {
54
- if (event.target instanceof HTMLElement) {
55
- const messageId = event.target.dataset.messageId;
56
- const action = event.target.dataset.action;
57
- if (messageId && action) {
58
- this.props.manager.accept(messageId, action);
59
- }
60
- }
61
- };
62
-
63
- protected onMessageClick = (event: React.MouseEvent) => {
64
- if (event.target instanceof HTMLAnchorElement) {
65
- event.stopPropagation();
66
- event.preventDefault();
67
- const link = event.target.href;
68
- this.props.manager.openLink(link);
69
- }
70
- };
71
-
72
- override render(): React.ReactNode {
73
- const { messageId, message, type, progress, collapsed, expandable, source, actions } = this.props.notification;
74
- const isProgress = type === 'progress' || typeof progress === 'number';
75
- const icon = type === 'progress' ? 'info' : type;
76
- return (<div key={messageId} className='theia-notification-list-item-container'>
77
- <div className='theia-notification-list-item' tabIndex={0}>
78
- <div className={`theia-notification-list-item-content ${collapsed ? 'collapsed' : ''}`}>
79
- <div className='theia-notification-list-item-content-main'>
80
- <div className={`theia-notification-icon ${codicon(icon)} ${icon}`} />
81
- <div className='theia-notification-message'>
82
- <span
83
- // eslint-disable-next-line react/no-danger
84
- dangerouslySetInnerHTML={{
85
- __html: DOMPurify.sanitize(message, {
86
- ALLOW_UNKNOWN_PROTOCOLS: true // DOMPurify usually strips non http(s) links from hrefs
87
- })
88
- }}
89
- onClick={this.onMessageClick}
90
- />
91
- </div>
92
- <ul className='theia-notification-actions'>
93
- {expandable && (
94
- <li className={codicon('chevron-down', true) + (collapsed ? ' expand' : ' collapse')} title={collapsed ? 'Expand' : 'Collapse'}
95
- data-message-id={messageId} onClick={this.onToggleExpansion} />
96
- )}
97
- {!isProgress && (<li className={codicon('close', true)} title={nls.localizeByDefault('Clear')} data-message-id={messageId}
98
- onClick={this.onClear} />)}
99
- </ul>
100
- </div>
101
- {(source || !!actions.length) && (
102
- <div className='theia-notification-list-item-content-bottom'>
103
- <div className='theia-notification-source'>
104
- {source && (<span>{source}</span>)}
105
- </div>
106
- <div className='theia-notification-buttons'>
107
- {actions && actions.map((action, index) => (
108
- <button key={messageId + `-action-${index}`} className='theia-button'
109
- data-message-id={messageId} data-action={action}
110
- onClick={this.onAction}>
111
- {action}
112
- </button>
113
- ))}
114
- </div>
115
- </div>
116
- )}
117
- </div>
118
- {isProgress && (
119
- <div className='theia-notification-item-progress'>
120
- <div className={`theia-notification-item-progressbar ${progress ? 'determinate' : 'indeterminate'}`}
121
- style={{ width: `${progress ?? '100'}%` }} />
122
- </div>
123
- )}
124
- </div>
125
- </div>);
126
- }
127
-
128
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as React from '@theia/core/shared/react';
18
+ import * as DOMPurify from '@theia/core/shared/dompurify';
19
+ import { NotificationManager, Notification } from './notifications-manager';
20
+ import { codicon } from '@theia/core/lib/browser';
21
+ import { nls } from '@theia/core/lib/common/nls';
22
+
23
+ export interface NotificationComponentProps {
24
+ readonly manager: NotificationManager;
25
+ readonly notification: Notification;
26
+ }
27
+
28
+ export class NotificationComponent extends React.Component<NotificationComponentProps> {
29
+
30
+ constructor(props: NotificationComponentProps) {
31
+ super(props);
32
+ this.state = {};
33
+ }
34
+
35
+ protected onClear = (event: React.MouseEvent) => {
36
+ if (event.target instanceof HTMLElement) {
37
+ const messageId = event.target.dataset.messageId;
38
+ if (messageId) {
39
+ this.props.manager.clear(messageId);
40
+ }
41
+ }
42
+ };
43
+
44
+ protected onToggleExpansion = (event: React.MouseEvent) => {
45
+ if (event.target instanceof HTMLElement) {
46
+ const messageId = event.target.dataset.messageId;
47
+ if (messageId) {
48
+ this.props.manager.toggleExpansion(messageId);
49
+ }
50
+ }
51
+ };
52
+
53
+ protected onAction = (event: React.MouseEvent) => {
54
+ if (event.target instanceof HTMLElement) {
55
+ const messageId = event.target.dataset.messageId;
56
+ const action = event.target.dataset.action;
57
+ if (messageId && action) {
58
+ this.props.manager.accept(messageId, action);
59
+ }
60
+ }
61
+ };
62
+
63
+ protected onMessageClick = (event: React.MouseEvent) => {
64
+ if (event.target instanceof HTMLAnchorElement) {
65
+ event.stopPropagation();
66
+ event.preventDefault();
67
+ const link = event.target.href;
68
+ this.props.manager.openLink(link);
69
+ }
70
+ };
71
+
72
+ override render(): React.ReactNode {
73
+ const { messageId, message, type, progress, collapsed, expandable, source, actions } = this.props.notification;
74
+ const isProgress = type === 'progress' || typeof progress === 'number';
75
+ const icon = type === 'progress' ? 'info' : type;
76
+ return (<div key={messageId} className='theia-notification-list-item-container'>
77
+ <div className='theia-notification-list-item' tabIndex={0}>
78
+ <div className={`theia-notification-list-item-content ${collapsed ? 'collapsed' : ''}`}>
79
+ <div className='theia-notification-list-item-content-main'>
80
+ <div className={`theia-notification-icon ${codicon(icon)} ${icon}`} />
81
+ <div className='theia-notification-message'>
82
+ <span
83
+ // eslint-disable-next-line react/no-danger
84
+ dangerouslySetInnerHTML={{
85
+ __html: DOMPurify.sanitize(message, {
86
+ ALLOW_UNKNOWN_PROTOCOLS: true // DOMPurify usually strips non http(s) links from hrefs
87
+ })
88
+ }}
89
+ onClick={this.onMessageClick}
90
+ />
91
+ </div>
92
+ <ul className='theia-notification-actions'>
93
+ {expandable && (
94
+ <li className={codicon('chevron-down', true) + (collapsed ? ' expand' : ' collapse')} title={collapsed ? 'Expand' : 'Collapse'}
95
+ data-message-id={messageId} onClick={this.onToggleExpansion} />
96
+ )}
97
+ {!isProgress && (<li className={codicon('close', true)} title={nls.localizeByDefault('Clear')} data-message-id={messageId}
98
+ onClick={this.onClear} />)}
99
+ </ul>
100
+ </div>
101
+ {(source || !!actions.length) && (
102
+ <div className='theia-notification-list-item-content-bottom'>
103
+ <div className='theia-notification-source'>
104
+ {source && (<span>{source}</span>)}
105
+ </div>
106
+ <div className='theia-notification-buttons'>
107
+ {actions && actions.map((action, index) => (
108
+ <button key={messageId + `-action-${index}`} className='theia-button'
109
+ data-message-id={messageId} data-action={action}
110
+ onClick={this.onAction}>
111
+ {action}
112
+ </button>
113
+ ))}
114
+ </div>
115
+ </div>
116
+ )}
117
+ </div>
118
+ {isProgress && (
119
+ <div className='theia-notification-item-progress'>
120
+ <div className={`theia-notification-item-progressbar ${progress ? 'determinate' : 'indeterminate'}`}
121
+ style={{ width: `${progress ?? '100'}%` }} />
122
+ </div>
123
+ )}
124
+ </div>
125
+ </div>);
126
+ }
127
+
128
+ }
@@ -1,73 +1,73 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { expect } from 'chai';
18
- import { NotificationContentRenderer } from './notification-content-renderer';
19
-
20
- describe('notification-content-renderer', () => {
21
-
22
- const contentRenderer = new NotificationContentRenderer();
23
-
24
- it('should remove new lines', () => {
25
- expectRenderedContent('foo\nbar', 'foo bar');
26
- expectRenderedContent('foo\n\n\nbar', 'foo bar');
27
- });
28
-
29
- it('should render links', () => {
30
- expectRenderedContent(
31
- 'Link to [theia](https://github.com/eclipse-theia/theia)!',
32
- 'Link to <a href="https://github.com/eclipse-theia/theia">theia</a>!'
33
- );
34
- expectRenderedContent(
35
- 'Link to [theia](https://github.com/eclipse-theia/theia "title on hover")!',
36
- 'Link to <a href="https://github.com/eclipse-theia/theia" title="title on hover">theia</a>!'
37
- );
38
- expectRenderedContent(
39
- 'Click [here](command:my-command-id) to open stuff!',
40
- 'Click <a href="command:my-command-id">here</a> to open stuff!'
41
- );
42
- expectRenderedContent(
43
- 'Click [here](javascript:window.alert();) to open stuff!',
44
- 'Click [here](javascript:window.alert();) to open stuff!'
45
- );
46
- });
47
-
48
- it('should render markdown', () => {
49
- expectRenderedContent(
50
- '*italic*',
51
- '<em>italic</em>'
52
- );
53
- expectRenderedContent(
54
- '**bold**',
55
- '<strong>bold</strong>'
56
- );
57
- });
58
-
59
- it('should not render html', () => {
60
- expectRenderedContent(
61
- '<script>document.getElementById("demo").innerHTML = "Hello JavaScript!";</script>',
62
- '&lt;script&gt;document.getElementById(&quot;demo&quot;).innerHTML = &quot;Hello JavaScript!&quot;;&lt;/script&gt;'
63
- );
64
- expectRenderedContent(
65
- '<a href="javascript:window.alert();">foobar</a>',
66
- '&lt;a href=&quot;javascript:window.alert();&quot;&gt;foobar&lt;/a&gt;'
67
- );
68
- });
69
-
70
- const expectRenderedContent = (input: string, output: string) =>
71
- expect(contentRenderer.renderMessage(input)).to.be.equal(output);
72
-
73
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { expect } from 'chai';
18
+ import { NotificationContentRenderer } from './notification-content-renderer';
19
+
20
+ describe('notification-content-renderer', () => {
21
+
22
+ const contentRenderer = new NotificationContentRenderer();
23
+
24
+ it('should remove new lines', () => {
25
+ expectRenderedContent('foo\nbar', 'foo bar');
26
+ expectRenderedContent('foo\n\n\nbar', 'foo bar');
27
+ });
28
+
29
+ it('should render links', () => {
30
+ expectRenderedContent(
31
+ 'Link to [theia](https://github.com/eclipse-theia/theia)!',
32
+ 'Link to <a href="https://github.com/eclipse-theia/theia">theia</a>!'
33
+ );
34
+ expectRenderedContent(
35
+ 'Link to [theia](https://github.com/eclipse-theia/theia "title on hover")!',
36
+ 'Link to <a href="https://github.com/eclipse-theia/theia" title="title on hover">theia</a>!'
37
+ );
38
+ expectRenderedContent(
39
+ 'Click [here](command:my-command-id) to open stuff!',
40
+ 'Click <a href="command:my-command-id">here</a> to open stuff!'
41
+ );
42
+ expectRenderedContent(
43
+ 'Click [here](javascript:window.alert();) to open stuff!',
44
+ 'Click [here](javascript:window.alert();) to open stuff!'
45
+ );
46
+ });
47
+
48
+ it('should render markdown', () => {
49
+ expectRenderedContent(
50
+ '*italic*',
51
+ '<em>italic</em>'
52
+ );
53
+ expectRenderedContent(
54
+ '**bold**',
55
+ '<strong>bold</strong>'
56
+ );
57
+ });
58
+
59
+ it('should not render html', () => {
60
+ expectRenderedContent(
61
+ '<script>document.getElementById("demo").innerHTML = "Hello JavaScript!";</script>',
62
+ '&lt;script&gt;document.getElementById(&quot;demo&quot;).innerHTML = &quot;Hello JavaScript!&quot;;&lt;/script&gt;'
63
+ );
64
+ expectRenderedContent(
65
+ '<a href="javascript:window.alert();">foobar</a>',
66
+ '&lt;a href=&quot;javascript:window.alert();&quot;&gt;foobar&lt;/a&gt;'
67
+ );
68
+ });
69
+
70
+ const expectRenderedContent = (input: string, output: string) =>
71
+ expect(contentRenderer.renderMessage(input)).to.be.equal(output);
72
+
73
+ });
@@ -1,31 +1,31 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as markdownit from '@theia/core/shared/markdown-it';
18
- import { injectable } from '@theia/core/shared/inversify';
19
-
20
- @injectable()
21
- export class NotificationContentRenderer {
22
-
23
- protected readonly mdEngine = markdownit({ html: false });
24
-
25
- renderMessage(content: string): string {
26
- // in alignment with vscode, new lines aren't supported
27
- const contentWithoutNewlines = content.replace(/((\r)?\n)+/gm, ' ');
28
-
29
- return this.mdEngine.renderInline(contentWithoutNewlines);
30
- }
31
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as markdownit from '@theia/core/shared/markdown-it';
18
+ import { injectable } from '@theia/core/shared/inversify';
19
+
20
+ @injectable()
21
+ export class NotificationContentRenderer {
22
+
23
+ protected readonly mdEngine = markdownit({ html: false });
24
+
25
+ renderMessage(content: string): string {
26
+ // in alignment with vscode, new lines aren't supported
27
+ const contentWithoutNewlines = content.replace(/((\r)?\n)+/gm, ' ');
28
+
29
+ return this.mdEngine.renderInline(contentWithoutNewlines);
30
+ }
31
+ }
@@ -1,58 +1,58 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { interfaces } from '@theia/core/shared/inversify';
18
- import {
19
- createPreferenceProxy,
20
- PreferenceProxy,
21
- PreferenceService,
22
- PreferenceContribution,
23
- PreferenceSchema
24
- } from '@theia/core/lib/browser/preferences';
25
- import { nls } from '@theia/core/lib/common/nls';
26
-
27
- export const NotificationConfigSchema: PreferenceSchema = {
28
- 'type': 'object',
29
- 'properties': {
30
- 'notification.timeout': {
31
- 'type': 'number',
32
- 'description': nls.localize('theia/messages/notificationTimeout', 'Informative notifications will be hidden after this timeout.'),
33
- 'default': 30 * 1000 // `0` and negative values are treated as no timeout.
34
- }
35
- }
36
- };
37
-
38
- export interface NotificationConfiguration {
39
- 'notification.timeout': number
40
- }
41
-
42
- export const NotificationPreferenceContribution = Symbol('NotificationPreferenceContribution');
43
- export const NotificationPreferences = Symbol('NotificationPreferences');
44
- export type NotificationPreferences = PreferenceProxy<NotificationConfiguration>;
45
-
46
- export function createNotificationPreferences(preferences: PreferenceService, schema: PreferenceSchema = NotificationConfigSchema): NotificationPreferences {
47
- return createPreferenceProxy(preferences, schema);
48
- }
49
-
50
- export function bindNotificationPreferences(bind: interfaces.Bind): void {
51
- bind(NotificationPreferences).toDynamicValue(ctx => {
52
- const preferences = ctx.container.get<PreferenceService>(PreferenceService);
53
- const contribution = ctx.container.get<PreferenceContribution>(NotificationPreferenceContribution);
54
- return createNotificationPreferences(preferences, contribution.schema);
55
- }).inSingletonScope();
56
- bind(NotificationPreferenceContribution).toConstantValue({ schema: NotificationConfigSchema });
57
- bind(PreferenceContribution).toService(NotificationPreferenceContribution);
58
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { interfaces } from '@theia/core/shared/inversify';
18
+ import {
19
+ createPreferenceProxy,
20
+ PreferenceProxy,
21
+ PreferenceService,
22
+ PreferenceContribution,
23
+ PreferenceSchema
24
+ } from '@theia/core/lib/browser/preferences';
25
+ import { nls } from '@theia/core/lib/common/nls';
26
+
27
+ export const NotificationConfigSchema: PreferenceSchema = {
28
+ 'type': 'object',
29
+ 'properties': {
30
+ 'notification.timeout': {
31
+ 'type': 'number',
32
+ 'description': nls.localize('theia/messages/notificationTimeout', 'Informative notifications will be hidden after this timeout.'),
33
+ 'default': 30 * 1000 // `0` and negative values are treated as no timeout.
34
+ }
35
+ }
36
+ };
37
+
38
+ export interface NotificationConfiguration {
39
+ 'notification.timeout': number
40
+ }
41
+
42
+ export const NotificationPreferenceContribution = Symbol('NotificationPreferenceContribution');
43
+ export const NotificationPreferences = Symbol('NotificationPreferences');
44
+ export type NotificationPreferences = PreferenceProxy<NotificationConfiguration>;
45
+
46
+ export function createNotificationPreferences(preferences: PreferenceService, schema: PreferenceSchema = NotificationConfigSchema): NotificationPreferences {
47
+ return createPreferenceProxy(preferences, schema);
48
+ }
49
+
50
+ export function bindNotificationPreferences(bind: interfaces.Bind): void {
51
+ bind(NotificationPreferences).toDynamicValue(ctx => {
52
+ const preferences = ctx.container.get<PreferenceService>(PreferenceService);
53
+ const contribution = ctx.container.get<PreferenceContribution>(NotificationPreferenceContribution);
54
+ return createNotificationPreferences(preferences, contribution.schema);
55
+ }).inSingletonScope();
56
+ bind(NotificationPreferenceContribution).toConstantValue({ schema: NotificationConfigSchema });
57
+ bind(PreferenceContribution).toService(NotificationPreferenceContribution);
58
+ }