-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ElectronPlatform: Add support for a event index using Seshat. #11125
Changes from 2 commits
1dbdd0a
71023ae
94196eb
a6839af
c3c5756
449eca6
437c59f
e9352fc
b90a94b
7147af8
dd2c210
076bf6f
0813aff
b17a403
4a25252
73b302f
137bedb
2f2cbad
d0b5391
e96c44c
4c629e8
da4b403
b52141d
5f6636e
b1aff29
40f2648
f0fe968
5b8e918
1869350
b0783a8
f28f27a
e5956de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,17 @@ | |
"version": "1.4.2", | ||
"description": "A feature-rich client for Matrix.org", | ||
"author": "New Vector Ltd.", | ||
"scripts": { | ||
"build": "electron-build-env --electron 6.0.3 neon build seshat-node --release", | ||
"postinstall": "yarn build" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, so this is just to call the line above...? |
||
}, | ||
"dependencies": { | ||
"auto-launch": "^5.0.1", | ||
"electron-store": "^2.0.0", | ||
"electron-window-state": "^4.1.0", | ||
"minimist": "^1.2.0", | ||
"png-to-ico": "^1.0.2" | ||
"png-to-ico": "^1.0.2", | ||
"make-dir": "^3.0.0", | ||
"seshat-node": "^0.2.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be quite nice to have this renamed to something without the redundant |
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -39,6 +39,8 @@ const { migrateFromOldOrigin } = require('./originMigrator'); | |||||
|
||||||
const windowStateKeeper = require('electron-window-state'); | ||||||
const Store = require('electron-store'); | ||||||
const seshat = require('seshat-node'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As part of attempting to land this without a path to build it, let's test at runtime for its existence with a try / catch. |
||||||
const makeDir = require('make-dir'); | ||||||
|
||||||
if (argv["help"]) { | ||||||
console.log("Options:"); | ||||||
|
@@ -82,8 +84,12 @@ try { | |||||
// Could not load local config, this is expected in most cases. | ||||||
} | ||||||
|
||||||
|
||||||
jryans marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const eventStorePath = path.join(app.getPath('userData'), 'EventStore'); | ||||||
const store = new Store({ name: "electron-config" }); | ||||||
|
||||||
let eventIndex = null; | ||||||
|
||||||
let mainWindow = null; | ||||||
global.appQuitting = false; | ||||||
global.minimizeToTray = store.get('minimizeToTray', true); | ||||||
|
@@ -149,6 +155,17 @@ autoUpdater.on('update-downloaded', (ev, releaseNotes, releaseName, releaseDate, | |||||
ipcMain.on('ipcCall', async function(ev, payload) { | ||||||
if (!mainWindow) return; | ||||||
|
||||||
const send_error = (id, e) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use camel-case naming:
Suggested change
(We should have linting rules for this, but they seem not to have fired here... 🤔) |
||||||
const error = { | ||||||
message: e.message | ||||||
} | ||||||
|
||||||
mainWindow.webContents.send('ipcReply', { | ||||||
id:id, | ||||||
error: error | ||||||
}); | ||||||
} | ||||||
|
||||||
const args = payload.args || []; | ||||||
let ret; | ||||||
|
||||||
|
@@ -200,6 +217,105 @@ ipcMain.on('ipcCall', async function(ev, payload) { | |||||
case 'getConfig': | ||||||
ret = vectorConfig; | ||||||
break; | ||||||
|
||||||
case 'initEventIndex': | ||||||
if (args[0] && eventIndex === null) { | ||||||
let p = path.normalize(path.join(eventStorePath, args[0])); | ||||||
try { | ||||||
await makeDir(p); | ||||||
eventIndex = new seshat(p); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A common JS convention is for new-able things to start with a capital letter. I suppose we may not have a linting rule enforcing that at the moment, but I suggest changing the |
||||||
console.log("Initialized event store"); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'deleteEventIndex': | ||||||
await eventIndex.delete(); | ||||||
eventIndex = null; | ||||||
|
||||||
case 'isEventIndexEmpty': | ||||||
if (eventIndex === null) ret = true; | ||||||
else ret = await eventIndex.isEmpty(); | ||||||
break; | ||||||
|
||||||
case 'addEventToIndex': | ||||||
try { | ||||||
eventIndex.addEvent(args[0], args[1]); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'commitLiveEvents': | ||||||
try { | ||||||
ret = await eventIndex.commit(); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'searchEventIndex': | ||||||
try { | ||||||
ret = await eventIndex.search(args[0]); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'addHistoricEvents': | ||||||
if (eventIndex === null) ret = false; | ||||||
else { | ||||||
try { | ||||||
ret = await eventIndex.addHistoricEvents( | ||||||
args[0], args[1], args[2]); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'removeCrawlerCheckpoint': | ||||||
if (eventIndex === null) ret = false; | ||||||
else { | ||||||
try { | ||||||
ret = await eventIndex.removeCrawlerCheckpoint(args[0]); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'addCrawlerCheckpoint': | ||||||
if (eventIndex === null) ret = false; | ||||||
else { | ||||||
try { | ||||||
ret = await eventIndex.addCrawlerCheckpoint(args[0]); | ||||||
} catch (e) { | ||||||
send_error(payload.id, e); | ||||||
return; | ||||||
} | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'loadCheckpoints': | ||||||
if (eventIndex === null) ret = []; | ||||||
else { | ||||||
try { | ||||||
ret = await eventIndex.loadCheckpoints(); | ||||||
} catch (e) { | ||||||
ret = []; | ||||||
} | ||||||
} | ||||||
break; | ||||||
|
||||||
default: | ||||||
mainWindow.webContents.send('ipcReply', { | ||||||
id: payload.id, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really try hard to find a way to build that doesn't duplicate the Electron version in another place, as we'll surely forget to keep them synchronised. Maybe we need a wrapper script to pull it out of the main
package.json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing doesn't even work with the version passed as is. It seems to be only necessary if you need to rebuild seshat for some reason (e.g. if you're linking it from your dev folder) anyways.
Since we're adding run-time checks for seshat anyways it will be safe to remove it as well.