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#382
Open
Naatan wants to merge 1 commit intoasticode:masterfrom
Open
Facilitate running custom javascript on the main JS process#382Naatan wants to merge 1 commit intoasticode:masterfrom
Naatan wants to merge 1 commit intoasticode:masterfrom
Conversation
asticode
suggested changes
Sep 23, 2022
| EventNameAppErrorAccept = "app.error.accept" | ||
| EventNameAppEventReady = "app.event.ready" | ||
| EventNameAppEventSecondInstance = "app.event.second.instance" | ||
| EventNameAppExecuteJavaScript = "app.execute.javascript" |
Owner
There was a problem hiding this comment.
Could you rename those based on what I've suggested in the JS PR ?
| return newNotification(a.worker.Context(), o, a.supported != nil && a.supported.Notification != nil && *a.supported.Notification, a.dispatcher, a.identifier, a.writer) | ||
| } | ||
|
|
||
| type eventProxy struct { |
Owner
There was a problem hiding this comment.
you don't need this new struct, *Astilectron already has an On() method
| dispatcher: a.dispatcher, | ||
| logger: a.l, | ||
| } | ||
| event, err := synchronousEvent( |
Owner
There was a problem hiding this comment.
You can use this instead:
synchronousEvent(a.worker.Context(), a, a.writer, Event{Name: EventNameAppCmdExecuteJavaScript, TargetID: targetIDApp, Code: code}, EventNameAppEventExecutedJavaScript)| Displays *EventDisplays `json:"displays,omitempty"` | ||
| Enable *bool `json:"enable,omitempty"` | ||
| Error *string `json:"error,omitempty"` | ||
| FilePath string `json:"filePath,omitempty"` |
Owner
There was a problem hiding this comment.
I'd rather you create this new field instead of using Reply:
Success json.RawMessage `json:"success"`| if event.Error != nil && *event.Error != "" { | ||
| return fmt.Errorf("ExecuteJavascript failed: %s", *event.Error) | ||
| } | ||
| if err := json.Unmarshal([]byte(event.Reply), response); err != nil { |
Owner
There was a problem hiding this comment.
- Could you wrap this in
if response != nil && len(event.Success) > 0because some developers may not need a response here - If you use the
Successfield as I mentioned, you can usejson.Unmarshal(event.Success, response)instead
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.
Note this PR is dependent on asticode/astilectron#63
The rationale is explained in the PR above.
The
eventProxyfeels very awkward, I'm probably doing more than I need to. Happy to receive some pointers on how to improve this code.