Migrate to SQLCipher for messages/cache

Quite a few other fixes, including:
  - Sending to contact with no avatar yet (not synced from mobile)
  - Left pane doesn't update quickly or at all on new message
  - Left pane doesn't show sent or error status

Also:
 - Contributing.md: Ensure set of linux dev dependencies is complete
This commit is contained in:
Scott Nonnenberg 2018-07-26 18:13:56 -07:00
parent fc461c82ce
commit 3105b77475
29 changed files with 2006 additions and 716 deletions

55
app/sql_channel.js Normal file
View file

@ -0,0 +1,55 @@
const electron = require('electron');
const sql = require('./sql');
const { ipcMain } = electron;
module.exports = {
initialize,
};
let initialized = false;
const SQL_CHANNEL_KEY = 'sql-channel';
const ERASE_SQL_KEY = 'erase-sql-key';
function initialize({ userConfig }) {
if (initialized) {
throw new Error('sqlChannels: already initialized!');
}
initialized = true;
if (!userConfig) {
throw new Error('initialize: userConfig is required!');
}
ipcMain.on(SQL_CHANNEL_KEY, async (event, jobId, callName, ...args) => {
try {
const fn = sql[callName];
if (!fn) {
throw new Error(
`sql channel: ${callName} is not an available function`
);
}
const result = await fn(...args);
event.sender.send(`${SQL_CHANNEL_KEY}-done`, jobId, null, result);
} catch (error) {
const errorForDisplay = error && error.stack ? error.stack : error;
console.log(
`sql channel error with call ${callName}: ${errorForDisplay}`
);
event.sender.send(`${SQL_CHANNEL_KEY}-done`, jobId, errorForDisplay);
}
});
ipcMain.on(ERASE_SQL_KEY, async event => {
try {
userConfig.set('key', null);
event.sender.send(`${ERASE_SQL_KEY}-done`);
} catch (error) {
const errorForDisplay = error && error.stack ? error.stack : error;
console.log(`sql-erase error: ${errorForDisplay}`);
event.sender.send(`${ERASE_SQL_KEY}-done`, error);
}
});
}