Skip to content

Commit

Permalink
getting-started: fix opening of external links
Browse files Browse the repository at this point in the history
The following commit refactors the `getting-started` widget to make use of the
`WindowService` when opening links in external windows since it is properly implemented by both
the browser and electron targets.

Signed-off-by: vince-fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Apr 23, 2021
1 parent c5d440a commit 88caf97
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions packages/getting-started/src/browser/getting-started-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CommonCommands, LabelProvider, Key, KeyCode } from '@theia/core/lib/bro
import { ApplicationInfo, ApplicationServer } from '@theia/core/lib/common/application-protocol';
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { WindowService } from '@theia/core/lib/browser/window/window-service';

/**
* Default implementation of the `GettingStartedWidget`.
Expand Down Expand Up @@ -89,6 +90,9 @@ export class GettingStartedWidget extends ReactWidget {
@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

@inject(WindowService)
protected readonly windowService: WindowService;

@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

Expand Down Expand Up @@ -286,13 +290,31 @@ export class GettingStartedWidget extends ReactWidget {
Help
</h3>
<div className='gs-action-container'>
<a href={this.documentationUrl} target='_blank'>Documentation</a>
<a
role={'button'}
tabIndex={0}
onClick={() => this.doOpenExternalLink(this.documentationUrl)}
onKeyDown={(e: React.KeyboardEvent) => this.doOpenExternalLinkEnter(e, this.documentationUrl)}>
Documentation
</a>
</div>
<div className='gs-action-container'>
<a href={this.extensionUrl} target='_blank'>Building a New Extension</a>
<a
role={'button'}
tabIndex={0}
onClick={() => this.doOpenExternalLink(this.extensionUrl)}
onKeyDown={(e: React.KeyboardEvent) => this.doOpenExternalLinkEnter(e, this.extensionUrl)}>
Building a New Extension
</a>
</div>
<div className='gs-action-container'>
<a href={this.pluginUrl} target='_blank'>Building a New Plugin</a>
<a
role={'button'}
tabIndex={0}
onClick={() => this.doOpenExternalLink(this.pluginUrl)}
onKeyDown={(e: React.KeyboardEvent) => this.doOpenExternalLinkEnter(e, this.pluginUrl)}>
Building a New Plugin
</a>
</div>
</div>;
}
Expand Down Expand Up @@ -409,6 +431,17 @@ export class GettingStartedWidget extends ReactWidget {
}
};

/**
* 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;
}
Expand Down

0 comments on commit 88caf97

Please sign in to comment.