Skip to content

Commit 7a677ee

Browse files
Moves pending deep link to secret storage
1 parent f047617 commit 7a677ee

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/constants.storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type { DeepLinkServiceState } from './uris/deepLinks/deepLink';
1414
export type SecretKeys =
1515
| IntegrationAuthenticationKeys
1616
| `gitlens.${AIProviders}.key`
17-
| `gitlens.plus.auth:${Environment}`;
17+
| `gitlens.plus.auth:${Environment}`
18+
| 'deepLinks:pending';
1819

1920
export type IntegrationAuthenticationKeys =
2021
| `gitlens.integration.auth:${IntegrationId}|${string}`
@@ -64,7 +65,6 @@ export type GlobalStorage = {
6465
avatars: [string, StoredAvatar][];
6566
'confirm:ai:tos': boolean;
6667
repoVisibility: [string, StoredRepoVisibilityInfo][];
67-
'deepLinks:pending': StoredDeepLinkContext;
6868
pendingWhatsNewOnFocus: boolean;
6969
// Don't change this key name ('premium`) as its the stored subscription
7070
'premium:subscription': Stored<Subscription & { lastValidatedAt: number | undefined }>;

src/uris/deepLinks/deepLinkService.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { QuickPickItem } from 'vscode';
1+
import type { QuickPickItem, SecretStorageChangeEvent } from 'vscode';
22
import { Disposable, env, EventEmitter, ProgressLocation, Range, Uri, window, workspace } from 'vscode';
33
import type { OpenCloudPatchCommandArgs } from '../../commands/patches';
44
import type { StoredDeepLinkContext, StoredNamedRef } from '../../constants.storage';
@@ -74,8 +74,12 @@ export class DeepLinkService implements Disposable {
7474
container.uri.onDidReceiveUri(async (uri: Uri) => this.processDeepLinkUri(uri)),
7575
);
7676

77-
const pendingDeepLink = this.container.storage.get('deepLinks:pending');
78-
void this.processPendingDeepLink(pendingDeepLink);
77+
void this.container.storage.getSecret('deepLinks:pending').then(pendingDeepLink => {
78+
if (pendingDeepLink != null) {
79+
const link = JSON.parse(pendingDeepLink) as StoredDeepLinkContext;
80+
void this.processPendingDeepLink(link);
81+
}
82+
});
7983
}
8084

8185
dispose(): void {
@@ -254,7 +258,7 @@ export class DeepLinkService implements Disposable {
254258
@debug()
255259
private async processPendingDeepLink(pendingDeepLink: StoredDeepLinkContext | undefined) {
256260
if (pendingDeepLink == null) return;
257-
void this.container.storage.delete('deepLinks:pending');
261+
void this.container.storage.deleteSecret('deepLinks:pending');
258262
if (pendingDeepLink?.url == null) return;
259263
const link = parseDeepLinkUri(Uri.parse(pendingDeepLink.url));
260264
if (link == null) return;
@@ -1061,13 +1065,16 @@ export class DeepLinkService implements Disposable {
10611065
action = DeepLinkServiceAction.RepoOpening;
10621066
if (!(repoOpenLocation === 'addToWorkspace' && (workspace.workspaceFolders?.length || 0) > 1)) {
10631067
// Deep link will resolve in a different service instance
1064-
await this.container.storage.store('deepLinks:pending', {
1065-
url: this._context.url,
1066-
repoPath: repoOpenUri.toString(),
1067-
targetSha: this._context.targetSha,
1068-
secondaryTargetSha: this._context.secondaryTargetSha,
1069-
useProgress: useProgress,
1070-
});
1068+
await this.container.storage.storeSecret(
1069+
'deepLinks:pending',
1070+
JSON.stringify({
1071+
url: this._context.url,
1072+
repoPath: repoOpenUri.toString(),
1073+
targetSha: this._context.targetSha,
1074+
secondaryTargetSha: this._context.secondaryTargetSha,
1075+
useProgress: useProgress,
1076+
}),
1077+
);
10711078
action = DeepLinkServiceAction.DeepLinkStored;
10721079
}
10731080

@@ -1349,9 +1356,11 @@ export class DeepLinkService implements Disposable {
13491356

13501357
// Storing link info in case the switch causes a new window to open
13511358
const onWorkspaceChanging = async (isNewWorktree?: boolean) =>
1352-
this.container.storage.store(
1359+
this.container.storage.storeSecret(
13531360
'deepLinks:pending',
1354-
isNewWorktree ? pendingDeepLink : { ...pendingDeepLink, url: nonPrUrl },
1361+
isNewWorktree
1362+
? JSON.stringify(pendingDeepLink)
1363+
: JSON.stringify({ ...pendingDeepLink, url: nonPrUrl }),
13551364
);
13561365

13571366
await executeGitCommand({
@@ -1406,7 +1415,7 @@ export class DeepLinkService implements Disposable {
14061415
}
14071416
case DeepLinkServiceState.OpenInspect: {
14081417
// If we arrive at this step, clear any stored data used for the "new window" option
1409-
await this.container.storage.delete('deepLinks:pending');
1418+
await this.container.storage.deleteSecret('deepLinks:pending');
14101419
if (!repo) {
14111420
action = DeepLinkServiceAction.DeepLinkErrored;
14121421
message = 'Missing repository.';

src/webviews/home/homeWebview.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,12 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
12361236
subcommand: 'open',
12371237
repo: defaultWorktree.repoPath,
12381238
worktree: defaultWorktree,
1239-
onWorkspaceChanging: async (_isNewWorktree?: boolean) =>
1240-
this.container.storage.store('deepLinks:pending', deleteBranchDeepLink),
1239+
onWorkspaceChanging: async (_isNewWorktree?: boolean) => {
1240+
await this.container.storage.storeSecret(
1241+
'deepLinks:pending',
1242+
JSON.stringify(deleteBranchDeepLink),
1243+
);
1244+
},
12411245
worktreeDefaultOpen: 'current',
12421246
},
12431247
});

0 commit comments

Comments
 (0)