Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show progress during context switch #1969

Merged
merged 5 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/commands/context/useDockerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IActionContext } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { localize } from '../../localize';
import { ContextTreeItem } from '../../tree/contexts/ContextTreeItem';
import { LocalRootTreeItemBase } from '../../tree/LocalRootTreeItemBase';

export async function useDockerContext(actionContext: IActionContext, node?: ContextTreeItem): Promise<void> {
let invokedFromCommandPalette = false;
Expand All @@ -19,7 +20,20 @@ export async function useDockerContext(actionContext: IActionContext, node?: Con
invokedFromCommandPalette = true;
}

await node.use(actionContext);
try {
LocalRootTreeItemBase.autoRefreshViews = false;
await node.runWithTemporaryDescription(
localize('vscode-docker.tree.context.switching', 'Switching...'),
async () => {
await node.use(actionContext);
// The refresh logic will use the cached contexts retrieved by polling (auto refresh logic)
// Since the context is changed, clear the cached contexts, otherwise the old context will be shown as active
ext.contextsRoot.clearPollingCache();
});
} finally {
LocalRootTreeItemBase.autoRefreshViews = true;
}

await ext.contextsRoot.refresh();

if (invokedFromCommandPalette) {
Expand Down
22 changes: 18 additions & 4 deletions src/tree/LocalRootTreeItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
public abstract getItems(): Promise<TItem[] | undefined>;
public abstract getPropertyValue(item: TItem, property: TProperty): string;

public static autoRefreshViews: boolean = true;

public groupBySetting: TProperty | CommonGroupBy;
public sortBySetting: CommonSortBy;
public labelSetting: TProperty;
Expand All @@ -72,6 +74,10 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
return workspace.getConfiguration(`${configPrefix}.${this.treePrefix}`);
}

private get autoRefreshEnabled(): boolean {
return window.state.focused && LocalRootTreeItemBase.autoRefreshViews;
}

protected getRefreshInterval(): number {
const configOptions: WorkspaceConfiguration = workspace.getConfiguration('docker');
return configOptions.get<number>('explorerRefreshInterval', 2000)
Expand All @@ -89,8 +95,12 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
const refreshInterval: number = this.getRefreshInterval();
intervalId = setInterval(
async () => {
if (window.state.focused && await this.hasChanged()) {
await this.refresh();
if (this.autoRefreshEnabled && await this.hasChanged()) {
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
// Auto refresh could be disabled while invoking the hasChanged()
// So check again before starting the refresh.
if (this.autoRefreshEnabled) {
await this.refresh();
}
}
},
refreshInterval);
Expand Down Expand Up @@ -118,13 +128,17 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
})];
}

public clearPollingCache(): void {
this._itemsFromPolling = undefined;
}

public async loadMoreChildrenImpl(_clearCache: boolean, context: IActionContext): Promise<AzExtTreeItem[]> {
try {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
ext.activityMeasurementService.recordActivity('overallnoedit');

this._currentItems = this._itemsFromPolling || await this.getSortedItems();
this._itemsFromPolling = undefined;
this.clearPollingCache();
this.failedToConnect = false;
this._currentDockerStatus = 'Running';
} catch (error) {
Expand Down Expand Up @@ -345,7 +359,7 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
this._itemsFromPolling = await this.getSortedItems();
pollingDockerStatus = 'Running';
} catch (error) {
this._itemsFromPolling = undefined;
this.clearPollingCache();
pollingDockerStatus = await dockerInstallStatusProvider.isDockerInstalled() ? 'Installed' : 'NotInstalled';
isDockerStatusChanged = pollingDockerStatus !== this._currentDockerStatus;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree/contexts/ContextTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ContextTreeItem extends AzExtTreeItem {
}

public async deleteTreeItemImpl(context: IActionContext): Promise<void> {
await dockerContextManager.remove(this.name);
return dockerContextManager.remove(this.name);
}

public async inspect(context: IActionContext): Promise<string> {
Expand Down