Git Product home page Git Product logo

v-webui's Introduction

Logo

V-WebUI

Use any web browser or WebView as GUI.
With V in the backend and modern web technologies in the frontend.

Screenshot

Features

  • Parent library written in pure C
  • Fully Independent (No need for any third-party runtimes)
  • Lightweight ~200 Kb & Small memory footprint
  • Fast binary communication protocol between WebUI and the browser (Instead of JSON)
  • Multi-platform & Multi-Browser
  • Using private profile for safety

Installation

v install https://github.com/webui-dev/v-webui

Usage

Note

It is recommended to use GCC or Clang to compile a WebUI V program. TCC is currently not working due to missing header files. E.g.:

v -cc gcc run .

Example

import vwebui as ui

const html = '<!DOCTYPE html>
<html>
   <head>
      <script src="webui.js"></script>
      <style>
         body {
            background: linear-gradient(to left, #36265a, #654da9);
            color: AliceBlue;
            font: 16px sans-serif;
            text-align: center;
            margin-top: 30px;
         }
      </style>
   </head>
   <body>
      <h1>Welcome to WebUI!</h1>
      <br>
      <input type="text" id="name" value="Neo">
      <button onclick="handleVResponse();">Call V</button>
      <br>
      <br>
      <div><samp id="greeting"></samp></div>
      <script>
         async function handleVResponse() {
            const inputName = document.getElementById("name");
            const result = await webui.greet(inputName.value);
            document.getElementById("greeting").innerHTML = result;
         }
      </script>
   </body>
</html>'

fn greet(e &ui.Event) string {
	name := e.get_arg[string]() or { panic('expected an argument') }
	println('${name} has reached the backend!')
	return 'Hello ${name} 🐇'
}

fn main() {
	mut w := ui.new_window()
	w.bind('greet', greet)
	w.show(html)!
	ui.wait()
}

Find more examples in the examples/ directory.

Documentation

Tip

Until our online documentation is finished, you can refer to src/lib.v or use V's built-in v doc -comments vwebui in the terminal for the latest overview of exported functions.

  • To use WebUI's debug build in your V-WebUI application, add the -d debug flag. E.g.:

    v -d webui_log run examples/call_v_from_js.v
  • Run tests locally:

    VJOBS=1 v -stats test tests/

Supported Web Browsers

Browser Windows macOS Linux
Mozilla Firefox ✔️ ✔️ ✔️
Google Chrome ✔️ ✔️ ✔️
Microsoft Edge ✔️ ✔️ ✔️
Chromium ✔️ ✔️ ✔️
Yandex ✔️ ✔️ ✔️
Brave ✔️ ✔️ ✔️
Vivaldi ✔️ ✔️ ✔️
Epic ✔️ ✔️ not available
Apple Safari not available coming soon not available
Opera coming soon coming soon coming soon

License

Licensed under the MIT License.

v-webui's People

Contributors

albertshown avatar csm-18 avatar hassandraga avatar malisipi avatar ttytm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

v-webui's Issues

fatal error: client/webui.h: No such file or directory

Hey there webui-dev!

I was trying to build the program by using this method:

git clone https://github.com/webui-dev/webui.git
cd webui/build/Linux/GCC
make
make debug

But it gave me this error:

image

Is there a way to solve this problem?

Thanks,
Mehmet Mert

V-WebUI | To-Do List

  • <Window>.is_shown function is missing d2df962
  • <Window>.set_multi_access function is missing d2df962
  • <Window>.run function is missing d2df962
  • <Window>.set_runtime is missing b6e63e9
  • Native <webui.Event> is not implemented #18
    • Listening all events "" is broken (Fix it) 8483f17
  • Support nested usage like javascript (my_window.bind(/*params*/).bind(/*params*/)) a118aed
  • <Window>.destroy() is missing 08691ca
  • Use enums instead of const variables (webui.browser_chrome -> .chrome) 482c4b9
  • Update serve_a_folder example C Version #20
    • webui.new_window_id is missing 4ac9f28
    • webui.get_window_id is missing (Native implementation required) 4ac9f28
  • Add real-world V example #19 1c2e300 d88798a
  • Update V documentation #16
  • get_new_window_id is missing webui-dev/webui@bc5e5b2 482c4b9

VWeb UI stops unexpectedly

I am on a Windows operating system. I have tried using vegalite.js in my application. Everything works fine, until I click Save as SVG menu item near the plots. VWeb UI will then close, and the application breaks.

First software using V-WebUI

I want to let you know that I'm working on a nice-looking text editor in C using WebUI. When it is ready, I will share it with you to be the first real software example using V-WebUI. You have to change the OpenFile dialogue from C to V only.

gcc issue

when i try to compile or run a examples by GCC i get that error
when i try to use Clang or TCC it give me a like that error also

.vmodules\vwebui\examples\text-editor>v -cc gcc run .
==================
C.....\.vmodules\vwebui\webui/webui-2.dll: file not recognized: file format not recognized
collect2.exe: error: ld returned 1 exit status
...
==================
(Use `v -cg` to print the entire error message)

builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Download pre-built instead of building from source

# v run %userprofile%/.vmodules/vwebui/setup.vsh 
Cloning...
git clone --depth 1 https://github.com/webui-dev/webui

Building...
"Build WebUI library (gcc release static)..." 
"Build WebUI library (gcc release dynamic)..." 
"Done."

I suggest downloading the pre-built binaries from upstream repo instead of building it from source. For two reasons:

  • The the pre-built binaries are built by CI, so it's trusted and safe
  • The user must have GCC, and we know that TCC has issues

TLS Support

The next version 2.4.0 will include TLS Encryption between the GUI and the V application. This will make compiling WebUI from the source more challenging for the V wrapper.

I suggest making the V wrapper using the static pre-built library which makes things very easy as it does not need to compile WebUI from the source.

Compile time error

I tried to compile text-editor.v, but got a compile time error.

v text-editor.v

==================
.../v_0/text-editor.3556100730162151181.tmp.c:13996: warning: assignment discards qualifiers from pointer target type
.../v_0/text-editor.3556100730162151181.tmp.c:14074: error: macro 'ADDR' used with too many args
...
==================
(Use `v -cg` to print the entire error message)
builder error:
==================
C error. This should never happen.
This is a compiler bug, please report it using `v bug file.v`.
https://github.com/vlang/v/issues/new/choose
You can also use #help on Discord: https://discord.gg/vlang

text-editor.3556100730162151181.tmp.c:13996:

malisipi__vwebui__WebuiResponseData malisipi__vwebui__CEvent_get(malisipi__vwebui__CEvent* e) {
	---> string str = char_vstring(webui_get_string(e));
	malisipi__vwebui__WebuiResponseData _t1 = ((malisipi__vwebui__WebuiResponseData){._v_string = str,._v_int = string_int(str),._v_bool = string__eq(str, _SLIT("true")),});
	return _t1;
}

Info:
The warning is because char_vstring() expect a char* but webui_get_string() is a const char*

text-editor.3556100730162151181.tmp.c:14074:

VV_LOCAL_SYMBOL void malisipi__vwebui__native_event_handler(malisipi__vwebui__CEvent* e) {
	{ // Unsafe block
		u64 bind_id = webui_interface_get_bind_id(e->window, e->element);
		---> malisipi__vwebui__Response resp = ((malisipi__vwebui__Response (*) (malisipi__vwebui__Event* e))(*(voidptr*)map_get(ADDR(map, ADDR(map, function_list), &(u64[]){webui_interface_get_window_id(e->window)}, &(voidptr[]){ new_map_noscan_key(sizeof(u64), sizeof(malisipi__vwebui__Function), &map_hash_int_8, &map_eq_int_8, &map_clone_int_8, &map_free_nop) })))), &(u64[]){bind_id}, &(voidptr[]){ 0 })))(ADDR(malisipi__vwebui__Event/*qq*/, ((malisipi__vwebui__Event){.window = e->window,.event_type = ((malisipi__vwebui__event)(e->event_type)),.element = char_vstring(e->element),.data = malisipi__vwebui__CEvent_get(e),.event_number = e->event_number,})));
		malisipi__vwebui__CEvent_return(e, resp);
	}
}

