From edb28ee8d86b0bcdf7a8185b656a970fc526974c Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Tue, 20 Jan 2026 14:11:40 +0530 Subject: [PATCH 1/4] single web-view --- kulfi/src/tauri.rs | 109 ++----------- kulfi/static/browser.html | 289 +++++++++++++++++++++++++++++++++++ kulfi/static/init_view.html | 22 --- kulfi/static/navigation.html | 150 ------------------ 4 files changed, 300 insertions(+), 270 deletions(-) create mode 100644 kulfi/static/browser.html delete mode 100644 kulfi/static/init_view.html delete mode 100644 kulfi/static/navigation.html diff --git a/kulfi/src/tauri.rs b/kulfi/src/tauri.rs index 134c679..d8d24a9 100644 --- a/kulfi/src/tauri.rs +++ b/kulfi/src/tauri.rs @@ -1,82 +1,20 @@ -const BROWSER_WEBVIEW: &str = "browser_view"; -const NAV_WEBVIEW: &str = "navigation"; - #[allow(unexpected_cfgs)] #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn ui() -> eyre::Result<()> { - const BROWSER_INIT_SCRIPT: &str = r#" - console.log("Browser Init Script Loaded"); - - const listen = window.__TAURI__.event.listen; - const emitTo = window.__TAURI__.event.emitTo; - - // https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event - window.addEventListener("pageshow", () => { - console.info("Page show event triggered"); - emitUrlChange(window.location.href); - }); - - listen("nav-back", () => { - console.log("going back one page"); - history.back(); - }); - - listen("nav-forward", () => { - console.log("going forward one page"); - history.forward(); - }); - - - /** - * @param {string} url - */ - function emitUrlChange(url) { - console.log("Current URL:", url); - if (url.startsWith("tauri://")) { - console.info("URL starts with tauri://, ignoring emitUrlChange"); - return; - } - - emitTo("navigation", "url-changed", url). - then(() => { - console.log("URL change emitted to navigation webview"); - }) - .catch(err => { - console.error("Failed to emit URL change:", err); - }); - } - "#; - tauri::Builder::default() .plugin(tauri_plugin_opener::init()) .setup(|app| { - use tauri::{LogicalPosition, LogicalSize, WebviewUrl}; - - let width = 800.0; - let height = 600.0; - let bottom_height = 45.0; - let top_height = height - bottom_height; - - let window = tauri::window::WindowBuilder::new(app, "main") - .title("Kulfi") - .center() - .inner_size(width, height) - .build()?; - - let _browser_window = window.add_child( - tauri::webview::WebviewBuilder::new(BROWSER_WEBVIEW, tauri::WebviewUrl::App("init_view.html".into())) - .auto_resize() - .initialization_script(BROWSER_INIT_SCRIPT), - LogicalPosition::new(0., 0.), - LogicalSize::new(width, top_height), // TODO: - )?; - - let _webview2 = window.add_child( - tauri::webview::WebviewBuilder::new(NAV_WEBVIEW, WebviewUrl::App("navigation.html".into())) - .auto_resize(), - LogicalPosition::new(0., top_height), - LogicalSize::new(width, bottom_height), // TODO: - )?; + use tauri::WebviewUrl; + + let _window = tauri::WebviewWindowBuilder::new( + app, + "main", + WebviewUrl::App("browser.html".into()), + ) + .title("Kulfi") + .center() + .inner_size(800.0, 600.0) + .build()?; Ok(()) }) @@ -159,37 +97,12 @@ pub fn ui() -> eyre::Result<()> { } }); }) - .invoke_handler(tauri::generate_handler![open_url]) .run(tauri::generate_context!()) .expect("error while running tauri application"); Ok(()) } -/// Called from `navigation.html` frontend when the user enters a kulfi url and hits the enter key -#[tauri::command] -async fn open_url(app_handle: tauri::AppHandle, url: String) -> Result<(), OpenUrlError> { - use tauri::Manager; - - tracing::info!("{:?}", app_handle.webviews().get("browser_view")); - - app_handle - .get_webview(BROWSER_WEBVIEW) - .ok_or(OpenUrlError::NoWebview)? - .navigate(url.parse().map_err(|_| OpenUrlError::InvalidUrl)?) - .map_err(|_| OpenUrlError::Navigation) -} - -#[derive(Debug, thiserror::Error, serde::Serialize)] -enum OpenUrlError { - #[error("No webview found to open the URL")] - NoWebview, - #[error("Invalid URL provided")] - InvalidUrl, - #[error("Failed to navigate to the URL")] - Navigation, -} - fn kulfi_uri_to_path_and_id52(uri: &hyper::Uri) -> (String, String) { // TODO: handle the following assert as error let uri_str = uri.to_string(); diff --git a/kulfi/static/browser.html b/kulfi/static/browser.html new file mode 100644 index 0000000..7105ffd --- /dev/null +++ b/kulfi/static/browser.html @@ -0,0 +1,289 @@ + + + + + + Kulfi Browser + + + +
+ + +
+

Kulfi Browser

+

Enter a URL above and press Enter

+
+ + +
+ + + + diff --git a/kulfi/static/init_view.html b/kulfi/static/init_view.html deleted file mode 100644 index c1c3563..0000000 --- a/kulfi/static/init_view.html +++ /dev/null @@ -1,22 +0,0 @@ - - -
-

Enter the URL below and hit Enter.

-
diff --git a/kulfi/static/navigation.html b/kulfi/static/navigation.html deleted file mode 100644 index aab1a0f..0000000 --- a/kulfi/static/navigation.html +++ /dev/null @@ -1,150 +0,0 @@ - - -
- - - - - -
- - From 9ba41bdb2b5a7c841c53fc6d57cb0c4de00c2e5b Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Tue, 20 Jan 2026 14:14:51 +0530 Subject: [PATCH 2/4] status bar --- kulfi/static/browser.html | 55 +++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/kulfi/static/browser.html b/kulfi/static/browser.html index 7105ffd..a188318 100644 --- a/kulfi/static/browser.html +++ b/kulfi/static/browser.html @@ -86,12 +86,16 @@ font-weight: 500; } - #loading { + #status { font-size: 12px; color: #666; min-width: 60px; } + #status.error { + color: #d32f2f; + } + #content { flex: 1; width: 100%; @@ -139,7 +143,7 @@ - +
@@ -152,14 +156,22 @@

Kulfi Browser