Browse Source

Adds secret storage access

Renames storage keys for clarity
main
Eric Amodio 2 years ago
parent
commit
0f0a1d62e8
15 changed files with 114 additions and 81 deletions
  1. +4
    -4
      src/avatars.ts
  2. +2
    -2
      src/commands/closeView.ts
  3. +4
    -4
      src/commands/gitCommands.utils.ts
  4. +2
    -2
      src/commands/showView.ts
  5. +3
    -3
      src/env/node/git/localGitProvider.ts
  6. +23
    -19
      src/extension.ts
  7. +3
    -3
      src/git/gitProviderService.ts
  8. +2
    -2
      src/git/models/branch.ts
  9. +3
    -3
      src/git/models/remote.ts
  10. +5
    -5
      src/git/models/repository.ts
  11. +3
    -3
      src/git/remotes/provider.ts
  12. +29
    -13
      src/storage.ts
  13. +6
    -4
      src/views/nodes/compareBranchNode.ts
  14. +4
    -4
      src/views/repositoriesView.ts
  15. +21
    -10
      src/views/searchAndCompareView.ts

+ 4
- 4
src/avatars.ts View File

@ -2,7 +2,7 @@ import { EventEmitter, Uri } from 'vscode';
import { GravatarDefaultStyle } from './config';
import { Container } from './container';
import { GitRevisionReference } from './git/models';
import { GlobalState } from './storage';
import { StorageKeys } from './storage';
import { debounce } from './system/function';
import { filterMap } from './system/iterable';
import { base64, equalsIgnoreCase, md5 } from './system/string';
@ -27,7 +27,7 @@ _onDidFetchAvatar.event(
),
]
: undefined;
void Container.instance.storage.store(GlobalState.Avatars, avatars);
void Container.instance.storage.store(StorageKeys.Avatars, avatars);
}, 1000),
);
@ -138,7 +138,7 @@ function createOrUpdateAvatar(
function ensureAvatarCache(cache: Map<string, Avatar> | undefined): asserts cache is Map<string, Avatar> {
if (cache == null) {
const avatars: [string, Avatar][] | undefined = Container.instance.storage
.get<[string, SerializedAvatar][]>(GlobalState.Avatars)
.get<[string, SerializedAvatar][]>(StorageKeys.Avatars)
?.map<[string, Avatar]>(([key, avatar]) => [
key,
{
@ -246,7 +246,7 @@ export function getPresenceDataUri(status: ContactPresenceStatus) {
export function resetAvatarCache(reset: 'all' | 'failed' | 'fallback') {
switch (reset) {
case 'all':
void Container.instance.storage.delete(GlobalState.Avatars);
void Container.instance.storage.delete(StorageKeys.Avatars);
avatarCache?.clear();
avatarQueue.clear();
break;

+ 2
- 2
src/commands/closeView.ts View File

@ -1,7 +1,7 @@
import { Commands, ContextKeys } from '../constants';
import type { Container } from '../container';
import { setContext } from '../context';
import { SyncedState } from '../storage';
import { SyncedStorageKeys } from '../storage';
import { command } from '../system/command';
import { Command, CommandContext } from './base';
@ -18,7 +18,7 @@ export class CloseViewCommand extends Command {
async execute(command: Commands) {
switch (command) {
case Commands.CloseWelcomeView:
await this.container.storage.store(SyncedState.WelcomeViewVisible, false);
await this.container.storage.store(SyncedStorageKeys.WelcomeViewVisible, false);
await setContext(ContextKeys.ViewsWelcomeVisible, false);
break;
}

+ 4
- 4
src/commands/gitCommands.utils.ts View File

@ -2,7 +2,7 @@ import { GitCommandSorting } from '../config';
import { ContextKeys } from '../constants';
import type { Container } from '../container';
import { getContext } from '../context';
import { Usage, WorkspaceState } from '../storage';
import { Usage, WorkspaceStorageKeys } from '../storage';
import { BranchGitCommand } from './git/branch';
import { CherryPickGitCommand } from './git/cherry-pick';
import { CoAuthorsGitCommand } from './git/coauthors';
@ -93,7 +93,7 @@ export class PickCommandStep implements QuickPickStep {
].filter(<T>(i: T | undefined): i is T => i != null);
if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage);
const usage = this.container.storage.getWorkspace<Usage>(WorkspaceStorageKeys.GitCommandPaletteUsage);
if (usage != null) {
this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0));
}
@ -133,12 +133,12 @@ export class PickCommandStep implements QuickPickStep {
}
private async updateCommandUsage(id: string, timestamp: number) {
let usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage);
let usage = this.container.storage.getWorkspace<Usage>(WorkspaceStorageKeys.GitCommandPaletteUsage);
if (usage === undefined) {
usage = Object.create(null) as Usage;
}
usage[id] = timestamp;
await this.container.storage.storeWorkspace(WorkspaceState.GitCommandPaletteUsage, usage);
await this.container.storage.storeWorkspace(WorkspaceStorageKeys.GitCommandPaletteUsage, usage);
}
}

+ 2
- 2
src/commands/showView.ts View File

@ -1,7 +1,7 @@
import { Commands, ContextKeys } from '../constants';
import type { Container } from '../container';
import { setContext } from '../context';
import { SyncedState } from '../storage';
import { SyncedStorageKeys } from '../storage';
import { command, executeCommand } from '../system/command';
import { Command, CommandContext } from './base';
@ -51,7 +51,7 @@ export class ShowViewCommand extends Command {
return this.container.tagsView.show();
case Commands.ShowWelcomeView:
await setContext(ContextKeys.ViewsWelcomeVisible, true);
void this.container.storage.store(SyncedState.WelcomeViewVisible, true);
void this.container.storage.store(SyncedStorageKeys.WelcomeViewVisible, true);
void (await executeCommand('gitlens.views.welcome.focus'));
}

+ 3
- 3
src/env/node/git/localGitProvider.ts View File

@ -95,7 +95,7 @@ import { RemoteProvider, RichRemoteProvider } from '../../../git/remotes/provide
import { SearchPattern } from '../../../git/search';
import { LogCorrelationContext, Logger } from '../../../logger';
import { Messages } from '../../../messages';
import { WorkspaceState } from '../../../storage';
import { WorkspaceStorageKeys } from '../../../storage';
import { countStringLength, filterMap } from '../../../system/array';
import { gate } from '../../../system/decorators/gate';
import { debug, log } from '../../../system/decorators/log';
@ -266,7 +266,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const potentialGitPaths =
configuration.getAny<string | string[]>('git.path') ??
this.container.storage.getWorkspace(WorkspaceState.GitPath, undefined);
this.container.storage.getWorkspace(WorkspaceStorageKeys.GitPath, undefined);
const start = hrtime();
@ -290,7 +290,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const location = await any<GitLocation>(findGitPromise, findGitFromSCMPromise);
// Save the found git path, but let things settle first to not impact startup performance
setTimeout(() => {
void this.container.storage.storeWorkspace(WorkspaceState.GitPath, location.path);
void this.container.storage.storeWorkspace(WorkspaceStorageKeys.GitPath, location.path);
}, 1000);
if (cc != null) {

+ 23
- 19
src/extension.ts View File

@ -12,7 +12,7 @@ import { GitBranch, GitCommit } from './git/models';
import { Logger, LogLevel } from './logger';
import { Messages } from './messages';
import { registerPartnerActionRunners } from './partners';
import { GlobalState, SyncedState } from './storage';
import { StorageKeys, SyncedStorageKeys } from './storage';
import { executeCommand, registerCommands } from './system/command';
import { once } from './system/event';
import { Stopwatch } from './system/stopwatch';
@ -68,10 +68,10 @@ export async function activate(context: ExtensionContext): Promise
setKeysForSync(context);
const syncedVersion = context.globalState.get<string>(SyncedState.Version);
const syncedVersion = context.globalState.get<string>(SyncedStorageKeys.Version);
const localVersion =
context.globalState.get<string>(GlobalState.Version) ??
context.globalState.get<string>(GlobalState.Deprecated_Version);
context.globalState.get<string>(StorageKeys.Version) ??
context.globalState.get<string>(StorageKeys.Deprecated_Version);
let previousVersion: string | undefined;
if (localVersion == null || syncedVersion == null) {
@ -85,17 +85,17 @@ export async function activate(context: ExtensionContext): Promise
let exitMessage;
if (Logger.enabled(LogLevel.Debug)) {
exitMessage = `syncedVersion=${syncedVersion}, localVersion=${localVersion}, previousVersion=${previousVersion}, welcome=${context.globalState.get<boolean>(
SyncedState.WelcomeViewVisible,
SyncedStorageKeys.WelcomeViewVisible,
)}`;
}
if (previousVersion == null) {
void context.globalState.update(SyncedState.WelcomeViewVisible, true);
void context.globalState.update(SyncedStorageKeys.WelcomeViewVisible, true);
void setContext(ContextKeys.ViewsWelcomeVisible, true);
} else {
void setContext(
ContextKeys.ViewsWelcomeVisible,
context.globalState.get<boolean>(SyncedState.WelcomeViewVisible) ?? false,
context.globalState.get<boolean>(SyncedStorageKeys.WelcomeViewVisible) ?? false,
);
}
@ -111,11 +111,11 @@ export async function activate(context: ExtensionContext): Promise
void showWelcomeOrWhatsNew(container, gitlensVersion, previousVersion);
void context.globalState.update(GlobalState.Version, gitlensVersion);
void context.globalState.update(StorageKeys.Version, gitlensVersion);
// Only update our synced version if the new version is greater
if (syncedVersion == null || compare(gitlensVersion, syncedVersion) === 1) {
void context.globalState.update(SyncedState.Version, gitlensVersion);
void context.globalState.update(SyncedStorageKeys.Version, gitlensVersion);
}
if (cfg.outputLevel === OutputLevel.Debug) {
@ -159,8 +159,12 @@ export function deactivate() {
// }
// }
function setKeysForSync(context: ExtensionContext, ...keys: (SyncedState | string)[]) {
return context.globalState?.setKeysForSync([...keys, SyncedState.Version, SyncedState.WelcomeViewVisible]);
function setKeysForSync(context: ExtensionContext, ...keys: (SyncedStorageKeys | string)[]) {
return context.globalState?.setKeysForSync([
...keys,
SyncedStorageKeys.Version,
SyncedStorageKeys.WelcomeViewVisible,
]);
}
function registerBuiltInActionRunners(container: Container): void {
@ -201,19 +205,19 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (container.config.showWelcomeOnInstall === false) return;
if (window.state.focused) {
await container.storage.delete(GlobalState.PendingWelcomeOnFocus);
await container.storage.delete(StorageKeys.PendingWelcomeOnFocus);
await executeCommand(Commands.ShowWelcomePage);
} else {
// Save pending on window getting focus
await container.storage.store(GlobalState.PendingWelcomeOnFocus, true);
await container.storage.store(StorageKeys.PendingWelcomeOnFocus, true);
const disposable = window.onDidChangeWindowState(e => {
if (!e.focused) return;
disposable.dispose();
// If the window is now focused and we are pending the welcome, clear the pending state and show the welcome
if (container.storage.get(GlobalState.PendingWelcomeOnFocus) === true) {
void container.storage.delete(GlobalState.PendingWelcomeOnFocus);
if (container.storage.get(StorageKeys.PendingWelcomeOnFocus) === true) {
void container.storage.delete(StorageKeys.PendingWelcomeOnFocus);
if (container.config.showWelcomeOnInstall) {
void executeCommand(Commands.ShowWelcomePage);
}
@ -242,19 +246,19 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (major !== prevMajor && container.config.showWhatsNewAfterUpgrades) {
if (window.state.focused) {
await container.storage.delete(GlobalState.PendingWhatsNewOnFocus);
await container.storage.delete(StorageKeys.PendingWhatsNewOnFocus);
await Messages.showWhatsNewMessage(version);
} else {
// Save pending on window getting focus
await container.storage.store(GlobalState.PendingWhatsNewOnFocus, true);
await container.storage.store(StorageKeys.PendingWhatsNewOnFocus, true);
const disposable = window.onDidChangeWindowState(e => {
if (!e.focused) return;
disposable.dispose();
// If the window is now focused and we are pending the what's new, clear the pending state and show the what's new
if (container.storage.get(GlobalState.PendingWhatsNewOnFocus) === true) {
void container.storage.delete(GlobalState.PendingWhatsNewOnFocus);
if (container.storage.get(StorageKeys.PendingWhatsNewOnFocus) === true) {
void container.storage.delete(StorageKeys.PendingWhatsNewOnFocus);
if (container.config.showWhatsNewAfterUpgrades) {
void Messages.showWhatsNewMessage(version);
}

+ 3
- 3
src/git/gitProviderService.ts View File

@ -23,7 +23,7 @@ import { setContext } from '../context';
import { ProviderNotFoundError } from '../errors';
import { Logger } from '../logger';
import { asRepoComparisonKey, RepoComparisionKey, Repositories } from '../repositories';
import { WorkspaceState } from '../storage';
import { WorkspaceStorageKeys } from '../storage';
import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
@ -499,7 +499,7 @@ export class GitProviderService implements Disposable {
// If we think we should be disabled during startup, check if we have a saved value from the last time this repo was loaded
if (!enabled && this._initializing) {
disabled = !(
this.container.storage.getWorkspace<boolean>(WorkspaceState.AssumeRepositoriesOnStartup) ?? true
this.container.storage.getWorkspace<boolean>(WorkspaceStorageKeys.AssumeRepositoriesOnStartup) ?? true
);
}
@ -520,7 +520,7 @@ export class GitProviderService implements Disposable {
await Promise.all(promises);
if (!this._initializing) {
void this.container.storage.storeWorkspace(WorkspaceState.AssumeRepositoriesOnStartup, enabled);
void this.container.storage.storeWorkspace(WorkspaceStorageKeys.AssumeRepositoriesOnStartup, enabled);
}
}

+ 2
- 2
src/git/models/branch.ts View File

@ -1,6 +1,6 @@
import { BranchSorting, configuration, DateStyle } from '../../configuration';
import { Container } from '../../container';
import { Starred, WorkspaceState } from '../../storage';
import { Starred, WorkspaceStorageKeys } from '../../storage';
import { formatDate, fromNow } from '../../system/date';
import { debug } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
@ -234,7 +234,7 @@ export class GitBranch implements GitBranchReference {
}
get starred() {
const starred = Container.instance.storage.getWorkspace<Starred>(WorkspaceState.StarredBranches);
const starred = Container.instance.storage.getWorkspace<Starred>(WorkspaceStorageKeys.StarredBranches);
return starred !== undefined && starred[this.id] === true;
}

+ 3
- 3
src/git/models/remote.ts View File

@ -1,5 +1,5 @@
import { Container } from '../../container';
import { WorkspaceState } from '../../storage';
import { WorkspaceStorageKeys } from '../../storage';
import { sortCompare } from '../../system/string';
import { RemoteProvider, RichRemoteProvider } from '../remotes/provider';
@ -59,7 +59,7 @@ export class GitRemote
) {}
get default() {
const defaultRemote = Container.instance.storage.getWorkspace<string>(WorkspaceState.DefaultRemote);
const defaultRemote = Container.instance.storage.getWorkspace<string>(WorkspaceStorageKeys.DefaultRemote);
return this.id === defaultRemote;
}
@ -84,7 +84,7 @@ export class GitRemote
async setAsDefault(state: boolean = true, updateViews: boolean = true) {
void (await Container.instance.storage.storeWorkspace(
WorkspaceState.DefaultRemote,
WorkspaceStorageKeys.DefaultRemote,
state ? this.id : undefined,
));

+ 5
- 5
src/git/models/repository.ts View File

@ -17,7 +17,7 @@ import { Container } from '../../container';
import { Logger } from '../../logger';
import { Messages } from '../../messages';
import { asRepoComparisonKey } from '../../repositories';
import { Starred, WorkspaceState } from '../../storage';
import { Starred, WorkspaceStorageKeys } from '../../storage';
import { filterMap, groupByMap } from '../../system/array';
import { executeActionCommand, executeCoreGitCommand } from '../../system/command';
import { formatDate, fromNow } from '../../system/date';
@ -821,7 +821,7 @@ export class Repository implements Disposable {
}
get starred() {
const starred = this.container.storage.getWorkspace<Starred>(WorkspaceState.StarredRepositories);
const starred = this.container.storage.getWorkspace<Starred>(WorkspaceStorageKeys.StarredRepositories);
return starred != null && starred[this.id] === true;
}
@ -891,15 +891,15 @@ export class Repository implements Disposable {
private async updateStarred(star: boolean, branch?: GitBranch) {
if (branch != null) {
await this.updateStarredCore(WorkspaceState.StarredBranches, branch.id, star);
await this.updateStarredCore(WorkspaceStorageKeys.StarredBranches, branch.id, star);
} else {
await this.updateStarredCore(WorkspaceState.StarredRepositories, this.id, star);
await this.updateStarredCore(WorkspaceStorageKeys.StarredRepositories, this.id, star);
}
this.fireChange(RepositoryChange.Starred);
}
private async updateStarredCore(key: WorkspaceState, id: string, star: boolean) {
private async updateStarredCore(key: WorkspaceStorageKeys, id: string, star: boolean) {
let starred = this.container.storage.getWorkspace<Starred>(key);
if (starred === undefined) {
starred = Object.create(null) as Starred;

+ 3
- 3
src/git/remotes/provider.ts View File

@ -13,7 +13,7 @@ import { AutolinkReference } from '../../config';
import { Container } from '../../container';
import { AuthenticationError, ProviderRequestClientError } from '../../errors';
import { Logger } from '../../logger';
import { WorkspaceState } from '../../storage';
import { WorkspaceStorageKeys } from '../../storage';
import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log';
import { encodeUrl } from '../../system/encoding';
@ -303,8 +303,8 @@ export abstract class RichRemoteProvider extends RemoteProvider {
return this.custom ? `${this.name}:${this.domain}` : this.name;
}
private get connectedKey(): `${WorkspaceState.ConnectedPrefix}${string}` {
return `${WorkspaceState.ConnectedPrefix}${this.key}`;
private get connectedKey(): `${WorkspaceStorageKeys.ConnectedPrefix}${string}` {
return `${WorkspaceStorageKeys.ConnectedPrefix}${this.key}`;
}
get maybeConnected(): boolean | undefined {

+ 29
- 13
src/storage.ts View File

@ -5,42 +5,58 @@ import type { SearchPattern } from './git/search';
export class Storage {
constructor(private readonly context: ExtensionContext) {}
get<T>(key: GlobalState | SyncedState): T | undefined;
get<T>(key: GlobalState | SyncedState, defaultValue: T): T;
get<T>(key: GlobalState | SyncedState, defaultValue?: T): T | undefined {
get<T>(key: StorageKeys | SyncedStorageKeys): T | undefined;
get<T>(key: StorageKeys | SyncedStorageKeys, defaultValue: T): T;
get<T>(key: StorageKeys | SyncedStorageKeys, defaultValue?: T): T | undefined {
return this.context.globalState.get(key, defaultValue);
}
async delete(key: GlobalState | SyncedState): Promise<void> {
async delete(key: StorageKeys | SyncedStorageKeys): Promise<void> {
return this.context.globalState.update(key, undefined);
}
async store(key: GlobalState | SyncedState, value: unknown): Promise<void> {
async store(key: StorageKeys | SyncedStorageKeys, value: unknown): Promise<void> {
return this.context.globalState.update(key, value);
}
getWorkspace<T>(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`): T | undefined;
getWorkspace<T>(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`, defaultValue: T): T;
async getSecret(key: SecretKeys): Promise<string | undefined> {
return this.context.secrets.get(key);
}
async deleteSecret(key: SecretKeys): Promise<void> {
return this.context.secrets.delete(key);
}
async storeSecret(key: SecretKeys, value: string): Promise<void> {
return this.context.secrets.store(key, value);
}
getWorkspace<T>(key: WorkspaceStorageKeys | `${WorkspaceStorageKeys.ConnectedPrefix}${string}`): T | undefined;
getWorkspace<T>(key: WorkspaceStorageKeys | `${WorkspaceStorageKeys.ConnectedPrefix}${string}`, defaultValue: T): T;
getWorkspace<T>(
key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`,
key: WorkspaceStorageKeys | `${WorkspaceStorageKeys.ConnectedPrefix}${string}`,
defaultValue?: T,
): T | undefined {
return this.context.workspaceState.get(key, defaultValue);
}
async deleteWorkspace(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`): Promise<void> {
async deleteWorkspace(
key: WorkspaceStorageKeys | `${WorkspaceStorageKeys.ConnectedPrefix}${string}`,
): Promise<void> {
return this.context.workspaceState.update(key, undefined);
}
async storeWorkspace(
key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`,
key: WorkspaceStorageKeys | `${WorkspaceStorageKeys.ConnectedPrefix}${string}`,
value: unknown,
): Promise<void> {
return this.context.workspaceState.update(key, value);
}
}
export const enum GlobalState {
export type SecretKeys = string;
export const enum StorageKeys {
Avatars = 'gitlens:avatars',
PendingWelcomeOnFocus = 'gitlens:pendingWelcomeOnFocus',
PendingWhatsNewOnFocus = 'gitlens:pendingWhatsNewOnFocus',
@ -49,14 +65,14 @@ export const enum GlobalState {
Deprecated_Version = 'gitlensVersion',
}
export const enum SyncedState {
export const enum SyncedStorageKeys {
Version = 'gitlens:synced:version',
WelcomeViewVisible = 'gitlens:views:welcome:visible',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
}
export const enum WorkspaceState {
export const enum WorkspaceStorageKeys {
AssumeRepositoriesOnStartup = 'gitlens:assumeRepositoriesOnStartup',
GitPath = 'gitlens:gitPath',

+ 6
- 4
src/views/nodes/compareBranchNode.ts View File

@ -5,7 +5,7 @@ import { GitUri } from '../../git/gitUri';
import { GitBranch, GitRevision } from '../../git/models';
import { CommandQuickPickItem } from '../../quickpicks/items/common';
import { ReferencePicker } from '../../quickpicks/referencePicker';
import { BranchComparison, BranchComparisons, WorkspaceState } from '../../storage';
import { BranchComparison, BranchComparisons, WorkspaceStorageKeys } from '../../storage';
import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log';
import { pluralize } from '../../system/string';
@ -332,7 +332,7 @@ export class CompareBranchNode extends ViewNode
private loadCompareWith() {
const comparisons = this.view.container.storage.getWorkspace<BranchComparisons>(
WorkspaceState.BranchComparisons,
WorkspaceStorageKeys.BranchComparisons,
);
const id = `${this.branch.id}${this.branch.current ? '+current' : ''}`;
@ -351,7 +351,9 @@ export class CompareBranchNode extends ViewNode
private async updateCompareWith(compareWith: BranchComparison | undefined) {
this._compareWith = compareWith;
let comparisons = this.view.container.storage.getWorkspace<BranchComparisons>(WorkspaceState.BranchComparisons);
let comparisons = this.view.container.storage.getWorkspace<BranchComparisons>(
WorkspaceStorageKeys.BranchComparisons,
);
if (comparisons == null) {
if (compareWith == null) return;
@ -368,6 +370,6 @@ export class CompareBranchNode extends ViewNode
const { [id]: _, ...rest } = comparisons;
comparisons = rest;
}
await this.view.container.storage.storeWorkspace(WorkspaceState.BranchComparisons, comparisons);
await this.view.container.storage.storeWorkspace(WorkspaceStorageKeys.BranchComparisons, comparisons);
}
}

+ 4
- 4
src/views/repositoriesView.ts View File

@ -29,7 +29,7 @@ import {
GitStashReference,
GitTagReference,
} from '../git/models';
import { WorkspaceState } from '../storage';
import { WorkspaceStorageKeys } from '../storage';
import { executeCommand } from '../system/command';
import { gate } from '../system/decorators/gate';
import {
@ -276,7 +276,7 @@ export class RepositoriesView extends ViewBase
get autoRefresh() {
return (
this.config.autoRefresh &&
this.container.storage.getWorkspace<boolean>(WorkspaceState.ViewsRepositoriesAutoRefresh, true)
this.container.storage.getWorkspace<boolean>(WorkspaceStorageKeys.ViewsRepositoriesAutoRefresh, true)
);
}
@ -774,12 +774,12 @@ export class RepositoriesView extends ViewBase
if (enabled) {
if (workspaceEnabled === undefined) {
workspaceEnabled = this.container.storage.getWorkspace<boolean>(
WorkspaceState.ViewsRepositoriesAutoRefresh,
WorkspaceStorageKeys.ViewsRepositoriesAutoRefresh,
true,
);
} else {
await this.container.storage.storeWorkspace(
WorkspaceState.ViewsRepositoriesAutoRefresh,
WorkspaceStorageKeys.ViewsRepositoriesAutoRefresh,
workspaceEnabled,
);
}

+ 21
- 10
src/views/searchAndCompareView.ts View File

@ -8,7 +8,7 @@ import { GitLog, GitRevision } from '../git/models';
import { SearchPattern } from '../git/search';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks/referencePicker';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { NamedRef, PinnedItem, PinnedItems, WorkspaceState } from '../storage';
import { NamedRef, PinnedItem, PinnedItems, WorkspaceStorageKeys } from '../storage';
import { filterMap } from '../system/array';
import { executeCommand } from '../system/command';
import { gate } from '../system/decorators/gate';
@ -358,7 +358,10 @@ export class SearchAndCompareView extends ViewBase
}
get keepResults(): boolean {
return this.container.storage.getWorkspace<boolean>(WorkspaceState.ViewsSearchAndCompareKeepResults, true);
return this.container.storage.getWorkspace<boolean>(
WorkspaceStorageKeys.ViewsSearchAndCompareKeepResults,
true,
);
}
clear() {
@ -437,12 +440,12 @@ export class SearchAndCompareView extends ViewBase
getPinned() {
let savedPins = this.container.storage.getWorkspace<PinnedItems>(
WorkspaceState.ViewsSearchAndComparePinnedItems,
WorkspaceStorageKeys.ViewsSearchAndComparePinnedItems,
);
if (savedPins == null) {
// Migrate any deprecated pinned items
const deprecatedPins = this.container.storage.getWorkspace<DeprecatedPinnedComparisons>(
WorkspaceState.Deprecated_PinnedComparisons,
WorkspaceStorageKeys.Deprecated_PinnedComparisons,
);
if (deprecatedPins == null) return [];
@ -457,8 +460,11 @@ export class SearchAndCompareView extends ViewBase
};
}
void this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndComparePinnedItems, savedPins);
void this.container.storage.deleteWorkspace(WorkspaceState.Deprecated_PinnedComparisons);
void this.container.storage.storeWorkspace(
WorkspaceStorageKeys.ViewsSearchAndComparePinnedItems,
savedPins,
);
void this.container.storage.deleteWorkspace(WorkspaceStorageKeys.Deprecated_PinnedComparisons);
}
const migratedPins = Object.create(null) as PinnedItems;
@ -501,13 +507,18 @@ export class SearchAndCompareView extends ViewBase
});
if (migrated) {
void this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndComparePinnedItems, migratedPins);
void this.container.storage.storeWorkspace(
WorkspaceStorageKeys.ViewsSearchAndComparePinnedItems,
migratedPins,
);
}
return pins;
}
async updatePinned(id: string, pin?: PinnedItem) {
let pinned = this.container.storage.getWorkspace<PinnedItems>(WorkspaceState.ViewsSearchAndComparePinnedItems);
let pinned = this.container.storage.getWorkspace<PinnedItems>(
WorkspaceStorageKeys.ViewsSearchAndComparePinnedItems,
);
if (pinned == null) {
pinned = Object.create(null) as PinnedItems;
}
@ -519,7 +530,7 @@ export class SearchAndCompareView extends ViewBase
pinned = rest;
}
await this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndComparePinnedItems, pinned);
await this.container.storage.storeWorkspace(WorkspaceStorageKeys.ViewsSearchAndComparePinnedItems, pinned);
this.triggerNodeChange(this.ensureRoot());
}
@ -564,7 +575,7 @@ export class SearchAndCompareView extends ViewBase
}
private setKeepResults(enabled: boolean) {
void this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndCompareKeepResults, enabled);
void this.container.storage.storeWorkspace(WorkspaceStorageKeys.ViewsSearchAndCompareKeepResults, enabled);
void setContext(ContextKeys.ViewsSearchAndCompareKeepResults, enabled);
}

Loading…
Cancel
Save