webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.91k stars 167 forks source link

refactor, fix and add feat to js bridge #132

Closed JOTSR closed 1 year ago

JOTSR commented 1 year ago

Summary

Encapse private methods and attributes inside a class to securise access with private fields. Support JSON handling. Fix logic and types errors. Simplify code...

Motivation

One of the challenges of this project is the JS bridge, which is difficult to maintain for contributors and hard to discover for new users. A possible improvement is to rewrite the bridge using typescript, which has several benefits. First, it improves discoverability, as typescript can help with code completion and documentation. Second, it improves interoperability by providing type hints and safeguards. Third, as typescript is used in source code it don't affect the final execution (only JS is embedded). Moreover, for internal use, typescript can prevent errors (many references and typos in the original JS bridge have been caught by typescript) and improve project structure by enforcing types and modules.

Main changes

AlbertShown commented 1 year ago

This is really a big improvement to the project. Thank you @JOTSR 👍 We should add instruction in the readme to explain that to build WebUI we need to install esbuild /xxd

JOTSR commented 1 year ago

Ok I will add it later. I'm currently dealing on resolving issue #98 by adding add set/get_title, set/get_size, set_position (get_position is a future work as no common browser API allow this).

petabyt commented 1 year ago

Ok I will add it later. I'm currently dealing on resolving issue #98 by adding add set/get_title, set/get_size, set_position (get_position is a future work as no common browser API allow this).

https://github.com/webui-dev/webui/pull/133 should make that easier

AlbertShown commented 1 year ago

adding add set/get_title, set/get_size, set_position

I don't think we should add title to WebUI because the end-user will use HTML <title></title> in all scenarios.

The APIs get_title, get_position and get_size can be added as TypeScript functions in the WebUI-Bridge, then we make a new C core function to call those JavaScript functions. But I vote not to do it. The end-user can write his custom JavaScript function if needed. But feel free to add them if you like too 👍

JOTSR commented 1 year ago

@AlbertShown As title, position and size is a part of the "external" aspect of the UI, proposing an turnkey solution is less boilerplate to implement for the end user. API to manage the rendered UI are out of scope obviously.

https://github.com/webui-dev/webui/assets/58234376/9df066fa-c13b-4429-830a-9e629bdb9eaa