Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Conversation

@Naatan
Copy link
Contributor

@Naatan Naatan commented Sep 10, 2022

Note this PR is dependent on asticode/astilectron#63

The rationale is explained in the PR above.

The eventProxy feels very awkward, I'm probably doing more than I need to. Happy to receive some pointers on how to improve this code.

EventNameAppErrorAccept = "app.error.accept"
EventNameAppEventReady = "app.event.ready"
EventNameAppEventSecondInstance = "app.event.second.instance"
EventNameAppExecuteJavaScript = "app.execute.javascript"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this new struct, *Astilectron already has an On() method

dispatcher: a.dispatcher,
logger: a.l,
}
event, err := synchronousEvent(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Could you wrap this in if response != nil && len(event.Success) > 0 because some developers may not need a response here
  2. If you use the Success field as I mentioned, you can use json.Unmarshal(event.Success, response) instead

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants