zig-webui icon indicating copy to clipboard operation
zig-webui copied to clipboard

macOS: Keyboard events aren't forwarded to the WebView

Open thundron opened this issue 1 year ago • 1 comments

On macOS, when loading a website, the input is not forwarded to the window but remains in the terminal. Code to reproduce:

const std = @import("std");
const webui = @import("webui");

pub fn main() !void {
    // Create new windows
    var nwin = webui.newWindow();

    // Show a new WebView window
    _ = nwin.showWv("https://www.google.com");

    // Wait until all windows get closed
    webui.wait();

    // Free all memory resources (Optional)
    webui.clean();
}

Moreover, the instance eventually quits by itself after some ~10 seconds

thundron avatar Aug 16 '24 14:08 thundron

the instance eventually quits by itself after some ~10 seconds

Yes, it will auto close because https://www.google.com does not have webui.js. You need to add it to your HTML UI to create a connection between the window and your backend.

AlbertShown avatar Aug 16 '24 16:08 AlbertShown

So can we close this issue?

jinzhongjia avatar Aug 17 '24 11:08 jinzhongjia

I think it should be possible to open the webview and interact with the keyboard even without connection to the backend. I don't need it for what I'm trying to do so it shouldn't be a requirement in my opinion; I just need to open the webview and interact with it normally

thundron avatar Aug 17 '24 13:08 thundron

In order for webui to correctly control the webview, it needs to inject webui.js, otherwise the webview will be out of control. This is why webui will forcefully kill the webview when it cannot connect to the webview.

jinzhongjia avatar Aug 17 '24 14:08 jinzhongjia

But I don't need webui to control the webview, just spawn it and eventually kill it (if needed) which as far as I understand, it can already do even without injecting webui. If it's against your intended design, that's another story

thundron avatar Aug 17 '24 20:08 thundron

This cannot be solved by the wrapper. Maybe you can make a request to the webui main repository.

jinzhongjia avatar Aug 18 '24 12:08 jinzhongjia

Gotcha, thanks!

thundron avatar Aug 18 '24 13:08 thundron

If it's against your intended design, that's another story

I guess yes, webui is designed to connect UI to backend using webui.js, but if you need to interact with window itself using webview APIs then you should either manually modify the webui.c, or use webview for that, then later add webui to connect to UI if needed.

AlbertShown avatar Aug 20 '24 16:08 AlbertShown