From 1f2d7ccc9571baf97eedc4f435d847caab67cf09 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Tue, 8 Aug 2023 16:01:54 +0200 Subject: [PATCH 1/3] chore: move keytar to loadSavedConnections --- src/connectionController.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/connectionController.ts b/src/connectionController.ts index 754d85e1c..e33ca8d02 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -143,6 +143,13 @@ export default class ConnectionController { } async loadSavedConnections(): Promise { + try { + ext.keytarModule = + ext.keytarModule === undefined ? createKeytar() : ext.keytarModule; + } catch (err) { + // Couldn't load keytar, proceed without storing & loading connections. + } + const globalAndWorkspaceConnections = Object.entries({ ...this._storageController.get( StorageVariables.GLOBAL_SAVED_CONNECTIONS, @@ -296,13 +303,6 @@ 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) { From d1db1b6f29d01cf6a57ab69741a3b3e341dafab4 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Tue, 8 Aug 2023 16:10:23 +0200 Subject: [PATCH 2/3] chore: Only load keytar if connections were not migrated earlier --- src/connectionController.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/connectionController.ts b/src/connectionController.ts index e33ca8d02..2c51a5c06 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -143,13 +143,6 @@ export default class ConnectionController { } async loadSavedConnections(): Promise { - try { - ext.keytarModule = - ext.keytarModule === undefined ? createKeytar() : ext.keytarModule; - } catch (err) { - // Couldn't load keytar, proceed without storing & loading connections. - } - const globalAndWorkspaceConnections = Object.entries({ ...this._storageController.get( StorageVariables.GLOBAL_SAVED_CONNECTIONS, @@ -177,6 +170,15 @@ export default class ConnectionController { [] ); + if (connectionIdsThatDidNotMigrateEarlier.length > 0) { + try { + ext.keytarModule = + ext.keytarModule === undefined ? createKeytar() : ext.keytarModule; + } catch (err) { + // Couldn't load keytar, proceed without storing & loading connections. + } + } + // A list of connection descriptors that we could not migration in the // current load of connections because of Keytar not being available. const connectionsThatDidNotMigrate = ( From f6c69df65eeaf43d6097e0ee61a6094019c11990 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Tue, 8 Aug 2023 16:40:20 +0200 Subject: [PATCH 3/3] chore: only load keytar if at least one connection needs to be migrated --- src/connectionController.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/connectionController.ts b/src/connectionController.ts index 2c51a5c06..e4f03cb68 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -170,7 +170,12 @@ export default class ConnectionController { [] ); - if (connectionIdsThatDidNotMigrateEarlier.length > 0) { + const hasConnectionsThatDidNotMigrateEarlier = + !!globalAndWorkspaceConnections.some( + ([, connectionInfo]) => !connectionInfo.storageLocation + ); + + if (hasConnectionsThatDidNotMigrateEarlier) { try { ext.keytarModule = ext.keytarModule === undefined ? createKeytar() : ext.keytarModule;