wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.28k stars 1.22k forks source link

v3 architecture API suggestions #2585

Closed mholt closed 1 year ago

mholt commented 1 year ago

Is your feature request related to a problem? Please describe.

I know there has been some talk about a server/hybrid mode (#1652 for example), and brainstorms about using Caddy as the server to benefit from its plugin ecosystem. After reviewing my (excellent) experience with Wails, I think I have some concrete suggestions/requests for Wails v3 related to how we expose functions/methods to the outside.

Currently, Wails exposes pure-Go functionality to the frontend (JS) through method bindings which it generates at compile-time. (In v3 this still applies, although I believe it is done with static analysis rather than runtime hacks.)

This is great but has some limitations/difficulties:

On that first point: I have an increasing need to be able to use the app in ways other than through the native webview frontend:

Describe the solution you'd like

I'd like to propose -- and discuss -- the possibility of approaching method bindings in a new way for v3:

With 3 ways to access the API instead of just 1, it will be possible to:

Describe alternatives you've considered

One last thought, regarding using Caddy as the HTTP server: I agree this is a cool idea, as it would allow the HTTP endpoint to be greatly extended so that Wails apps could become much more versatile in both production and end-user environments.

The way it usually works with Caddy is you'd embed your app into Caddy (not the other way around). This is because Caddy does all the configuration management for you, etc. So when you run the program, you actually run Caddy, which then runs apps. You can extend Caddy's CLI to add subcommands, and rename the main command from Caddy to something else if needed, but the basic core of Caddy would remain. I don't know if that's desirable, but that's usually how things work.

There is one possible alternative that I have not explored in depth yet, and that is using the caddyhttp package independently of using the entire Caddy core and CLI. You'd probably have to still use functions from the caddy/v2 package to load HTTP modules and such, but I don't know how much work would be needed to flip around the architecture so that you can truly embed Caddy into your app (instead embedding your app into Caddy). Anyone with a little time want to explore this?

Additional context

Thanks for Wails, it continues to be great. I hope some of these suggestions can make it in. I'm willing to help iron out technical details.

tmclane commented 1 year ago

Should this be moved to the actual discussion area?

mholt commented 1 year ago

Either way. I can never tell when to use issues or discussions. Typically in my own projects I use issues for development items.

leaanthony commented 1 year ago

GitHub for project management is.....fun....

leaanthony commented 1 year ago

@mholt - Been reviewing this. Thanks for the awesome suggestions. I'd love to use Caddy as the http server but I guess changing the architecture of it is far too hardcore 😱 Some of what's been suggested here has already been done in slightly different forms so none of the above is unfeasible. The CLI generation might be a stretch but having a generic CLI that loads up a config to build up the CLI options would be realistic. Thanks again! 👍