Skip to content

Commit

Permalink
feat(compass): display warning message to user when Compass cannot ac…
Browse files Browse the repository at this point in the history
…cess cred… (mongodb-js#6056)

* feat: display warning message to user when Compass cannot access credential storage COMPASS-7819

* feat: track secret storage not available

* fix: await for app be ready before sending telemetry
  • Loading branch information
alenakhineika authored Jul 26, 2024
1 parent 3d110bd commit 5d039d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/compass/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { globalAppRegistry } from 'hadron-app-registry';
import { defaultPreferencesInstance } from 'compass-preferences-model';
import semver from 'semver';
import { CompassElectron } from './components/entrypoint';
import { openToast } from '@mongodb-js/compass-components';

// https://github.com/nodejs/node/issues/40537
dns.setDefaultResultOrder('ipv4first');
Expand Down Expand Up @@ -114,6 +115,10 @@ async function getWindowAutoConnectPreferences(): Promise<AutoConnectPreferences
return await ipcRenderer?.call('compass:get-window-auto-connect-preferences');
}

async function checkSecretStorageIsAvailable(): Promise<boolean> {
return await ipcRenderer?.call('compass:check-secret-storage-is-available');
}

/**
* The top-level application singleton that brings everything together!
*/
Expand Down Expand Up @@ -212,6 +217,7 @@ const Application = View.extend({
(): Promise<AutoConnectPreferences> => {
return Promise.resolve(initialAutoConnectPreferences);
};
const isSecretStorageAvailable = await checkSecretStorageIsAvailable();
const connectionStorage = new CompassRendererConnectionStorage(
ipcRenderer,
getInitialAutoConnectPreferences
Expand Down Expand Up @@ -253,6 +259,15 @@ const Application = View.extend({
this.queryByHook('layout-container')
);

if (!isSecretStorageAvailable) {
openToast('secret-storage-not-available', {
variant: 'warning',
title:
'Compass cannot access credential storage. You can still connect, but please note that passwords will not be saved.',
});
track('Secret Storage Not Available');
}

document.querySelector('#loading-placeholder')?.remove();
},
updateAppVersion: async function () {
Expand Down
9 changes: 9 additions & 0 deletions packages/compass/src/main/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class CompassApplication {
safeStorage.setUsePlainTextEncryption(true);
}

// Accessing isEncryptionAvailable is not allowed when app is not ready on Windows
// https://github.com/electron/electron/issues/33640
await app.whenReady();
log.info(
mongoLogId(1_001_000_307),
'Application',
Expand Down Expand Up @@ -230,6 +233,12 @@ class CompassApplication {
debug('Did not agree to license, quitting app.');
app.quit();
},
'compass:check-secret-storage-is-available': async function () {
// Accessing isEncryptionAvailable is not allowed when app is not ready on Windows
// https://github.com/electron/electron/issues/33640
await app.whenReady();
return safeStorage.isEncryptionAvailable();
},
});

ipcMain?.handle('coverage', () => {
Expand Down

0 comments on commit 5d039d3

Please sign in to comment.