Skip to content
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

feat(client/windows): introduce go plugin to call fetchResource as a library #2263

Merged
merged 18 commits into from
Nov 19, 2024

Conversation

jyyi1
Copy link
Contributor

@jyyi1 jyyi1 commented Nov 7, 2024

This PR introduces a new mechanism for Electron's renderer process to directly call Go functions.

It shows how this works by migrating the fetchResource function as an example.

@github-actions github-actions bot added size/M and removed size/XS labels Nov 8, 2024
@github-actions github-actions bot added size/L and removed size/M labels Nov 13, 2024
@jyyi1 jyyi1 marked this pull request as ready for review November 14, 2024 19:52
@jyyi1 jyyi1 requested review from a team as code owners November 14, 2024 19:52
client/electron/app_paths.ts Outdated Show resolved Hide resolved
client/go/outline/electron/go_plugin.go Outdated Show resolved Hide resolved
@jyyi1 jyyi1 changed the title feat(client/windows): call fetchResource as a library feat(client/windows): introduce go plugin to call fetchResource as a library Nov 14, 2024
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Strong change. I love it!

#include <stdlib.h> // for C.free

// InvokeGoAPIResult is a struct used to pass result from Go to TypeScript boundary.
typedef struct InvokeGoAPIResult_t
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can define this struct in Go instead and only have the include here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean define it as the struct as:

type InvokeGoAPIResult struct {
  Output, ErrorJson *C.char
}

I'm afraid this is not supported by CGo:

Not all Go types can be mapped to C types in a useful way. Go struct types are not supported; use a C struct type. Go array types are not supported; use a C pointer.

@jyyi1 jyyi1 merged commit 769fc25 into master Nov 19, 2024
23 checks passed
@jyyi1 jyyi1 deleted the junyi/electron-library-call branch November 19, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants