From 0081a4167c0ee4c508b15c68181e73164e404686 Mon Sep 17 00:00:00 2001 From: Fabio Di Stasio Date: Mon, 8 Mar 2021 17:35:43 +0100 Subject: [PATCH] refactor: moving from keytar to local storage due issues on Linux --- src/main/index.js | 13 +++++++++---- src/main/ipc-handlers/application.js | 9 ++++++++- src/renderer/store/modules/connections.store.js | 8 +++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 79c34579..de6b8714 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -96,11 +96,16 @@ else { // create main BrowserWindow when electron is ready app.on('ready', async () => { - let key = await keytar.getPassword('antares', 'user'); + try { + let key = await keytar.getPassword('antares', 'user'); - if (!key) { - key = crypto.randomBytes(16).toString('hex'); - keytar.setPassword('antares', 'user', key); + if (!key) { + key = crypto.randomBytes(16).toString('hex'); + keytar.setPassword('antares', 'user', key); + } + } + catch (err) { + console.log(err); } mainWindow = createMainWindow(); diff --git a/src/main/ipc-handlers/application.js b/src/main/ipc-handlers/application.js index efc36e9b..c4130020 100644 --- a/src/main/ipc-handlers/application.js +++ b/src/main/ipc-handlers/application.js @@ -7,7 +7,14 @@ export default () => { }); ipcMain.on('get-key', async event => { - const key = await keytar.getPassword('antares', 'user'); + let key = false; + + try { + key = await keytar.getPassword('antares', 'user'); + } + catch (err) { + console.log(err); + } event.returnValue = key; }); }; diff --git a/src/renderer/store/modules/connections.store.js b/src/renderer/store/modules/connections.store.js index 5f7a56f0..7e01d881 100644 --- a/src/renderer/store/modules/connections.store.js +++ b/src/renderer/store/modules/connections.store.js @@ -1,7 +1,13 @@ 'use strict'; import Store from 'electron-store'; +import crypto from 'crypto'; import Application from '../../ipc-api/Application'; -const key = Application.getKey(); +const key = Application.getKey() || localStorage.getItem('key'); + +if (!key) + localStorage.setItem('key', crypto.randomBytes(16).toString('hex')); +else + localStorage.setItem('key', key); const persistentStore = new Store({ name: 'connections',