diff --git a/packages/accounts/package.json b/packages/accounts/package.json index 7b3752cfb..c27eb59c2 100644 --- a/packages/accounts/package.json +++ b/packages/accounts/package.json @@ -6,7 +6,8 @@ "build": "yarn lint && tsc" }, "dependencies": { - "@ente/shared": "*" + "@ente/shared": "*", + "is-electron": "^2.2.2" }, "devDependencies": { "@ente/eslint-config": "*", diff --git a/packages/accounts/pages/credentials.tsx b/packages/accounts/pages/credentials.tsx index 8558fcb02..d7d40f942 100644 --- a/packages/accounts/pages/credentials.tsx +++ b/packages/accounts/pages/credentials.tsx @@ -37,8 +37,7 @@ import FormPaper from '@ente/shared/components/Form/FormPaper'; import FormPaperTitle from '@ente/shared/components/Form/FormPaper/Title'; import FormPaperFooter from '@ente/shared/components/Form/FormPaper/Footer'; import LinkButton from '@ente/shared/components/LinkButton'; -// import isElectron from 'is-electron'; -// import safeStorageService from 'services/electron/safeStorage'; +import isElectron from 'is-electron'; import { VerticallyCentered } from '@ente/shared/components/Container'; import EnteSpinner from '@ente/shared/components/EnteSpinner'; import VerifyMasterPasswordForm, { @@ -53,6 +52,7 @@ import InMemoryStore, { MS_KEYS } from '@ente/shared/storage/InMemoryStore'; import { PageProps } from '@ente/shared/apps/types'; import { APPS } from '@ente/shared/apps/constants'; import { logError } from '@ente/shared/sentry'; +import ElectronAPIs from '@ente/shared/electron'; export default function Credentials({ appContext, @@ -78,17 +78,17 @@ export default function Credentials({ return; } setUser(user); - const key = getKey(SESSION_KEYS.ENCRYPTION_KEY); - // if (!key && isElectron()) { - // key = await safeStorageService.getEncryptionKey(); - // if (key) { - // await saveKeyInSessionStore( - // SESSION_KEYS.ENCRYPTION_KEY, - // key, - // true - // ); - // } - // } + let key = getKey(SESSION_KEYS.ENCRYPTION_KEY); + if (!key && isElectron()) { + key = await ElectronAPIs.getEncryptionKey(); + if (key) { + await saveKeyInSessionStore( + SESSION_KEYS.ENCRYPTION_KEY, + key, + true + ); + } + } if (key) { router.push(PAGES.GALLERY); return; diff --git a/packages/accounts/services/user.ts b/packages/accounts/services/user.ts index 59ae89df2..32664b19f 100644 --- a/packages/accounts/services/user.ts +++ b/packages/accounts/services/user.ts @@ -6,6 +6,8 @@ import { clearData } from '@ente/shared/storage/localStorage'; import { logError } from '@ente/shared/sentry'; import { clearFiles } from '@ente/shared/storage/localForage/helpers'; import router from 'next/router'; +import ElectronAPIs from '@ente/shared/electron'; +import isElectron from 'is-electron'; export const logoutUser = async () => { try { @@ -41,13 +43,13 @@ export const logoutUser = async () => { } catch (e) { logError(e, 'clearFiles failed'); } - // if (isElectron()) { - // try { - // safeStorageService.clearElectronStore(); - // } catch (e) { - // logError(e, 'clearElectronStore failed'); - // } - // } + if (isElectron()) { + try { + ElectronAPIs.clearElectronStore(); + } catch (e) { + logError(e, 'clearElectronStore failed'); + } + } // try { // eventBus.emit(Events.LOGOUT); // } catch (e) { diff --git a/packages/shared/crypto/helpers.ts b/packages/shared/crypto/helpers.ts index 899742490..3a01023ce 100644 --- a/packages/shared/crypto/helpers.ts +++ b/packages/shared/crypto/helpers.ts @@ -6,6 +6,8 @@ import { getActualKey } from '@ente/shared/user'; import { KeyAttributes } from '@ente/shared/user/types'; import { setRecoveryKey } from '@ente/accounts/api/user'; import { logError } from '@ente/shared/sentry'; +import isElectron from 'is-electron'; +import ElectronAPIs from '../electron'; const LOGIN_SUB_KEY_LENGTH = 32; const LOGIN_SUB_KEY_ID = 1; @@ -103,13 +105,13 @@ export const saveKeyInSessionStore = async ( ); setKey(keyType, sessionKeyAttributes); console.log('fromDesktop', fromDesktop); - // if ( - // isElectron() && - // !fromDesktop && - // keyType === SESSION_KEYS.ENCRYPTION_KEY - // ) { - // safeStorageService.setEncryptionKey(key); - // } + if ( + isElectron() && + !fromDesktop && + keyType === SESSION_KEYS.ENCRYPTION_KEY + ) { + ElectronAPIs.setEncryptionKey(key); + } }; export async function encryptWithRecoveryKey(key: string) {