electron-main: Rework the event index initialization and deletion.

pull/11125/head
Damir Jelić 2019-11-14 16:14:48 +01:00
parent 7147af8f80
commit dd2c210cfb
3 changed files with 24 additions and 7 deletions

View File

@ -15,7 +15,6 @@
"electron-window-state": "^4.1.0", "electron-window-state": "^4.1.0",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"png-to-ico": "^1.0.2", "png-to-ico": "^1.0.2",
"make-dir": "^3.0.0",
"matrix-seshat": "^0.3.0" "matrix-seshat": "^0.3.0"
} }
} }

View File

@ -40,12 +40,13 @@ const { migrateFromOldOrigin } = require('./originMigrator');
const windowStateKeeper = require('electron-window-state'); const windowStateKeeper = require('electron-window-state');
const Store = require('electron-store'); const Store = require('electron-store');
const fs = require('fs');
const afs = fs.promises;
let Seshat = null; let Seshat = null;
let makeDir = null;
try { try {
Seshat = require('matrix-seshat'); Seshat = require('matrix-seshat');
makeDir = require('make-dir');
} catch (e) { } catch (e) {
} }
@ -255,9 +256,8 @@ ipcMain.on('seshat', async function(ev, payload) {
if (eventIndex === null) { if (eventIndex === null) {
let p = path.normalize(eventStorePath); let p = path.normalize(eventStorePath);
try { try {
await makeDir(p); await afs.mkdir(p, {recursive: true});
eventIndex = new Seshat(p, {passphrase: "DEFAULT_PASSPHRASE"}); eventIndex = new Seshat(p, {passphrase: "DEFAULT_PASSPHRASE"});
console.log("Initialized event store");
} catch (e) { } catch (e) {
sendError(payload.id, e); sendError(payload.id, e);
return; return;
@ -265,11 +265,25 @@ ipcMain.on('seshat', async function(ev, payload) {
} }
break; break;
case 'deleteEventIndex': case 'closeEventIndex':
await eventIndex.delete();
eventIndex = null; eventIndex = null;
break; break;
case 'deleteEventIndex':
const deleteFolderRecursive = async(p) => {
for (let entry of await afs.readdir(p)) {
const curPath = path.join(p, entry);
await afs.unlink(curPath);
}
}
try {
await deleteFolderRecursive(path.normalize(eventStorePath));
} catch (e) {
}
break;
case 'isEventIndexEmpty': case 'isEventIndexEmpty':
if (eventIndex === null) ret = true; if (eventIndex === null) ret = true;
else ret = await eventIndex.isEmpty(); else ret = await eventIndex.isEmpty();

View File

@ -149,6 +149,10 @@ class SeshatIndexerManager extends BaseEventIndexManager {
return this._ipcCall('loadCheckpoints'); return this._ipcCall('loadCheckpoints');
} }
async closeEventIndex(): Promise<> {
return this._ipcCall('closeEventIndex');
}
async deleteEventIndex(): Promise<> { async deleteEventIndex(): Promise<> {
return this._ipcCall('deleteEventIndex'); return this._ipcCall('deleteEventIndex');
} }