Skip to content

Commit 095a20b

Browse files
authored
chore: only load keytar during the migration process VSCODE-450 (#572)
1 parent 711587b commit 095a20b

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/connectionController.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ConnectionString from 'mongodb-connection-string-url';
1313
import { EventEmitter } from 'events';
1414
import type { MongoClientOptions } from 'mongodb';
1515
import { v4 as uuidv4 } from 'uuid';
16-
16+
import { createKeytar } from './utils/keytar';
1717
import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants';
1818
import { createLogger } from './logging';
1919
import { ext } from './extensionConstants';
@@ -296,6 +296,13 @@ export default class ConnectionController {
296296
async _migrateConnectionWithKeytarSecrets(
297297
savedConnectionInfo: StoreConnectionInfoWithConnectionOptions
298298
): Promise<MigratedStoreConnectionInfoWithConnectionOptions | undefined> {
299+
try {
300+
ext.keytarModule =
301+
ext.keytarModule === undefined ? createKeytar() : ext.keytarModule;
302+
} catch (err) {
303+
// Couldn't load keytar, proceed without storing & loading connections.
304+
}
305+
299306
// If the Keytar module is not available, we simply mark the connections
300307
// storage as Keytar and return
301308
if (!ext.keytarModule) {

src/extension.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import * as vscode from 'vscode';
44

55
import { ext } from './extensionConstants';
6-
import { createKeytar } from './utils/keytar';
76
import { createLogger } from './logging';
87
// eslint-disable-next-line @typescript-eslint/no-var-requires
98
const { version } = require('../package.json');
@@ -30,14 +29,6 @@ export async function activate(
3029
context: vscode.ExtensionContext
3130
): Promise<void> {
3231
ext.context = context;
33-
let hasKeytar = false;
34-
35-
try {
36-
ext.keytarModule = createKeytar();
37-
hasKeytar = true;
38-
} catch (err) {
39-
// Couldn't load keytar, proceed without storing & loading connections.
40-
}
4132

4233
const defaultConnectionSavingLocation = vscode.workspace
4334
.getConfiguration('mdb.connectionSaving')
@@ -53,7 +44,6 @@ export async function activate(
5344
workspaceStoragePath: context.storageUri?.path,
5445
globalStoragePath: context.globalStorageUri.path,
5546
defaultConnectionSavingLocation,
56-
hasKeytar,
5747
buildInfo: {
5848
nodeVersion: process.version,
5949
runtimePlatform: process.platform,

0 commit comments

Comments
 (0)