@@ -40,6 +40,16 @@ const { migrateFromOldOrigin } = require('./originMigrator');
4040const windowStateKeeper = require ( 'electron-window-state' ) ;
4141const Store = require ( 'electron-store' ) ;
4242
43+ const fs = require ( 'fs' ) ;
44+ const afs = fs . promises ;
45+
46+ let Seshat = null ;
47+
48+ try {
49+ Seshat = require ( 'matrix-seshat' ) ;
50+ } catch ( e ) {
51+ }
52+
4353if ( argv [ "help" ] ) {
4454 console . log ( "Options:" ) ;
4555 console . log ( " --profile-dir {path}: Path to where to store the profile." ) ;
@@ -94,8 +104,11 @@ try {
94104 // Could not load local config, this is expected in most cases.
95105}
96106
107+ const eventStorePath = path . join ( app . getPath ( 'userData' ) , 'EventStore' ) ;
97108const store = new Store ( { name : "electron-config" } ) ;
98109
110+ let eventIndex = null ;
111+
99112let mainWindow = null ;
100113global . appQuitting = false ;
101114
@@ -225,6 +238,7 @@ ipcMain.on('ipcCall', async function(ev, payload) {
225238 case 'getConfig' :
226239 ret = vectorConfig ;
227240 break ;
241+
228242 default :
229243 mainWindow . webContents . send ( 'ipcReply' , {
230244 id : payload . id ,
@@ -239,6 +253,154 @@ ipcMain.on('ipcCall', async function(ev, payload) {
239253 } ) ;
240254} ) ;
241255
256+ ipcMain . on ( 'seshat' , async function ( ev , payload ) {
257+ if ( ! mainWindow ) return ;
258+
259+ const sendError = ( id , e ) => {
260+ const error = {
261+ message : e . message
262+ }
263+
264+ mainWindow . webContents . send ( 'seshatReply' , {
265+ id :id ,
266+ error : error
267+ } ) ;
268+ }
269+
270+ const args = payload . args || [ ] ;
271+ let ret ;
272+
273+ switch ( payload . name ) {
274+ case 'supportsEventIndexing' :
275+ if ( Seshat === null ) ret = false ;
276+ else ret = true ;
277+ break ;
278+
279+ case 'initEventIndex' :
280+ if ( eventIndex === null ) {
281+ try {
282+ await afs . mkdir ( eventStorePath , { recursive : true } ) ;
283+ eventIndex = new Seshat ( eventStorePath , { passphrase : "DEFAULT_PASSPHRASE" } ) ;
284+ } catch ( e ) {
285+ sendError ( payload . id , e ) ;
286+ return ;
287+ }
288+ }
289+ break ;
290+
291+ case 'closeEventIndex' :
292+ eventIndex = null ;
293+ break ;
294+
295+ case 'deleteEventIndex' :
296+ const deleteFolderRecursive = async ( p ) => {
297+ for ( let entry of await afs . readdir ( p ) ) {
298+ const curPath = path . join ( p , entry ) ;
299+ await afs . unlink ( curPath ) ;
300+ }
301+ }
302+
303+ try {
304+ await deleteFolderRecursive ( eventStorePath ) ;
305+ } catch ( e ) {
306+ }
307+
308+ break ;
309+
310+ case 'isEventIndexEmpty' :
311+ if ( eventIndex === null ) ret = true ;
312+ else ret = await eventIndex . isEmpty ( ) ;
313+ break ;
314+
315+ case 'addEventToIndex' :
316+ try {
317+ eventIndex . addEvent ( args [ 0 ] , args [ 1 ] ) ;
318+ } catch ( e ) {
319+ sendError ( payload . id , e ) ;
320+ return ;
321+ }
322+ break ;
323+
324+ case 'commitLiveEvents' :
325+ try {
326+ ret = await eventIndex . commit ( ) ;
327+ } catch ( e ) {
328+ sendError ( payload . id , e ) ;
329+ return ;
330+ }
331+ break ;
332+
333+ case 'searchEventIndex' :
334+ try {
335+ ret = await eventIndex . search ( args [ 0 ] ) ;
336+ } catch ( e ) {
337+ sendError ( payload . id , e ) ;
338+ return ;
339+ }
340+ break ;
341+
342+ case 'addHistoricEvents' :
343+ if ( eventIndex === null ) ret = false ;
344+ else {
345+ try {
346+ ret = await eventIndex . addHistoricEvents (
347+ args [ 0 ] , args [ 1 ] , args [ 2 ] ) ;
348+ } catch ( e ) {
349+ sendError ( payload . id , e ) ;
350+ return ;
351+ }
352+ }
353+ break ;
354+
355+ case 'removeCrawlerCheckpoint' :
356+ if ( eventIndex === null ) ret = false ;
357+ else {
358+ try {
359+ ret = await eventIndex . removeCrawlerCheckpoint ( args [ 0 ] ) ;
360+ } catch ( e ) {
361+ sendError ( payload . id , e ) ;
362+ return ;
363+ }
364+ }
365+ break ;
366+
367+ case 'addCrawlerCheckpoint' :
368+ if ( eventIndex === null ) ret = false ;
369+ else {
370+ try {
371+ ret = await eventIndex . addCrawlerCheckpoint ( args [ 0 ] ) ;
372+ } catch ( e ) {
373+ sendError ( payload . id , e ) ;
374+ return ;
375+ }
376+ }
377+ break ;
378+
379+ case 'loadCheckpoints' :
380+ if ( eventIndex === null ) ret = [ ] ;
381+ else {
382+ try {
383+ ret = await eventIndex . loadCheckpoints ( ) ;
384+ } catch ( e ) {
385+ ret = [ ] ;
386+ }
387+ }
388+ break ;
389+
390+ default :
391+ mainWindow . webContents . send ( 'seshatReply' , {
392+ id : payload . id ,
393+ error : "Unknown IPC Call: " + payload . name ,
394+ } ) ;
395+ return ;
396+ }
397+
398+ mainWindow . webContents . send ( 'seshatReply' , {
399+ id : payload . id ,
400+ reply : ret ,
401+ } ) ;
402+ } ) ;
403+
242404app . commandLine . appendSwitch ( '--enable-usermedia-screen-capturing' ) ;
243405
244406const gotLock = app . requestSingleInstanceLock ( ) ;
0 commit comments