webview / webview_deno

🌐 Deno bindings for webview, a tiny library for creating web-based desktop GUIs
https://deno.land/x/webview
MIT License
1.44k stars 75 forks source link

How to run in background? #151

Open rj-hwang opened 1 year ago

JOTSR commented 1 year ago

You want to run webiview without freezing the main script ? As I know, there is no simple way to run in background since webview handle the client event loop. You can run webview in a worker or a sub process and send data to client via websocket but you don't have direct access of the server part. I'm working on a pull request to solve that via an async api but this project seems to be slowing down.

DNAScanner commented 7 months ago

If what you want is what JOTSR described, you can achieve this by doing an non-awaited asynchronous function as I did.

import {Webview, SizeHint} from "jsr:@webview/webview";
import {loadImage} from "https://deno.land/x/canvas@v1.4.1/mod.ts";

(async () => {
    const image = await loadImage("E:/AniWorld.png");

    const webview = new Webview(false, {height: image.height(), width: image.width(), hint: SizeHint.FIXED});

    // Load image file at "E:\AniWorld.png"
    webview.navigate("E:/AniWorld.png");
    webview.run();
})();

const urls = [
    "https://aniworld.to/anime/stream/golden-time",
];

console.log(urls.join("\n"));

The main part is

(async () => { /* Code here */ })()