Prevent desktop reloads at the wry level (#4422)

* Prevent desktop reloads at the wry level

* add a test

* only allow one navigation
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-07-15 14:26:52 -07:00
1 parent 393246b923
commit 0d2e1f4051
7 files changed
+124 -20

No files matched your search

+7 -2
View File
@@ -21,6 +21,7 @@ use dioxus_history::{History, MemoryHistory};
use dioxus_hooks::to_owned;
use dioxus_html::{HasFileData, HtmlEvent, PlatformEventData};
use futures_util::{pin_mut, FutureExt};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::{cell::OnceCell, time::Duration};
use std::{rc::Rc, task::Waker};
@@ -300,6 +301,8 @@ impl WebviewInstance {
}
};
let page_loaded = AtomicBool::new(false);
let mut webview = WebViewBuilder::new_with_web_context(&mut web_context)
.with_bounds(wry::Rect {
position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
@@ -311,11 +314,13 @@ impl WebviewInstance {
.with_transparent(cfg.window.window.transparent)
.with_url("dioxus://index.html/")
.with_ipc_handler(ipc_handler)
.with_navigation_handler(|var| {
.with_navigation_handler(move |var| {
// We don't want to allow any navigation
// We only want to serve the index file and assets
if var.starts_with("dioxus://") || var.starts_with("http://dioxus.") {
true
// After the page has loaded once, don't allow any more navigation
let page_loaded = page_loaded.swap(true, std::sync::atomic::Ordering::SeqCst);
!page_loaded
} else {
if var.starts_with("http://")
|| var.starts_with("https://")