This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Facilitate running custom javascript on the main JS process#63
Open
Naatan wants to merge 2 commits intoasticode:masterfrom
Open
Facilitate running custom javascript on the main JS process#63Naatan wants to merge 2 commits intoasticode:masterfrom
Naatan wants to merge 2 commits intoasticode:masterfrom
Conversation
This was referenced Sep 10, 2022
asticode
suggested changes
Sep 23, 2022
| appCmdQuit: "app.cmd.quit", | ||
| appEventReady: "app.event.ready", | ||
| appEventSecondInstance: "app.event.second.instance", | ||
| appExecuteJavaScript: "app.execute.javascript", |
Owner
There was a problem hiding this comment.
Could you rename that to appCmdExecuteJavascript: "app.cmd.execute.javascript"?
| appEventReady: "app.event.ready", | ||
| appEventSecondInstance: "app.event.second.instance", | ||
| appExecuteJavaScript: "app.execute.javascript", | ||
| appExecuteJavaScriptCallback: "app.execute.javascript.callback", |
Owner
There was a problem hiding this comment.
Could you rename that to appEventExecutedJavascript: "app.event.executed.javascript"?
| }; | ||
| try { | ||
| client.write(json.targetID, consts.eventNames.appExecuteJavaScriptCallback, { | ||
| reply: await evalAsync(json.code, json) |
Owner
There was a problem hiding this comment.
Could you rename reply to success?
| (async function () { | ||
| let evalAsync = (ev, json) => { | ||
| return new Promise((resolve, reject) => { | ||
| eval(ev); |
Owner
There was a problem hiding this comment.
eval code will have access to resolve and reject here ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm preparing another PR for go-astilectron that interfaces with this.
I figured this works well with astilectron's approach of forward compatibility. ie. electron can release new versions but astilectron doesn't necessarily need an update to support them. Unfortunately, this can leave you stranded if you want to user features in the new electron version.
Obviously this has all the established security caveats of using eval. That's a consideration for the developer who utilizes the code though, IMO.
Note that the code is written so that you have to call
resolve()andreject()with the result. This is to facilitate asynchronous JavaScript code.Very new to this codebase so please feel free to point out better ways of addressing this.