Browse Source

Shows progress notification earlier in deep link process

main
Ramin Tadayon 1 year ago
parent
commit
8990301062
No known key found for this signature in database GPG Key ID: 79D60DDE3DFB95F5
2 changed files with 59 additions and 30 deletions
  1. +19
    -0
      src/uris/deepLinks/deepLink.ts
  2. +40
    -30
      src/uris/deepLinks/deepLinkService.ts

+ 19
- 0
src/uris/deepLinks/deepLink.ts View File

@ -182,3 +182,22 @@ export const deepLinkStateTransitionTable: { [state: string]: { [action: string]
[DeepLinkServiceAction.DeepLinkErrored]: DeepLinkServiceState.Idle,
},
};
export interface DeepLinkProgress {
message: string;
increment: number;
}
export const deepLinkStateToProgress: { [state: string]: DeepLinkProgress } = {
[DeepLinkServiceState.Idle]: { message: 'Done.', increment: 100 },
[DeepLinkServiceState.RepoMatch]: { message: 'Finding a matching repository...', increment: 10 },
[DeepLinkServiceState.CloneOrAddRepo]: { message: 'Adding repository...', increment: 20 },
[DeepLinkServiceState.OpeningRepo]: { message: 'Opening repository...', increment: 30 },
[DeepLinkServiceState.AddedRepoMatch]: { message: 'Finding a matching repository...', increment: 40 },
[DeepLinkServiceState.RemoteMatch]: { message: 'Finding a matching remote...', increment: 50 },
[DeepLinkServiceState.AddRemote]: { message: 'Adding remote...', increment: 60 },
[DeepLinkServiceState.TargetMatch]: { message: 'finding a matching target...', increment: 70 },
[DeepLinkServiceState.Fetch]: { message: 'Fetching...', increment: 80 },
[DeepLinkServiceState.FetchedTargetMatch]: { message: 'Finding a matching target...', increment: 90 },
[DeepLinkServiceState.OpenGraph]: { message: 'Opening graph...', increment: 95 },
};

+ 40
- 30
src/uris/deepLinks/deepLinkService.ts View File

@ -1,4 +1,4 @@
import { Disposable, env, ProgressLocation, Uri, window, workspace } from 'vscode';
import { Disposable, env, EventEmitter, ProgressLocation, Uri, window, workspace } from 'vscode';
import type { StoredDeepLinkContext } from '../../constants';
import { Commands } from '../../constants';
import type { Container } from '../../container';
@ -13,11 +13,12 @@ import { configuration } from '../../system/configuration';
import { once } from '../../system/event';
import { Logger } from '../../system/logger';
import { openWorkspace, OpenWorkspaceLocation } from '../../system/utils';
import type { DeepLink, DeepLinkServiceContext } from './deepLink';
import type { DeepLink, DeepLinkProgress, DeepLinkServiceContext } from './deepLink';
import {
DeepLinkRepoOpenType,
DeepLinkServiceAction,
DeepLinkServiceState,
deepLinkStateToProgress,
deepLinkStateTransitionTable,
DeepLinkType,
parseDeepLinkUri,
@ -27,12 +28,15 @@ import {
export class DeepLinkService implements Disposable {
private readonly _disposables: Disposable[] = [];
private _context: DeepLinkServiceContext;
private readonly _onDeepLinkProgressUpdated: EventEmitter<DeepLinkProgress>;
constructor(private readonly container: Container) {
this._context = {
state: DeepLinkServiceState.Idle,
};
this._onDeepLinkProgressUpdated = new EventEmitter<DeepLinkProgress>();
this._disposables.push(
container.uri.onDidReceiveUri(async (uri: Uri) => {
const link = parseDeepLinkUri(uri);
@ -219,9 +223,39 @@ export class DeepLinkService implements Disposable {
let repoOpenLocation;
let repoOpenUri: Uri | undefined = undefined;
queueMicrotask(
() =>
void window.withProgress(
{
cancellable: true,
location: ProgressLocation.Notification,
title: `Opening repository for link: ${this._context.url}}`,
},
(progress, token) => {
progress.report({ increment: 0 });
return new Promise<void>(resolve => {
token.onCancellationRequested(() => {
queueMicrotask(() => this.processDeepLink(DeepLinkServiceAction.DeepLinkCancelled));
resolve();
});
this._disposables.push(
this._onDeepLinkProgressUpdated.event(({ message, increment }) => {
progress.report({ message: message, increment: increment });
if (increment === 100) {
resolve();
}
}),
);
});
},
),
);
while (true) {
this._context.state = deepLinkStateTransitionTable[this._context.state][action];
const { state, repoId, repo, url, remoteUrl, remote, targetSha, targetType } = this._context;
this._onDeepLinkProgressUpdated.fire(deepLinkStateToProgress[state]);
switch (state) {
case DeepLinkServiceState.Idle:
if (action === DeepLinkServiceAction.DeepLinkErrored) {
@ -328,34 +362,10 @@ export class DeepLinkService implements Disposable {
break;
case DeepLinkServiceState.OpeningRepo:
queueMicrotask(
() =>
void window.withProgress(
{
cancellable: true,
location: ProgressLocation.Notification,
title: `Opening repository for link: ${url}`,
},
(progress, token) => {
return new Promise<void>(resolve => {
token.onCancellationRequested(() => {
queueMicrotask(() =>
this.processDeepLink(DeepLinkServiceAction.DeepLinkCancelled),
);
resolve();
});
this._disposables.push(
once(this.container.git.onDidChangeRepositories)(() => {
queueMicrotask(() =>
this.processDeepLink(DeepLinkServiceAction.RepoAdded),
);
resolve();
}),
);
});
},
),
this._disposables.push(
once(this.container.git.onDidChangeRepositories)(() => {
queueMicrotask(() => this.processDeepLink(DeepLinkServiceAction.RepoAdded));
}),
);
return;

Loading…
Cancel
Save