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

after setpublic ,browser does not work the same as it's autorun‘s window #38

Open
GodGavin opened this issue Jun 29, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@GodGavin
Copy link

Description

this is the picture
webuibug

Expected Behavior

it should display the same

Reproduction Steps

No response

Error Logs

No response

Possible Solution

No response

Version

v2.4.3-0.20240615225151-fa682814ad2c

Environment Details (OS name, version, etc.)

windows10 64bit
@GodGavin GodGavin added the bug Something isn't working label Jun 29, 2024
@GodGavin
Copy link
Author

// main.go
package main

import (
	"fmt"
	ui "github.com/webui-dev/go-webui/v2"
)

func greet(e ui.Event) string {
	name, _ := ui.GetArg[string](e)
	fmt.Printf("%s has reached the backend!\n", name)
	jsResp := fmt.Sprintf("Hello %s 🐇", name)
	return jsResp
	//return "Hello World111"
}

func main() {
	// Create a window.
	w := ui.NewWindow()
	//webui_set_public(public_window, true)
	w.SetPublic("public_window", true)
	// Bind a Go function.
	ui.Bind(w, "greet", greet)
	// Show frontend.
	w.Show("index.html")
	// Wait until all windows get closed.
	ui.Wait()
}

@hassandraga
Copy link
Member

Thank you @GodGavin for reporting this, we will check this issue as soon as mainstream (core) v2.5 gets released.

@ttytm
Copy link
Member

ttytm commented Jun 29, 2024

Thanks for providing the repro. To narrow it down we should check if this issue is limited to the Go binding.

I have check with C and can reproduce it. Mirroring the repro to C and trying to call the bound function from the public win in the browser it is a:

ReferenceError: webui is not defined
#include "webui.h"

void greet(webui_event_t* e) {
	const char* str_arg = webui_get_string(e);

	printf("%s has reached the backend\n", str_arg);

	webui_return_string(e, "some str return");
}

int main() {
	size_t w = webui_new_window();

	webui_bind(w, "greet", greet);
	webui_set_public(w, true);
	webui_show(w, "index.html");
	webui_wait();
	webui_clean();

	return 0;
}

Screenshot_20240629_221032

@hassandraga
Copy link
Member

after setpublic ,browser does not work the same

The setpublic means the link can be accessed from any machine on the network, but one client only. Currently we are working on a heavy core changes to allow multi-clients.

Poll: webui-dev/webui#434

ReferenceError: webui is not defined

document.addEventListener('DOMContentLoaded', function() {
    // DOM is loaded. Check if `webui` object is available
    if (typeof webui !== 'undefined') {
        // Set events callback
        webui.setEventCallback((e) => {
            if (e == webui.event.CONNECTED) {
                // Connection to the backend is established
                // Now it's safe to call a backend function

                myBackendFunction();
            }
        });
    }
});

More inf: https://webui.me/docs/2.5/#/?id=javascript-call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants