Skip to content

Commit

Permalink
fix: config loading for passphrase cache feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhongtw committed Aug 23, 2023
1 parent 9d5c5f6 commit 8af1f88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function activate(context: vscode.ExtensionContext) {
logger,
syncStatusInterval,
secretStorage,
configuration.get<boolean>('enableSecurelyPassphraseCache', false),
configuration.get<boolean>('enablePassphraseCache', false),
vscode.workspace.isTrusted,
os.homedir(),
);
Expand All @@ -114,7 +114,7 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}
const passphrase = await vscode.window.showInputBox({
prompt: keyStatusManager.enableSecurelyPassphraseCache
prompt: keyStatusManager.enablePassphraseCache
? vscode.l10n.t(m['passphraseInputPromptTitleWhenSecurelyPassphraseCacheEnabled'])
: vscode.l10n.t(m['passphraseInputPromptTitle']),
password: true,
Expand All @@ -132,7 +132,7 @@ export async function activate(context: vscode.ExtensionContext) {
}
}

if (keyStatusManager.enableSecurelyPassphraseCache) {
if (keyStatusManager.enablePassphraseCache) {
await secretStorage.set(currentKey.fingerprint, passphrase);
vscode.window.showInformationMessage(vscode.l10n.t(m['keyUnlockedWithCachedPassphrase']));
} else {
Expand Down Expand Up @@ -232,17 +232,17 @@ export async function activate(context: vscode.ExtensionContext) {
const configuration = vscode.workspace.getConfiguration('gpgIndicator');
keyStatusManager.updateSyncInterval(configuration.get<number>('statusRefreshInterval', 30));
logger.setLevel(configuration.get<string>('outputLogLevel', "info"));
const newEnableSecurelyPassphraseCache = configuration.get<boolean>('enableSecurelyPassphraseCache', false);
if (keyStatusManager.enableSecurelyPassphraseCache && !newEnableSecurelyPassphraseCache) {
const newEnablePassphraseCache = configuration.get<boolean>('enablePassphraseCache', false);
if (keyStatusManager.enablePassphraseCache && !newEnablePassphraseCache) {
try {
await Promise.all([...secretStorage].map((key) => secretStorage.delete(key)));
vscode.window.showInformationMessage(vscode.l10n.t(m['passphraseCleared']));
}
catch (e) {
logger.error(`Cannot clear the passphrase cache when "enableSecurelyPassphraseCache" turn to off: ${e instanceof Error ? e.message : JSON.stringify(e, null, 4)}`);
logger.error(`Cannot clear the passphrase cache when "enablePassphraseCache" turn to off: ${e instanceof Error ? e.message : JSON.stringify(e, null, 4)}`);
}
}
keyStatusManager.enableSecurelyPassphraseCache = newEnableSecurelyPassphraseCache;
keyStatusManager.enablePassphraseCache = newEnablePassphraseCache;
const oldStatusStyle = statusStyle;
statusStyle = configuration.get<statusStyleEnum>('statusStyle', "fingerprintWithUserId");
if (oldStatusStyle !== statusStyle) {
Expand Down Expand Up @@ -302,7 +302,7 @@ async function introduceCacheFeature(context: vscode.ExtensionContext) {
}
await context.globalState.update("user:is-cache-notice-read", true);
if (result === actions.YES) {
configuration.update("enableSecurelyPassphraseCache", true, true);
configuration.update("enablePassphraseCache", true, true);
}

let postMessage: string;
Expand All @@ -312,7 +312,7 @@ async function introduceCacheFeature(context: vscode.ExtensionContext) {
postMessage = m["enableSecurelyPassphraseCacheNoticeForbidden"];
}
// Due to the fact that vscode automatically collapses ordinary notifications into one line,
// causing `enableSecurelyPassphraseCache` setting links to be collapsed,
// causing `enablePassphraseCache` setting links to be collapsed,
// notifications with options are used instead to avoid being collapsed.
const postMessageResult = await vscode.window.showInformationMessage<string>(
vscode.l10n.t(postMessage),
Expand Down
4 changes: 2 additions & 2 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class KeyStatusManager {
private logger: Logger,
private syncInterval: number,
private secretStorage: Storage,
public enableSecurelyPassphraseCache: boolean,
public enablePassphraseCache: boolean,
private isWorkspaceTrusted: boolean,
private defaultFolder: string,
) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class KeyStatusManager {
let newEvent: KeyStatusEvent | undefined;
const hasPassphrase = (await this.secretStorage.get(this.currentKey.fingerprint) !== undefined);
try {
if (this.enableSecurelyPassphraseCache && hasPassphrase) {
if (this.enablePassphraseCache && hasPassphrase) {
this.isUnlocked = await this.tryUnlockWithCache(isChanged, isUnlockedPrev, this.currentKey);
} else {
this.isUnlocked = await this.showInfoOnly(isChanged, isUnlockedPrev, this.currentKey);
Expand Down

0 comments on commit 8af1f88

Please sign in to comment.