Skip to content

Commit

Permalink
Change fireSoon to take callback function (#4071)
Browse files Browse the repository at this point in the history
* change firesoon to take callback function

* use RDP label when determining type of registry
  • Loading branch information
alexyaang authored Sep 14, 2023
1 parent 51e8fa9 commit 4e6aa8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { AzExtTreeDataProvider, AzExtTreeItem, IExperimentationServiceAdapter } from '@microsoft/vscode-azext-utils';
import { DockerHubRegistryDataProvider, GenericRegistryV2DataProvider } from '@microsoft/vscode-docker-registries';
import { DockerHubRegistryDataProvider, GenericRegistryV2DataProvider, GitHubRegistryDataProvider } from '@microsoft/vscode-docker-registries';
import { ExtensionContext, StatusBarItem, TreeView } from 'vscode';
import { ContainerRuntimeManager } from './runtimes/ContainerRuntimeManager';
import { OrchestratorRuntimeManager } from './runtimes/OrchestratorRuntimeManager';
Expand Down Expand Up @@ -53,6 +53,7 @@ export namespace ext {
export let genericRegistryV2DataProvider: GenericRegistryV2DataProvider;
export let azureRegistryDataProvider: AzureRegistryDataProvider;
export let dockerHubRegistryDataProvider: DockerHubRegistryDataProvider;
export let githubRegistryDataProvider: GitHubRegistryDataProvider;

export let volumesTree: AzExtTreeDataProvider;
export let volumesTreeView: TreeView<AzExtTreeItem>;
Expand Down
4 changes: 3 additions & 1 deletion src/tree/registerTrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function registerTrees(): void {
const genericRegistryV2DataProvider = new GenericRegistryV2DataProvider(ext.context);
const azureRegistryDataProvider = new AzureRegistryDataProvider(ext.context);
const dockerHubRegistryDataProvider = new DockerHubRegistryDataProvider(ext.context);
urtdp.registerProvider(new GitHubRegistryDataProvider(ext.context));
const githubRegistryDataProvider = new GitHubRegistryDataProvider(ext.context);
urtdp.registerProvider(githubRegistryDataProvider);
urtdp.registerProvider(dockerHubRegistryDataProvider);
urtdp.registerProvider(azureRegistryDataProvider);
urtdp.registerProvider(genericRegistryV2DataProvider);
Expand All @@ -58,6 +59,7 @@ export function registerTrees(): void {
ext.genericRegistryV2DataProvider = genericRegistryV2DataProvider;
ext.azureRegistryDataProvider = azureRegistryDataProvider;
ext.dockerHubRegistryDataProvider = dockerHubRegistryDataProvider;
ext.githubRegistryDataProvider = githubRegistryDataProvider;

ext.volumesRoot = new VolumesTreeItem(undefined);
const volumesLoadMore = 'vscode-docker.volumes.loadMore';
Expand Down
9 changes: 4 additions & 5 deletions src/tree/registries/Azure/AzureRegistryDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class AzureRegistryDataProvider extends RegistryV2DataProvider implements
if (isRegistryRoot(element)) {
if (!await this.subscriptionProvider.isSignedIn()) {
await this.subscriptionProvider.signIn();
this.fireSoon(element);
this.fireSoon(() => this.onDidChangeTreeDataEmitter.fire(element));
return [];
}

Expand Down Expand Up @@ -216,11 +216,10 @@ export class AzureRegistryDataProvider extends RegistryV2DataProvider implements
return this.authenticationProviders.get(registryString)!;
}

private fireSoon(element?: CommonRegistryItem | undefined) {
private fireSoon(callback: () => void, delay: number = 5) {
const timeout = setTimeout(() => {
clearTimeout(timeout);
this.onDidChangeTreeDataEmitter.fire(element);
}, 5);
callback();
}, delay);
}

}
7 changes: 4 additions & 3 deletions src/tree/registries/UnifiedRegistryTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommonRegistry, CommonRegistryRoot, RegistryDataProvider, isRegistry } from '@microsoft/vscode-docker-registries';
import * as vscode from 'vscode';
import { ext } from '../../extensionVariables';
import { isAzureSubscriptionRegistryItem } from './Azure/AzureRegistryDataProvider';

export interface UnifiedRegistryItem<T> {
Expand Down Expand Up @@ -149,14 +150,14 @@ export class UnifiedRegistryTreeDataProvider implements vscode.TreeDataProvider<
// filter out registry roots that don't match the image base name
if (imageBaseName) {
if (imageBaseName === 'docker.io') {
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === 'Docker Hub');
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === ext.dockerHubRegistryDataProvider.label);
}
else if (imageBaseName.endsWith('azurecr.io')) {
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === 'Azure');
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === ext.azureRegistryDataProvider.label);
findAzureRegistryOnly = true;
}
else if (imageBaseName === 'ghcr.io') {
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === 'GitHub');
registryRoots = registryRoots.filter(r => (r.wrappedItem as CommonRegistryRoot).label === ext.githubRegistryDataProvider.label);
}
else {
registryRoots = registryRoots.filter(
Expand Down

0 comments on commit 4e6aa8a

Please sign in to comment.