From 582b2e516c3bd9234dd502de0770578b52f616b7 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Wed, 2 Aug 2023 17:26:46 +0200 Subject: [PATCH] chore: only load keytar during the migration process VSCODE-450 --- src/connectionController.ts | 9 ++++++++- src/extension.ts | 10 ---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/connectionController.ts b/src/connectionController.ts index 9c39d75fa..754d85e1c 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -13,7 +13,7 @@ import ConnectionString from 'mongodb-connection-string-url'; import { EventEmitter } from 'events'; import type { MongoClientOptions } from 'mongodb'; import { v4 as uuidv4 } from 'uuid'; - +import { createKeytar } from './utils/keytar'; import { CONNECTION_STATUS } from './views/webview-app/extension-app-message-constants'; import { createLogger } from './logging'; import { ext } from './extensionConstants'; @@ -296,6 +296,13 @@ export default class ConnectionController { async _migrateConnectionWithKeytarSecrets( savedConnectionInfo: StoreConnectionInfoWithConnectionOptions ): Promise { + try { + ext.keytarModule = + ext.keytarModule === undefined ? createKeytar() : ext.keytarModule; + } catch (err) { + // Couldn't load keytar, proceed without storing & loading connections. + } + // If the Keytar module is not available, we simply mark the connections // storage as Keytar and return if (!ext.keytarModule) { diff --git a/src/extension.ts b/src/extension.ts index ae57ea4d3..a4d690889 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,6 @@ import * as vscode from 'vscode'; import { ext } from './extensionConstants'; -import { createKeytar } from './utils/keytar'; import { createLogger } from './logging'; // eslint-disable-next-line @typescript-eslint/no-var-requires const { version } = require('../package.json'); @@ -30,14 +29,6 @@ export async function activate( context: vscode.ExtensionContext ): Promise { ext.context = context; - let hasKeytar = false; - - try { - ext.keytarModule = createKeytar(); - hasKeytar = true; - } catch (err) { - // Couldn't load keytar, proceed without storing & loading connections. - } const defaultConnectionSavingLocation = vscode.workspace .getConfiguration('mdb.connectionSaving') @@ -53,7 +44,6 @@ export async function activate( workspaceStoragePath: context.storageUri?.path, globalStoragePath: context.globalStorageUri.path, defaultConnectionSavingLocation, - hasKeytar, buildInfo: { nodeVersion: process.version, runtimePlatform: process.platform,