[英]Resize Wry WebView from window.resizeTo
I have a web application currently running in Electron and would like to move it to Wry/Tauri for opening speed.我有一个 web 应用程序当前在 Electron 中运行,并且想将其移动到 Wry/Tauri 以提高打开速度。 The application uses
window.resizeTo
to change the window size in real time.该应用程序使用
window.resizeTo
实时更改 window 大小。 I have tried using the same command with Wry/Tauri, but it does not work.我曾尝试对 Wry/Tauri 使用相同的命令,但它不起作用。 Is it possible to intercept such a call and act correctly?
是否有可能拦截这样的电话并正确行动?
Maybe will be useful for someone other.也许对其他人有用。 I figured out that it is possible to use
webview.evaluate_script('<js code>')
to inject some code in opened page.我发现可以使用
webview.evaluate_script('<js code>')
在打开的页面中注入一些代码。 Thus it's possible to change the default window.resizeTo
functionallity to something I need to, for example for my needs I can do:因此,可以将默认的
window.resizeTo
功能更改为我需要的功能,例如,为了我的需要,我可以这样做:
window.resizeTo = (w, h) => window.ipc.postMessage(`resize,${w},${h}`);
On the WRY
side I can use with_ipc_handler
to resize the window as requested.在
WRY
方面,我可以使用with_ipc_handler
根据要求调整 window 的大小。
WebViewBuilder::new()
.with_ipc_handler(|win, msg| {
let (w, h) = parse_resize_msg(&msg).unwrap();
win.set_inner_size(LogicalSize::new(w, h)).unwrap();
})
.build()?;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.