From 4e92f273cc6b253caa118fba7002fcdaca75ae6f Mon Sep 17 00:00:00 2001 From: AAA <35992542+TNTcraftHIM@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:48:58 -0500 Subject: [PATCH] fix(app): keep saved sites reachable from the native caption --- docs/standards/visual-language.md | 6 +- prototype/channel-server/src/app_windows.rs | 146 ++++++++++++------ .../channel-server/src/app_windows/caption.rs | 1 + .../components/living/AppConnectionButton.tsx | 2 +- .../components/living/LauncherWorkspace.tsx | 2 +- src/client/ui/native-window-caption.html | 4 +- src/client/ui/window-controls.json | 8 +- 7 files changed, 112 insertions(+), 57 deletions(-) diff --git a/docs/standards/visual-language.md b/docs/standards/visual-language.md index a5930dacc..830362537 100644 --- a/docs/standards/visual-language.md +++ b/docs/standards/visual-language.md @@ -186,9 +186,9 @@ frame. This presentation choice does not remove meaningful content cards or create separate page implementations. Keep one visible application identity. Shared modal materials must remain consistent across the content and any separately trusted window controls, whose commands stay with the native host. -Native caption controls only minimize, maximize/restore and close the window. -Site navigation and management remain in the shared application interface; -opening management preserves the current page until an explicit site switch. +The main Windows caption provides Saved sites alongside minimize, +maximize/restore and close. Its Saved sites action opens the shared site +management interface and preserves the current page until an explicit switch. Saved-site rows navigate, Add opens creation, and Manage edits an existing site or its App access. Language, theme and help share the same More options menu in the launcher and room workspace, identified by the ellipsis rather than a settings icon. diff --git a/prototype/channel-server/src/app_windows.rs b/prototype/channel-server/src/app_windows.rs index ed3a8759a..abbdd104d 100644 --- a/prototype/channel-server/src/app_windows.rs +++ b/prototype/channel-server/src/app_windows.rs @@ -156,6 +156,7 @@ enum ServiceEvent { PagePopup(uuid::Uuid), Ready { entry: String, + launcher: url::Url, }, Navigate(String), ContentLoading, @@ -173,6 +174,7 @@ enum ServiceEvent { Fullscreen(bool), Caption(WindowId, WindowAction), CaptionReady(WindowId), + OpenBookmarks(WindowId), PopupTitle(WindowId, String), Content(ContentMessage), } @@ -245,6 +247,7 @@ impl Core { runtime.block_on(async { let signal = piik_channel_native::shutdown_signal()?; let listener = app::listen(port).await?; + let launcher = url::Url::parse(&format!("http://{}/client", listener.local_addr()?))?; let (ready, entry) = oneshot::channel(); let service = app::serve(listener, config, async { tokio::select! { _ = stopped => {}, _ = signal => {} } @@ -253,7 +256,7 @@ impl Core { tokio::select! { result = &mut service => result, entry = entry => { - if let Ok(entry) = entry { let _ = events.send_event(ServiceEvent::Ready { entry }); } + if let Ok(entry) = entry { let _ = events.send_event(ServiceEvent::Ready { entry, launcher }); } service.await }, } @@ -300,11 +303,61 @@ struct PopupWindow { window: Rc, } impl PopupWindow { - fn follow_main_theme(&self, launcher: Option<&url::Origin>, theme: &Theme, language: Language) { + fn new( + window: Rc, + environment: webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Environment, + events: EventLoopProxy, + pending: PendingPermissions, + controls: &WindowControls, + ) -> Result { + let id = window.id(); + let presentation = events.clone(); + let title_events = events.clone(); + let load_events = events.clone(); + let webview = WebViewBuilder::new() + .with_environment(environment) + .with_initialization_script(SYSTEM_PRESENTATION) + .with_initialization_script(download::SCRIPT) + .with_document_title_changed_handler(move |title| { let _ = title_events.send_event(ServiceEvent::PopupTitle(id, title)); }) + .with_on_page_load_handler(move |event, _| { + if matches!(event, PageLoadEvent::Finished) { + let _ = load_events.send_event(ServiceEvent::PopupLoaded(id)); + } + }) + .with_ipc_handler(move |request| { + if let Ok(message) = serde_json::from_str::(request.body()) { + let _ = presentation.send_event(ServiceEvent::PopupPresentation(id, message)); + } else if let Ok(ContentMessage::Appearance { theme, language, material }) = serde_json::from_str(request.body()) { + let _ = presentation.send_event(ServiceEvent::PopupAppearance(id, theme, language, material)); + } + }) + .build_as_child(window.as_ref())?; + let download_events = events.clone(); + download::install(&webview, Some(Rc::new(move |url, status| { + let _ = download_events.send_event(ServiceEvent::Download(id, url, status)); + })), None)?; + let caption = caption::Caption::new(&window, &webview, events.clone(), controls, true)?; + caption.title("Piik"); + caption.layout(&window, &webview, controls); + permissions(&webview, id, pending, events.clone())?; + let closed = events.clone(); + // The WebView closes its container; this adapter retires the top-level window. + unsafe { + webview.webview().add_WindowCloseRequested( + &WindowCloseRequestedEventHandler::create(Box::new(move |_, _| { + let _ = closed.send_event(ServiceEvent::PopupClosed(id)); + Ok(()) + })), &mut Default::default(), + )?; + } + Ok(Self { caption, content: webview, window }) + } + + fn follow_main_theme(&self, launcher: Option<&url::Url>, theme: &Theme, language: Language) { let Some(page) = self.content.url().ok().and_then(|url| url::Url::parse(&url).ok()) else { return; }; - if launcher.is_some_and(|origin| *origin == page.origin()) + if launcher.is_some_and(|url| url.origin() == page.origin()) && page.path() == "/client" && page.query_pairs().any(|(key, _)| key == "bookmarks") { @@ -390,48 +443,10 @@ impl MainWindow { let create = || -> Result { let window = Rc::new(popup::builder(window_builder()?, features.size, features.position, &popup_controls) .with_decorations(false).with_undecorated_shadow(true).build(&popup_target)?); - let id = window.id(); - let presentation = popup_events.clone(); - let title_events = popup_events.clone(); - let load_events = popup_events.clone(); - let webview = WebViewBuilder::new() - .with_environment(features.opener.environment) - .with_initialization_script(SYSTEM_PRESENTATION) - .with_initialization_script(download::SCRIPT) - .with_document_title_changed_handler(move |title| { let _ = title_events.send_event(ServiceEvent::PopupTitle(id, title)); }) - .with_on_page_load_handler(move |event, _| { - if matches!(event, PageLoadEvent::Finished) { - let _ = load_events.send_event(ServiceEvent::PopupLoaded(id)); - } - }) - .with_ipc_handler(move |request| { - if let Ok(message) = serde_json::from_str::(request.body()) { - let _ = presentation.send_event(ServiceEvent::PopupPresentation(id, message)); - } else if let Ok(ContentMessage::Appearance { theme, language, material }) = serde_json::from_str(request.body()) { - let _ = presentation.send_event(ServiceEvent::PopupAppearance(id, theme, language, material)); - } - }) - .build_as_child(window.as_ref())?; - let download_events = popup_events.clone(); - download::install(&webview, Some(Rc::new(move |url, status| { - let _ = download_events.send_event(ServiceEvent::Download(id, url, status)); - })), None)?; - let caption = caption::Caption::new(&window, &webview, popup_events.clone(), &popup_controls, true)?; - caption.title("Piik"); - caption.layout(&window, &webview, &popup_controls); - permissions(&webview, id, popup_pending.clone(), popup_events.clone())?; - let closed = popup_events.clone(); - // The WebView closes its container; this adapter retires the top-level window. - unsafe { - webview.webview().add_WindowCloseRequested( - &WindowCloseRequestedEventHandler::create(Box::new(move |_, _| { - let _ = closed.send_event(ServiceEvent::PopupClosed(id)); - Ok(()) - })), &mut Default::default(), - )?; - } - let response = NewWindowResponse::Create { webview: webview.webview() }; - popups.borrow_mut().push(PopupWindow { caption, content: webview, window }); + let popup = PopupWindow::new(window, features.opener.environment, popup_events.clone(), + popup_pending.clone(), &popup_controls)?; + let response = NewWindowResponse::Create { webview: popup.content.webview() }; + popups.borrow_mut().push(popup); Ok(response) }; create().unwrap_or_else(|error| { @@ -581,7 +596,8 @@ pub fn run(mut config: Config, port: Option) -> Result<()> { let mut result = Ok(()); let mut language = Language::En; let mut theme = Theme::Light; - let mut launcher_origin = None; + let mut launcher_url: Option = None; + let mut bookmarks_window = None; let mut prompt: Option = None; let mut slot = None; let mut minimum_scale = window.as_ref().map(|main| main.window.scale_factor()); @@ -626,7 +642,7 @@ pub fn run(mut config: Config, port: Option) -> Result<()> { } pages.appearance(&theme, language); for child in popups.borrow().iter() { - child.follow_main_theme(launcher_origin.as_ref(), &theme, language); + child.follow_main_theme(launcher_url.as_ref(), &theme, language); } if let Some(prompt) = &prompt { prompt.update_appearance(&theme, language); @@ -751,6 +767,36 @@ pub fn run(mut config: Config, port: Option) -> Result<()> { } } } + Event::UserEvent(ServiceEvent::OpenBookmarks(id)) => { + if let (Some(main), Some(launcher)) = (window.as_ref().filter(|main| main.window.id() == id), launcher_url.as_ref()) { + let result = (|| -> Result<()> { + let mut launcher = launcher.clone(); + if let Some(open) = popups.borrow().iter().find(|popup| Some(popup.window.id()) == bookmarks_window) { + open.window.set_focus(); + return Ok(()); + } + launcher.query_pairs_mut().append_pair("bookmarks", "1").append_pair("piik-preferences", "copy"); + let mut fragment = url::form_urlencoded::Serializer::new(String::new()); + fragment.append_pair("piik-client", "1").append_pair("piik-lang", language.code()); + if let Some(site) = main.content.url().ok().and_then(|url| url::Url::parse(&url).ok()) + .filter(|url| matches!(url.scheme(), "http" | "https") && url.origin() != launcher.origin()) + { + fragment.append_pair("site", &site.origin().ascii_serialization()); + } + launcher.set_fragment(Some(&fragment.finish())); + let window = Rc::new(popup::builder(window_builder()?, None, None, &controls) + .with_decorations(false).with_undecorated_shadow(true).build(target)?); + let popup = PopupWindow::new(window, main.content.environment(), page_events.clone(), pending.clone(), &controls)?; + popup.content.load_url(launcher.as_str())?; + bookmarks_window = Some(popup.window.id()); + popups.borrow_mut().push(popup); + Ok(()) + })(); + if let Err(error) = result { + eprintln!("Open saved sites: {error:#}"); + } + } + } Event::UserEvent(ServiceEvent::Navigate(url)) => { if let Some(main) = &window { match main.content.load_url(&url) { @@ -789,11 +835,11 @@ pub fn run(mut config: Config, port: Option) -> Result<()> { } Event::UserEvent(ServiceEvent::PopupLoaded(id)) => { if let Some(child) = popups.borrow().iter().find(|child| child.window.id() == id) { - child.follow_main_theme(launcher_origin.as_ref(), &theme, language); + child.follow_main_theme(launcher_url.as_ref(), &theme, language); } } - Event::UserEvent(ServiceEvent::Ready { entry }) => { - launcher_origin = url::Url::parse(&entry).ok().map(|url| url.origin()); + Event::UserEvent(ServiceEvent::Ready { entry, launcher }) => { + launcher_url = Some(launcher); let opened = match &window { Some(main) => main.content.load_url(&entry).map_err(anyhow::Error::from), None => Ok(()), diff --git a/prototype/channel-server/src/app_windows/caption.rs b/prototype/channel-server/src/app_windows/caption.rs index 317851c0b..57b234112 100644 --- a/prototype/channel-server/src/app_windows/caption.rs +++ b/prototype/channel-server/src/app_windows/caption.rs @@ -71,6 +71,7 @@ impl Caption { .with_new_window_req_handler(|_, _| NewWindowResponse::Deny) .with_ipc_handler(move |request| { let event = match request.body().as_str() { + "bookmarks" if !standalone => ServiceEvent::OpenBookmarks(id), "ready" => ServiceEvent::CaptionReady(id), "minimize" => ServiceEvent::Caption(id, WindowAction::Minimize), "maximize" => ServiceEvent::Caption(id, WindowAction::Maximize), diff --git a/src/client/components/living/AppConnectionButton.tsx b/src/client/components/living/AppConnectionButton.tsx index a0f27b8cd..e10dcd610 100644 --- a/src/client/components/living/AppConnectionButton.tsx +++ b/src/client/components/living/AppConnectionButton.tsx @@ -284,7 +284,7 @@ export function AppConnectionButton({ onConnected, discovery = channelAppDiscove App - {ready && management && {t("client.launcher.manageSites")} } diff --git a/src/client/components/living/LauncherWorkspace.tsx b/src/client/components/living/LauncherWorkspace.tsx index 2aa417c93..b16b1c944 100644 --- a/src/client/components/living/LauncherWorkspace.tsx +++ b/src/client/components/living/LauncherWorkspace.tsx @@ -27,7 +27,7 @@ export function LauncherWorkspace({ bookmarks, bookmarksError, onRetryBookmarks,