webview-bun icon indicating copy to clipboard operation
webview-bun copied to clipboard

Support non-blocking render

Open exoRift opened this issue 6 months ago • 20 comments

Introduced by https://github.com/webview/webview/pull/1308

I doubt this will be merged while the PR is open and pointing to Complexicon's fork, but I needed this so at least this PR being open can point people in the right direction

Edit:

I switched the webview submodule to my own instead of Complexicon's to add some MacOS functionality discussed here

(closes #35)

exoRift avatar Jun 19 '25 23:06 exoRift

Hi,

This looks awesome! I’d love to try it out, but I noticed there aren’t any Windows binaries. Can you add those to the repository, or do I need to build them myself?

Thanks!

CoreBytee avatar Jun 23 '25 22:06 CoreBytee

Hi,

This looks awesome! I’d love to try it out, but I noticed there aren’t any Windows binaries. Can you add those to the repository, or do I need to build them myself?

Thanks!

It seems the platform is determined by the platform being built on (i.e. no cross-compilation) and I don't have access to my other machines at the moment.

For the moment, it seems you'll have to build it yourself; my apologies

If you know how to cross-platform compile, I'd be happy to update it

exoRift avatar Jun 23 '25 22:06 exoRift

One possible solution is to use GitHub Actions. It looks like there's already a PR addressing this (#29). Maybe you could take a look at that?

CoreBytee avatar Jun 23 '25 23:06 CoreBytee

One possible solution is to use GitHub Actions. It looks like there's already a PR addressing this (#29). Maybe you could take a look at that?

I've implemented actions to build the binaries. I'm concerned, however, because the sizes for two of the files are smaller. Please test them to make sure everything is working correctly.

Please ignore all the force pushes. That was me amending the commit that adds the GitHub Action to get it to work

exoRift avatar Jun 27 '25 05:06 exoRift

It looks like the DLLs are working since a window is created, and the onClose callback is functioning as well. Is there anything else that needs to be tested?

CoreBytee avatar Jun 27 '25 10:06 CoreBytee

It looks like the DLLs are working since a window is created, and the onClose callback is functioning as well. Is there anything else that needs to be tested?

I guess not. Cool

exoRift avatar Jun 27 '25 15:06 exoRift

Hi, I found that when you use multiple windows, the close event is only fired after all windows are closed. Could you maybe look for a fix? Thanks in advance!

CoreBytee avatar Jul 25 '25 14:07 CoreBytee

At some point I switched it from using EventEmitter to just taking a callback on runNonBlocking. Try pulling the latest commit and see if that works

exoRift avatar Jul 25 '25 15:07 exoRift

I'm already on the latest commit 😅. I'm on Windows, if that changes the issue in any way...

CoreBytee avatar Jul 25 '25 15:07 CoreBytee

Could you send me some example code to try out so I have more clarity into the issue?

exoRift avatar Jul 25 '25 15:07 exoRift

This is my index.ts:

import { Webview } from "webview-bun"

const webview1 = new Webview()
const webview2 = new Webview()

webview1.runNonBlocking(() => console.log("webview1 closed"))
webview2.runNonBlocking(() => console.log("webview2 closed"))

And this is my package.json (with the latest git commit hash):

{
    "scripts": {
        "dev": "bun run --watch index.ts"
    },
    "dependencies": {
		"webview-bun": "exoRift/webview-bun#b805351391e58d0cce4c3b15d92cae192b6b1dda"
    }
}

Hope this helps!

CoreBytee avatar Jul 25 '25 15:07 CoreBytee

It was an upstream issue with Complexicon's implementation. I've fixed it in my fork.

Once the build action finishes (https://github.com/exoRift/webview-bun/actions/runs/16531577944), it will be available at the latest commit on main. Let me know if you run into any more issues!

exoRift avatar Jul 25 '25 21:07 exoRift

Now both windows close if the user closes one of them...

CoreBytee avatar Jul 27 '25 08:07 CoreBytee

Yep, you're right. I didn't observe this on Mac but I tested it on Windows and it happened. I'll take a look

exoRift avatar Jul 27 '25 13:07 exoRift

Should be fixed now! Tested it myself (I hope I didn't screw up 😅)

https://github.com/exoRift/webview-bun/actions/runs/16553419049

exoRift avatar Jul 27 '25 16:07 exoRift

It works🎉, Thank you very much!

CoreBytee avatar Jul 27 '25 17:07 CoreBytee

Would be better if it were:

webview.runSync();
await webview.run();

to be more in line with the rest of bun...

Also remove the changes to webview prebuilt binaries and your own repo (fine for your setup, not fine for everyone else). Let's work on publishing changes upstream to webview. 😃

gabereiser avatar Aug 07 '25 00:08 gabereiser

Originally, the PR pointed to Complexicon's fork which added the ability to manually pump the event loop (allowing for this implementation) which is still a fork.

My fork adds some missing functionalities to Mac as well as corrects some issues present in Complexicon's fork/the original webview implementation for Windows.

Thus, my fork is needed for stability.

It couldn't be merged anyway because it's always pointing to a fork of webview regardless.

I also don't really have any intention of this actually getting merged into webview-bun but it's moreso open so people can easily find my fork to use for their own purposes. I've also implemented Github action workflows to auto-build the binaries which is technically its own scope and not suitable for this PR

In summary, it doesn't really matter since this isn't really open to be merged anyway

exoRift avatar Aug 07 '25 02:08 exoRift

If you don't plan on merging, could you maybe take a look at publishing this as a standalone NPM package?

CoreBytee avatar Aug 25 '25 23:08 CoreBytee

Is there any need for that? I think that may be a bit disrespectful to the original package creators, not to mention it would need to be maintained and kept up-to-date.

This package is specifically for Bun which natively supports repo dependencies so what ease of use would it introduce?

exoRift avatar Aug 26 '25 12:08 exoRift