Skip to content

Commit

Permalink
Use executeCommand(vscode.open) instead of opn (#903)
Browse files Browse the repository at this point in the history
* use vscode.open instead of opn everywhere.
For thenables, disable no-floating-promises
  • Loading branch information
PrashanthCorp committed Apr 24, 2019
1 parent 7287cd4 commit baf595f
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ testOutput
test-results.xml
dist
stats.json

# Artifacts from running npm install
**/npm-debug.log
19 changes: 11 additions & 8 deletions commands/utils/quick-pick-azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import * as ContainerModels from 'azure-arm-containerregistry/lib/models';
import { Registry } from 'azure-arm-containerregistry/lib/models';
import { ResourceGroup } from 'azure-arm-resource/lib/resource/models';
import { Location, Subscription } from 'azure-arm-resource/lib/subscription/models';
import * as opn from 'opn';
import * as vscode from "vscode";
import { IAzureQuickPickItem, UserCancelledError } from 'vscode-azureextensionui';
import { skus } from '../../constants'
import { skus } from '../../constants';
import { openExternal } from '../../explorer/utils/openExternal';
import { ext } from '../../extensionVariables';
import { ResourceManagementClient } from '../../node_modules/azure-arm-resource';
import * as acrTools from '../../utils/Azure/acrTools';
Expand Down Expand Up @@ -79,12 +79,15 @@ export async function quickPickSubscription(): Promise<Subscription> {
const subscriptions = await AzureUtilityManager.getInstance().getFilteredSubscriptionList();
if (subscriptions.length === 0) {
let openPortal = 'Open Portal';
vscode.window.showErrorMessage("You are not signed in to Azure, or you do not have any subscriptions. To sign in, select 'Azure: Sign In' from the command palette. Subscriptions can be created in the Azure portal", openPortal).then(val => {
if (val === openPortal) {
// tslint:disable-next-line:no-unsafe-any
opn('https://portal.azure.com/');
}
});
vscode.window.showErrorMessage("You are not signed in to Azure, or you do not have any subscriptions. To sign in, select 'Azure: Sign In' from the command palette. Subscriptions can be created in the Azure portal", openPortal)
.then(response => {
if (response === openPortal) {
//don't wait for openExternal to finish. Intentional
// tslint:disable-next-line: no-floating-promises
openExternal('https://portal.azure.com/');
}
});

}
if (subscriptions.length === 1) { return subscriptions[0]; }

Expand Down
6 changes: 3 additions & 3 deletions debugging/coreclr/browserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as opn from 'opn';
import { Uri } from "vscode";
import { openExternal } from '../../explorer/utils/openExternal';

export interface BrowserClient {
openBrowser(url: string): void;
Expand All @@ -14,8 +14,8 @@ export class OpnBrowserClient implements BrowserClient {
const uri = Uri.parse(url);

if (uri.scheme === 'http' || uri.scheme === 'https') {
// tslint:disable-next-line:no-unsafe-any
opn(url);
// tslint:disable-next-line:no-floating-promises
openExternal(url);
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions explorer/models/taskNode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import ContainerRegistryManagementClient from 'azure-arm-containerregistry';
import * as ContainerModels from 'azure-arm-containerregistry/lib/models';
import { SubscriptionModels } from 'azure-arm-resource';
import * as opn from 'opn';
import * as path from 'path';
import * as vscode from 'vscode';
import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azureextensionui';
import { imagesPath } from '../../constants';
import { AzureAccount } from '../../typings/azure-account.api';
import * as acrTools from '../../utils/Azure/acrTools';
import { AzureUtilityManager } from '../../utils/azureUtilityManager';
import { openExternal } from '../utils/openExternal';
import { NodeBase } from './nodeBase';

/* Single TaskRootNode under each Repository. Labeled "Tasks" */
Expand Down Expand Up @@ -55,12 +55,15 @@ export class TaskRootNode extends NodeBase {
tasks = await client.tasks.list(resourceGroup, element.registry.name);
if (tasks.length === 0) {
const learnHow: vscode.MessageItem = { title: "Learn How to Create Build Tasks" };
vscode.window.showInformationMessage(`You do not have any Tasks in the registry '${element.registry.name}'.`, learnHow).then(val => {
if (val === learnHow) {
// tslint:disable-next-line:no-unsafe-any
opn('https://aka.ms/acr/task');
}
})
vscode.window.showInformationMessage(`You do not have any Tasks in the registry '${element.registry.name}'.`, learnHow)
.then(response => {
if (response === learnHow) {
//don't wait for openExternal to finish. Intentional
// tslint:disable-next-line: no-floating-promises
openExternal('https://aka.ms/acr/task');
}
});

}

for (let task of tasks) {
Expand Down
6 changes: 3 additions & 3 deletions explorer/utils/browseAzurePortal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as opn from 'opn';
import { AzureSession } from '../../typings/azure-account.api';
import { getTenantId, nonNullValue } from '../../utils/nonNull';
import { AzureImageTagNode, AzureRegistryNode, AzureRepositoryNode } from '../models/azureRegistryNodes';
import { openExternal } from './openExternal';

export function browseAzurePortal(node?: AzureRegistryNode | AzureRepositoryNode | AzureImageTagNode): void {
if (node && node.azureAccount) {
Expand All @@ -18,7 +18,7 @@ export function browseAzurePortal(node?: AzureRegistryNode | AzureRepositoryNode
if (node.contextValue === AzureImageTagNode.contextValue || node.contextValue === AzureRepositoryNode.contextValue) {
url = `${url}/repository`;
}
// tslint:disable-next-line:no-unsafe-any
opn(url);
// tslint:disable-next-line:no-floating-promises
openExternal(url);
}
}
8 changes: 4 additions & 4 deletions explorer/utils/dockerConnectionError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as opn from 'opn';
import { MessageItem } from "vscode";
import * as vscode from 'vscode';
import { MessageItem } from "vscode";
import { IActionContext, parseError } from "vscode-azureextensionui";
import { isLinux } from "../../helpers/osVersion";
import { wrapError } from "../../utils/wrapError";
import { openExternal } from './openExternal';

const connectionMessage = 'Unable to connect to Docker. Please make sure you have installed Docker and that it is running.';

Expand Down Expand Up @@ -37,8 +37,8 @@ export function showDockerConnectionError(actionContext: IActionContext, error:
actionContext.suppressErrorDisplay = true;
vscode.window.showErrorMessage(parseError(wrappedError).message, ...items).then(response => {
if (response) {
// tslint:disable-next-line:no-unsafe-any
opn(response.url);
// tslint:disable-next-line:no-floating-promises
openExternal(response.url);
}
});

Expand Down
7 changes: 3 additions & 4 deletions explorer/utils/dockerHubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as opn from 'opn';
import * as vscode from 'vscode';
import { keytarConstants, PAGE_SIZE } from '../../constants';
import { ext } from '../../extensionVariables';
import { DockerHubImageTagNode, DockerHubOrgNode, DockerHubRepositoryNode } from '../models/dockerHubNodes';
import { NodeBase } from '../models/nodeBase';
import { openExternal } from './openExternal';

let _token: Token;

Expand Down Expand Up @@ -261,7 +261,7 @@ export async function getRepositoryTags(repository: Repository): Promise<Tag[]>
return tagsPage.results;
}

export function browseDockerHub(node?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode): void {
export async function browseDockerHub(node?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode): Promise<void> {
if (node) {
let url: string = 'https://hub.docker.com/';
if (node instanceof DockerHubOrgNode) {
Expand All @@ -274,7 +274,6 @@ export function browseDockerHub(node?: DockerHubImageTagNode | DockerHubReposito
assert(false, `browseDockerHub: Unexpected node type, contextValue=${(<NodeBase>node).contextValue}`)
}

// tslint:disable-next-line:no-unsafe-any
opn(url);
await openExternal(url);
}
}
15 changes: 15 additions & 0 deletions explorer/utils/openExternal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { commands, Uri } from 'vscode';

export async function openExternal(path: string, throwErrorOnFailure: boolean = false): Promise<void> {
let uri = Uri.parse(path);
let successful: boolean = await commands.executeCommand('vscode.open', uri);
if (!successful && throwErrorOnFailure) {
throw new Error(`Opening ${path} was unsuccessful`);
}
return;
}
2 changes: 1 addition & 1 deletion extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function registerDockerCommands(): void {
registerCommand('vscode-docker.acr.viewLogs', viewACRLogs);

registerCommand('vscode-docker.api.configure', async function (this: IActionContext, options: ConfigureApiOptions): Promise<void> { await configureApi(this, options); });
registerCommand('vscode-docker.browseDockerHub', (context?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode) => { browseDockerHub(context); });
registerCommand('vscode-docker.browseDockerHub', async (context?: DockerHubImageTagNode | DockerHubRepositoryNode | DockerHubOrgNode) => { await browseDockerHub(context); });
registerCommand('vscode-docker.browseAzurePortal', (context?: AzureRegistryNode | AzureRepositoryNode | AzureImageTagNode) => { browseAzurePortal(context); });

registerCommand('vscode-docker.compose.down', composeDown);
Expand Down
5 changes: 2 additions & 3 deletions utils/azureUtilityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { ResourceManagementClient, SubscriptionClient, SubscriptionModels } from
import { ResourceGroup } from "azure-arm-resource/lib/resource/models";
import { Subscription } from 'azure-arm-resource/lib/subscription/models';
import { ServiceClientCredentials } from 'ms-rest';
import * as opn from 'opn';
import * as vscode from 'vscode';
import { addExtensionUserAgent, callWithTelemetryAndErrorHandling, IActionContext, parseError, UserCancelledError } from 'vscode-azureextensionui';
import { MAX_CONCURRENT_SUBSCRIPTON_REQUESTS } from '../constants';
import { openExternal } from '../explorer/utils/openExternal';
import { AzureAccount, AzureSession } from '../typings/azure-account.api';
import { AsyncPool } from './asyncpool';
import { getSubscriptionId, getTenantId } from './nonNull';
Expand Down Expand Up @@ -75,8 +75,7 @@ export class AzureUtilityManager {
const msg = 'This functionality requires installing the Azure Account extension.';
let response = await vscode.window.showErrorMessage(msg, open);
if (response === open) {
// tslint:disable-next-line:no-unsafe-any
opn('https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account');
await openExternal('https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account');
}

throw new UserCancelledError(msg);
Expand Down

0 comments on commit baf595f

Please sign in to comment.