mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
electron-main: Rework the event index initialization and deletion.
This commit is contained in:
parent
7147af8f80
commit
dd2c210cfb
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user