-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathabout-dialog.tsx
137 lines (119 loc) · 5.28 KB
/
about-dialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// *****************************************************************************
// Copyright (C) 2018 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import * as React from 'react';
import { inject, injectable, postConstruct } from 'inversify';
import { Dialog, DialogProps } from './dialogs';
import { ReactDialog } from './dialogs/react-dialog';
import { ApplicationServer, ApplicationInfo, ExtensionInfo } from '../common/application-protocol';
import { Message } from './widgets/widget';
import { FrontendApplicationConfigProvider } from './frontend-application-config-provider';
import { DEFAULT_SUPPORTED_API_VERSION } from '@theia/application-package/lib/api';
import { WindowService } from './window/window-service';
import { Key, KeyCode } from './keys';
import { nls } from '../common/nls';
export const ABOUT_CONTENT_CLASS = 'theia-aboutDialog';
export const ABOUT_EXTENSIONS_CLASS = 'theia-aboutExtensions';
@injectable()
export class AboutDialogProps extends DialogProps {
}
@injectable()
export class AboutDialog extends ReactDialog<void> {
protected applicationInfo: ApplicationInfo | undefined;
protected extensionsInfos: ExtensionInfo[] = [];
protected readonly okButton: HTMLButtonElement;
@inject(ApplicationServer)
protected readonly appServer: ApplicationServer;
@inject(WindowService)
protected readonly windowService: WindowService;
constructor(
@inject(AboutDialogProps) protected override readonly props: AboutDialogProps
) {
super({
title: FrontendApplicationConfigProvider.get().applicationName,
});
this.appendAcceptButton(Dialog.OK);
}
@postConstruct()
protected init(): void {
this.doInit();
}
protected async doInit(): Promise<void> {
this.applicationInfo = await this.appServer.getApplicationInfo();
this.extensionsInfos = await this.appServer.getExtensionsInfos();
this.update();
}
protected renderHeader(): React.ReactNode {
const applicationInfo = this.applicationInfo;
const compatibilityUrl = 'https://eclipse-theia.github.io/vscode-theia-comparator/status.html';
const detailsLabel = nls.localizeByDefault('Details');
const versionLabel = nls.localize('theia/core/about/version', 'Version');
const defaultApiLabel = nls.localize('theia/core/about/defaultApi', 'Default {0} API', 'VS Code');
const compatibilityLabel = nls.localize('theia/core/about/compatibility', '{0} Compatibility', 'VS Code');
return <>
<h3>{detailsLabel}</h3>
<div className='about-details'>
{applicationInfo && <p>{`${versionLabel}: ${applicationInfo.version}`}</p>}
<p>{`${defaultApiLabel}: ${DEFAULT_SUPPORTED_API_VERSION}`}</p>
<p>
<a
role={'button'}
tabIndex={0}
onClick={() => this.doOpenExternalLink(compatibilityUrl)}
onKeyDown={(e: React.KeyboardEvent) => this.doOpenExternalLinkEnter(e, compatibilityUrl)}>
{compatibilityLabel}
</a>
</p>
</div>
</>;
}
protected renderExtensions(): React.ReactNode {
const extensionsInfos = this.extensionsInfos;
return <>
<h3>List of extensions</h3>
<ul className={ABOUT_EXTENSIONS_CLASS}>
{
extensionsInfos
.sort((a: ExtensionInfo, b: ExtensionInfo) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()))
.map((extension: ExtensionInfo) => <li key={extension.name}>{extension.name} {extension.version}</li>)
}
</ul>
</>;
}
protected render(): React.ReactNode {
return <div className={ABOUT_CONTENT_CLASS}>
{this.renderHeader()}
{this.renderExtensions()}
</div>;
}
protected override onAfterAttach(msg: Message): void {
super.onAfterAttach(msg);
this.update();
}
/**
* Open a link in an external window.
* @param url the link.
*/
protected doOpenExternalLink = (url: string) => this.windowService.openNewWindow(url, { external: true });
protected doOpenExternalLinkEnter = (e: React.KeyboardEvent, url: string) => {
if (this.isEnterKey(e)) {
this.doOpenExternalLink(url);
}
};
protected isEnterKey(e: React.KeyboardEvent): boolean {
return Key.ENTER.keyCode === KeyCode.createKeyCode(e.nativeEvent).key?.keyCode;
}
get value(): undefined { return undefined; }
}