webui-dev / deno-webui

Use any web browser as GUI, with Deno in the backend and HTML5 in the frontend.
https://webui.me/
MIT License
220 stars 12 forks source link

example not works: WebUI not exported #7

Open 7flash opened 1 year ago

7flash commented 1 year ago

1) create main.ts

import { WebUI } from "https://deno.land/x/webui/mod.ts";

const myWindow = new WebUI();
myWindow .show("<html>Hello World</html>");
await WebUI.wait();

2) run

deno run --allow-all main.ts

3) shows an error

error: Uncaught SyntaxError: The requested module 'https://deno.land/x/webui/mod.ts' does not provide an export named 'WebUI'
import { WebUI } from "https://deno.land/x/webui/mod.ts";
7flash commented 1 year ago

Solution:

> git clone git@github.com:webui-dev/deno-webui.git
import { WebUI } from "./deno-webui/mod.ts";

const myWindow = new WebUI();
myWindow .show("<html>Hello World</html>");
await WebUI.wait();
deno run --unstable --allow-all main.ts
AlbertShown commented 1 year ago

Thank you @7flash, That's right, in the meanwhile @JOTSR is working on this to be fixed in the main repo.

JOTSR commented 1 year ago

Since the current doc is tracking the next comming release there are breaking changes on the exports. For production use keep using the stable latest tag on deno.land. If you want to test the new comming features and API import directly from the main branch of the repo (pin a commit to reduce breaking changes).

AlbertShown commented 1 year ago

The new stable version will be available soon after we voted to remove the webui.js from the source.

7flash commented 1 year ago

The new stable version will be available soon after we voted to remove the webui.js from the source.

Not sure what it means, but I have a relevant question,

Is it recommended to implement backend with bind/call between frontend in terms of performance or rather perhaps better spawn my own http server in same process?

AlbertShown commented 1 year ago

Sorry, I meant that the current repo has an unfinished implementation. You can use the latest stable version here. Or clone the current branch, and apply the patch mentioned by @JOTSR.

About the HTTP Server, usually, webui will take care of it for you. You will receive events (clicks, calls) quickly. Many people have already used webui 2.0.3 in a production environment, and it's working fine, with no performance issues.

7flash commented 1 year ago

Sorry, I meant that the current repo has an unfinished implementation. You can use the latest stable version here. Or clone the current branch, and apply the patch mentioned by @JOTSR.

About the HTTP Server, usually, webui will take care of it for you. You will receive events (clicks, calls) quickly. Many people have already used webui 2.0.3 in a production environment, and it's working fine, with no performance issues.

Another issue, I'm not sure if it's supposed to support async handlers of events, and in that case I should open another issue with more detailed description, but what happens that it works with one or two invocations, and then throws a fatal error:

malloc(): unaligned fastbin chunk detected

I don't know if it can be easily fixed to support async handlers and in meantime I will have to stick with following approach, where I have to manually register callback on frontend, then call backend function which will run callback passing result.

// frontend
window.cb = (result) => {}
window.webui.call('first_function', {});

// backend
myWindow.bind('first_function', async event => {
  const result = await secondFunction();
  myWindow.run(`window.cb(${result})`);
})
AlbertShown commented 1 year ago

Do you mean this is causes issues:

webui_fn('first_function').then((response) => {
     window.cb(response);
});