diff --git a/src/electron-main.ts b/src/electron-main.ts index db6cd0af..13303ca4 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -464,8 +464,18 @@ app.on("ready", async () => { console.log("No update_base_url is defined: auto update is disabled"); } - console.debug("Ensuring storage is ready"); - await store.safeStorageReady(); + // Set up i18n before loading storage as we need translations for dialogs + global.appLocalization = new AppLocalization({ + components: [(): void => tray.initApplicationMenu(), (): void => Menu.setApplicationMenu(buildMenuTemplate())], + }); + + try { + console.debug("Ensuring storage is ready"); + await store.safeStorageReady(); + } catch (e) { + console.error(e); + app.exit(1); + } // Load the previous window state with fallback to defaults const mainWindowState = windowStateKeeper({ @@ -561,10 +571,6 @@ app.on("ready", async () => { webContentsHandler(global.mainWindow.webContents); - global.appLocalization = new AppLocalization({ - components: [(): void => tray.initApplicationMenu(), (): void => Menu.setApplicationMenu(buildMenuTemplate())], - }); - session.defaultSession.setDisplayMediaRequestHandler((_, callback) => { global.mainWindow?.webContents.send("openDesktopCapturerSourcePicker"); setDisplayMediaCallback(callback); diff --git a/src/store.ts b/src/store.ts index c390a46f..1691ab3b 100644 --- a/src/store.ts +++ b/src/store.ts @@ -177,7 +177,7 @@ class Store extends ElectronStore<{ if (data) { for (const key in data) { const plaintext = data[key]; - await this.setSecret(key, plaintext); + await this.setSecretSafeStorage(key, plaintext); } } } else if (safeStorageBackend in safeStorageBackendMap) { @@ -239,7 +239,7 @@ class Store extends ElectronStore<{ ]; for (const cred of credentials) { console.info("Store migration: writing", cred); - await this.setSecret(cred.account, cred.password); + await this.setSecretSafeStorage(cred.account, cred.password); console.info("Store migration: deleting", cred); await this.deleteSecretKeytar(LEGACY_KEYTAR_SERVICE, cred.account); } @@ -290,9 +290,13 @@ class Store extends ElectronStore<{ throw new Error("safeStorage is not available"); } + await this.setSecretSafeStorage(key, secret); + await keytar.setPassword(KEYTAR_SERVICE, key, secret); + } + + private async setSecretSafeStorage(key: string, secret: string): Promise { const encryptedValue = safeStorage.encryptString(secret); this.set(this.getSecretStorageKey(key), encryptedValue.toString("base64")); - await keytar.setPassword(KEYTAR_SERVICE, key, secret); } /**