web-view icon indicating copy to clipboard operation
web-view copied to clipboard

Handle window buttons, esp. close.

Open simonbuchan opened this issue 5 years ago • 6 comments

It would be nice if you could intercept and handle the window buttons so you can do things like confirm, show save progress while closing, or save window position - this might be something I'm missing (something with onunload in the view?) in which case this might just be a doc bug.

If this isn't currently possible, the simplest option might be to forward them into the JS like host calls, otherwise it looks like it might be a API breaking change in WebViewBuilder to add more fields.

simonbuchan avatar May 19 '20 05:05 simonbuchan

The title bar is handled by the respective gui apis, winapi for windows, gtk for linux and i guess cocoa? for macOS.

You could in theory do one of two things,

  1. modify webview itself, in src/lib.rs
/// Gracefully exits the webview
    pub fn exit(&mut self) {
		\\ Use tinyfiledialog to execute a confirm window?
        unsafe { webview_exit(self.inner.unwrap()) }
    }
  1. Implement a custom title bar, using my fork of webview https://github.com/Blakeinstein/web-view it has exit, minimize, maximize function calls for both gtk and edge, and window drag for edge only, as of now.

Blakeinstein avatar Jul 05 '20 20:07 Blakeinstein

I'm running into the same issue with handling the window closing. Did you manage to handle this situation @simonbuchan? Did you modify webview exit function as suggested or something different?

randall-coding avatar Jul 10 '22 02:07 randall-coding

We switched to Tauri.

simonbuchan avatar Jul 10 '22 02:07 simonbuchan

How difficult was that switch? Would you recommend that? @simonbuchan

randall-coding avatar Jul 10 '22 02:07 randall-coding

Well it's a whole different thing, much more of an application framework controlling your build etc., but it's quite nicely designed.

If you just want a webview, the WRY crate that they spun out might be enough.

simonbuchan avatar Jul 10 '22 04:07 simonbuchan

How difficult was that switch? Would you recommend that? @simonbuchan

I know you didn't ask me. But I would still like to pitch in. Even I switched to Tauri, for what I was using this project for. And for me it was relatively straightforward. Infact I was able to additionally simplify my frontend pipeline, which I had to add inorder to fit in with the restrictions here.

Blakeinstein avatar Jul 10 '22 13:07 Blakeinstein