Debug info:
a value of type "malisipi__vwebui__Response (*)(malisipi__vwebui__Event *e)" cannot be used to initialize an entity of type "malisipi__vwebui__Response"

vwebui does not re-use open browser (MacOS)

Running any example once a browser is open does not seem to work. Existing tab remains the same/blank, a new tab is not opened. The only thing that happens is for the browser to be brought into focus.

V full version: V 0.3.4 b9a8a21.134e781
OS: macos, macOS, 13.3.1, 22E261
Processor: 12 cpus, 64bit, little endian, Apple M2 Max

→ v show vwebui
Name: vwebui
Version: 2.2.0
Description: Use any web browser as GUI, with V in the backend and HTML5 in the frontend, all in a lightweight portable lib.
Homepage: https://github.com/malisipi/vwebui
Author: Mehmet Ali
License: GPL-3.0

WebUI v2.3.0

WebUI v2.3.0 is pushed to the main branch.
webui-dev/webui@ca7b4f5

The only difference from v2.2.0 on the side of the wrappers is:

  • The window object changed from void* (pointer) to a simple size_t (integer)
  • License changed from GPLv2 to 'MIT'

WebUI v2.2.0

WebUI v2.2.0 is ready for release.

Big changes:

  1. Now, webui.h it's become more straightforward and smaller and optimized for wrapper creation
  2. webui_show() will replace webui_open() and webui_new_server()
  3. webui_window_t struct becomes a simple void*
  4. To solves the complexity of memory leaks when executing JS, now, the wrapper creates a local buffer and passes it to webui_script()
  5. All core internal functions are removed from webui.h

To create the new V wrapper, run c2v webui.h. And remove all other functions from the old version v2.1.1.
After that, we will start creating more big software in V as an example (Text editor, Media Player, Database viewer...), which will be very exciting to explore and learn new things!.

If you have any questions, please don't hesitate to ask me here.
Thank you for maintaining the WebUI V wrapper. I appreciate it 👍

Installation Issue

# v install https://github.com/webui-dev/v-webui

Installing module "webui-dev\v-webui" from "https://github.com/webui-dev/v-webui" to "C:\Users\HD\.vmodules\webui_dev\v_webui" ...
Relocating module from "webui-dev\v-webui" to "vwebui" ( "C:\Users\HD\.vmodules\vwebui" ) ...
Module "webui-dev\v-webui" relocated to "vwebui" successfully.

# v run $HOME/.vmodules/vwebui/setup.vsh

v expects that `$HOME/.vmodules/vwebui/setup.vsh` exists, but it does not

I guess, in Windows it should be %userprofile% instead of $HOME.

# v run %userprofile%/.vmodules/vwebui/setup.vsh

Cloning...
git clone --depth 1 https://github.com/webui-dev/webui

Building...
"Build WebUI library (gcc release static)..." 
"Build WebUI library (gcc release dynamic)..." 
"Done."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.