From 7d8d5a56965ba88f07b39e4c8d7b87b7257b2e83 Mon Sep 17 00:00:00 2001 From: crynta <3nnigma.dev@gmail.com> Date: Wed, 18 Nov 2026 20:53:43 +0100 Subject: [PATCH 1/5] feat(mini): open a single page in a mini window on macOS and Windows Links from other apps, the New Mini Window command and links a mini page opens now open in a small window outside the sidebar. Rust owns admission, the pin, the remembered size and the live handoff into the main window; the desktop builds the window with its own privileged toolbar, routes the window's keys to it and recovers its renderer. Windows reparents the page's WebView2 controller between windows and joins each toolbar to the launcher's privileged browser. Builds on the Little Arc work in #435 by @nduongg04. --- crates/zephium-app/src/actor/tests.rs | 1 + crates/zephium-app/src/api.rs | 50 ++ crates/zephium-app/src/lib.rs | 7 +- crates/zephium-app/src/shell/mini.rs | 665 ++++++++++++++ crates/zephium-app/src/shell/mod.rs | 30 +- crates/zephium-app/src/shell/operations.rs | 33 +- crates/zephium-app/src/shell/presentation.rs | 48 +- crates/zephium-app/src/shell/private.rs | 5 + .../zephium-app/src/shell/profile_deletion.rs | 10 +- crates/zephium-app/src/shell/projections.rs | 11 +- crates/zephium-app/src/shell/scope.rs | 22 +- crates/zephium-app/src/shell/search.rs | 53 +- crates/zephium-app/src/shell/spaces.rs | 2 + crates/zephium-app/src/shell/tabs.rs | 31 +- .../zephium-app/src/shell/tests/favicons.rs | 1 + crates/zephium-app/src/shell/tests/mini.rs | 832 ++++++++++++++++++ crates/zephium-app/src/shell/tests/mod.rs | 18 + .../zephium-app/src/shell/tests/operations.rs | 7 + crates/zephium-app/src/shell/tests/search.rs | 10 +- .../zephium-app/src/shell/view_lifecycle.rs | 8 +- crates/zephium-app/src/shell/window_layout.rs | 9 +- .../zephium-app/src/shell/work_authoring.rs | 5 +- crates/zephium-core/src/commands.rs | 21 + crates/zephium-core/src/item.rs | 13 +- crates/zephium-core/src/items.rs | 10 +- crates/zephium-core/src/ports/engine.rs | 15 + crates/zephium-core/src/preferences.rs | 6 +- crates/zephium-core/src/session.rs | 23 +- crates/zephium-core/src/windows.rs | 51 +- crates/zephium-engine/src/host/dispatch.rs | 2 + crates/zephium-engine/src/host/mod.rs | 5 + crates/zephium-engine/src/host/page_ops.rs | 28 + crates/zephium-engine/src/host/stages.rs | 171 +++- crates/zephium-engine/src/lib.rs | 57 +- .../src/platform/windows/mod.rs | 13 + .../src/platform/windows/stage.rs | 8 + crates/zephium-ipc/src/lib.rs | 51 ++ crates/zephium-store/src/essentials.rs | 10 +- crates/zephium-store/src/hub/compatibility.rs | 17 +- desktop/capabilities/mini.json | 11 + desktop/src/external_links.rs | 26 +- desktop/src/frame_sources.rs | 1 + desktop/src/lib.rs | 90 +- desktop/src/mini.rs | 800 +++++++++++++++++ desktop/src/overlay.rs | 95 +- desktop/src/overlay/model.rs | 43 + desktop/src/platform/macos.rs | 58 +- desktop/src/platform/windows.rs | 64 +- desktop/src/renderer_recovery.rs | 8 + docs/architecture.md | 15 + frame/bootstrap-report.ts | 18 +- frame/bundle-budgets.json | 298 +++---- frame/messages/de.json | 14 +- frame/messages/en.json | 14 +- frame/messages/es.json | 14 +- frame/messages/fr.json | 14 +- frame/messages/it.json | 14 +- frame/messages/ja.json | 14 +- frame/messages/ko.json | 14 +- frame/messages/pt-BR.json | 14 +- frame/messages/ru.json | 14 +- frame/messages/tr.json | 14 +- frame/messages/uk.json | 14 +- frame/messages/zh-CN.json | 14 +- frame/messages/zh-TW.json | 14 +- frame/mini.html | 12 + frame/src/app/mini/MiniApp.svelte | 137 +++ .../panel/tests/PanelApp.component.test.ts | 1 + frame/src/entries/mini.ts | 15 + .../mini/components/MiniToolbar.svelte | 325 +++++++ frame/src/features/mini/index.ts | 2 + frame/src/features/mini/lib/mini-model.ts | 59 ++ .../mini/tests/MiniToolbar.component.test.ts | 115 +++ .../features/mini/tests/mini-model.test.ts | 88 ++ .../features/panel/tests/panel-model.test.ts | 1 + .../search/components/LauncherPanel.svelte | 29 +- .../search/lib/search-surface.svelte.ts | 16 +- .../tests/LauncherPanel.component.test.ts | 25 + frame/src/features/settings/lib/catalog.ts | 3 +- .../src/features/settings/lib/keymap-model.ts | 3 + frame/src/shared/ipc/bindings.ts | 54 +- frame/src/shared/ipc/native-events.ts | 6 + frame/src/styles/mini.css | 76 ++ frame/vite.config.ts | 2 +- frame/vite.frame.ts | 11 +- frame/vitest.config.ts | 2 +- 86 files changed, 4746 insertions(+), 304 deletions(-) create mode 100644 crates/zephium-app/src/shell/mini.rs create mode 100644 crates/zephium-app/src/shell/tests/mini.rs create mode 100644 desktop/capabilities/mini.json create mode 100644 desktop/src/mini.rs create mode 100644 frame/mini.html create mode 100644 frame/src/app/mini/MiniApp.svelte create mode 100644 frame/src/entries/mini.ts create mode 100644 frame/src/features/mini/components/MiniToolbar.svelte create mode 100644 frame/src/features/mini/index.ts create mode 100644 frame/src/features/mini/lib/mini-model.ts create mode 100644 frame/src/features/mini/tests/MiniToolbar.component.test.ts create mode 100644 frame/src/features/mini/tests/mini-model.test.ts create mode 100644 frame/src/styles/mini.css diff --git a/crates/zephium-app/src/actor/tests.rs b/crates/zephium-app/src/actor/tests.rs index f3e8b8a58..1ec32af00 100644 --- a/crates/zephium-app/src/actor/tests.rs +++ b/crates/zephium-app/src/actor/tests.rs @@ -687,6 +687,7 @@ fn scoped_launcher_actions_cross_the_real_operation_admission_boundary() { action: action.clone(), background: false, replace: None, + new_mini: false, } )); let Command::Operation { command, .. } = queue.try_recv().unwrap() else { diff --git a/crates/zephium-app/src/api.rs b/crates/zephium-app/src/api.rs index 62f6a4161..0bdb5fc43 100644 --- a/crates/zephium-app/src/api.rs +++ b/crates/zephium-app/src/api.rs @@ -115,6 +115,17 @@ pub trait PresentationChrome: GeometryChrome { presentation: ChromePresentation, done: ChromePresentationCallback, ) -> ChromePresentationDispatch; + + /// The same barrier for the page of a mini window, whose own toolbar + /// must show the exact page before it may appear. + fn apply_mini_presentation( + &self, + _window: zephium_core::ids::WindowId, + _presentation: ChromePresentation, + _done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + ChromePresentationDispatch::Rejected + } } /// Terminal result of the ordered application shutdown protocol. @@ -251,6 +262,24 @@ pub enum SpaceCommand { MoveActive(zephium_core::ids::SpaceId), } +/// Something the toolbar of a mini window asks of its page. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum MiniAction { + Back, + Forward, + Reload, + /// Moves the page into the main window as a tab and closes the window. + OpenInMain, + /// The same, into the space the person picked. + OpenInSpace(zephium_core::ids::SpaceId), + Close, + /// Keeps the window above other applications' windows, or stops; `None` + /// turns it the other way. + KeepOnTop(Option), + /// The native window could not be built, so the page opens as a tab. + Unbuilt, +} + /// What the person chose for a page's request to open another application /// or a blocked new tab. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -671,6 +700,9 @@ pub enum Command { SearchScoped { query: String, context: Box, + /// The launcher is choosing a page for a mini window, so it offers + /// only sites, and an open tab's site rather than the tab. + mini: bool, }, CancelSearch { session_id: String, @@ -687,6 +719,9 @@ pub enum Command { /// The tab whose address the launcher was opened to edit: an address /// chosen there replaces that tab's page while it is still in front. replace: Option, + /// The launcher was opened for a new mini window: an address chosen + /// there opens in one, unless the main window shows a private session. + new_mini: bool, }, OpenUrl { input: String, @@ -698,6 +733,21 @@ pub enum Command { /// `navigation::external_target`. Each opens in a new tab; any that /// arrive before the session is restored wait for it. OpenExternal(Vec), + /// The desktop built the native window for a mini window the shell + /// opened, and the engine took its handle. + MiniAttached { + window: zephium_core::ids::WindowId, + size: Size, + }, + MiniResized { + window: zephium_core::ids::WindowId, + size: Size, + }, + /// Something a mini window's toolbar, keys or native window asked of it. + Mini { + window: zephium_core::ids::WindowId, + action: MiniAction, + }, SetAppSetting { key: String, value: String, diff --git a/crates/zephium-app/src/lib.rs b/crates/zephium-app/src/lib.rs index ba56b0555..8f6232120 100644 --- a/crates/zephium-app/src/lib.rs +++ b/crates/zephium-app/src/lib.rs @@ -87,7 +87,7 @@ pub use actor::{spawn_agentic, spawn_agentic_suspended, AgenticSpawnFailure}; pub use api::AgentLifecycle; pub use api::{ BrowserPage, ChromePresentation, ChromePresentationCallback, ChromePresentationDispatch, - Command, ContentPolicyStatusQueryOutcome, EmitFn, PagePermissionPromptDecision, + Command, ContentPolicyStatusQueryOutcome, EmitFn, MiniAction, PagePermissionPromptDecision, PageRequestDecision, PresentationChrome, SharedBlocker, SharedChrome, SharedEngine, SharedStore, ShellTerminalFailure, ShellTerminalFailureCallback, ShutdownOutcome, TabMetadata, WorkPaneTarget, @@ -96,7 +96,10 @@ pub use lookup::{NoteMatch, TaskMatch}; pub use onboarding::{finish_onboarding, onboarding_due}; #[cfg(feature = "work-planning")] pub mod work_context; -pub use shell::{Shell, WebExtensionStatus, WebExtensionTarget}; +pub use shell::{ + admitted_mini_size, Shell, WebExtensionStatus, WebExtensionTarget, MAX_MINI_WINDOWS, + MINI_PAGE_INSET, MINI_TOOLBAR_HEIGHT, MINI_WINDOW_MIN_SIZE, MINI_WINDOW_SIZE, +}; #[doc(hidden)] pub use store_reads::{ImportWork, ImportedSite, StoreReadResult}; diff --git a/crates/zephium-app/src/shell/mini.rs b/crates/zephium-app/src/shell/mini.rs new file mode 100644 index 000000000..359686073 --- /dev/null +++ b/crates/zephium-app/src/shell/mini.rs @@ -0,0 +1,665 @@ +//! Mini windows: a small window of its own for one page, opened by a link +//! another application hands over, by the launcher, or by a link a mini +//! page opens. Its page lives outside every space until the person moves it +//! into the main window, where it becomes an ordinary tab without reloading. +//! A mini window is never saved; closing it ends its page. + +use super::*; + +/// Mini windows open at once; a page beyond this opens as a tab instead. +pub const MAX_MINI_WINDOWS: usize = 8; +/// The toolbar the mini window's chrome draws above its page. +pub const MINI_TOOLBAR_HEIGHT: f64 = 40.0; +/// The size of the first mini window; later ones open at the size the +/// person last gave one, for as long as the browser runs. +pub const MINI_WINDOW_SIZE: Size = Size { + width: 760.0, + height: 640.0, +}; +/// How far the page stays inside the window's left, right and bottom edges. +/// A Windows mini window draws no frame, and the ring it resizes by lies +/// along those edges inside the window; a page there would cover it. +pub const MINI_PAGE_INSET: f64 = if cfg!(target_os = "windows") { + 4.0 +} else { + 0.0 +}; + +/// Where a mini window's page sits in a window of `size`: under the toolbar, +/// clear of the edges it is resized by. +pub(crate) fn mini_page_region(size: Size) -> Rect { + Rect::new( + MINI_PAGE_INSET, + MINI_TOOLBAR_HEIGHT, + (size.width - 2.0 * MINI_PAGE_INSET).max(0.0), + (size.height - MINI_TOOLBAR_HEIGHT - MINI_PAGE_INSET).max(0.0), + ) +} + +/// The smallest content a mini window keeps; the native window enforces it. +pub const MINI_WINDOW_MIN_SIZE: Size = Size { + width: 360.0, + height: 240.0, +}; +/// A reported size beyond this is not a window anyone made. +const MINI_WINDOW_MAX_EDGE: f64 = 16_384.0; + +#[derive(Debug)] +pub(super) struct MiniWindow { + /// The space the page joins when it opens in the main window, if the + /// main window no longer shows one of its profile's spaces by then. + space: SpaceId, + pub(super) page: ItemId, + /// The native window exists and its stage can take the page. + pub(super) attached: bool, + /// Kept above other applications' windows, as the person asked. + pinned: bool, + /// The page takes the keyboard once its view is laid out, so a window + /// that opens can be scrolled and typed into at once. + focus_pending: std::cell::Cell, +} + +#[derive(Debug, Default)] +pub(super) struct MiniState { + pub(super) windows: std::collections::BTreeMap, + /// The size the person last gave a mini window. + size: Option, +} + +/// How a new mini window's page gets its document. +enum MiniSeed { + Navigate(String), + /// The engine already built the view for a page another page opened. + Adopt { + child: ItemId, + adoption: zephium_core::ports::engine::NativeTabAdoption, + }, +} + +/// A size a native window reported, if it is one a window can have. +pub fn admitted_mini_size(size: Size) -> Option { + let edge = |value: f64| value.is_finite() && (1.0..=MINI_WINDOW_MAX_EDGE).contains(&value); + (edge(size.width) && edge(size.height)).then_some(size) +} + +impl Shell { + /// The mini window showing `id`, if one does. + pub(super) fn mini_window_of(&self, id: ItemId) -> Option { + self.mini + .windows + .iter() + .find(|(_, mini)| mini.page == id) + .map(|(window, _)| *window) + } + + pub(super) fn mini_pages(&self) -> impl Iterator + '_ { + self.mini.windows.values().map(|mini| mini.page) + } + + /// Whether a link from another application should open in a mini window. + pub(super) fn external_links_open_mini(&self) -> bool { + self.tab_preferences.external_mini && self.engine.hosts_mini_windows() + } + + /// The regular profile and space a new mini window belongs to: a + /// private window in front is not where another application's link goes. + fn mini_scope(&self) -> Option<(ProfileId, SpaceId)> { + if let Some(scope) = self + .private + .as_ref() + .and_then(|session| session.regular_scope()) + { + return Some(scope); + } + self.windows + .focused() + .map(|window| (window.profile, window.space)) + } + + /// Opens a mini window on `url` in the regular scope. `false` means none + /// opened and the caller falls back. + pub(super) fn open_mini(&mut self, url: String) -> bool { + let Some((profile, space)) = self.mini_scope() else { + return false; + }; + self.open_mini_page(profile, space, MiniSeed::Navigate(url)) + .is_some() + } + + /// A page in a mini window asked for a new window: the link opens in a + /// mini window of its own, in the same profile, so the person's place in + /// the main window stays as it was. `false` when none can open. + pub(super) fn open_linked_mini(&mut self, source: ItemId, url: &str) -> bool { + let Some((profile, space)) = self.mini_origin(source) else { + return false; + }; + self.open_mini_page(profile, space, MiniSeed::Navigate(url.to_owned())) + .is_some() + } + + /// A link a mini page opened when no further mini window can: it waits + /// as a tab in the main window, which stays where it was. + pub(super) fn open_mini_link_as_tab(&mut self, source: ItemId, url: &str) { + if let Some((profile, space)) = self.mini_origin(source) { + let _ = self.open_page_tab(profile, space, None, url, false); + } + } + + /// The same for a page the engine already built, such as a sign-in + /// popup that keeps its opener. + pub(super) fn adopt_linked_mini( + &mut self, + source: ItemId, + child: ItemId, + foreground: bool, + adoption: zephium_core::ports::engine::NativeTabAdoption, + ) { + let Some((profile, space)) = self.mini_origin(source) else { + adoption.finish(false); + return; + }; + if self.items.get(child).is_some() + || self.items.view_ids().len() >= LIVE_VIEW_ABSOLUTE_LIMIT + { + adoption.finish(false); + return; + } + if self + .open_mini_page(profile, space, MiniSeed::Adopt { child, adoption }) + .is_none() + { + return; + } + self.items.clear_blocked_popup(source); + self.native_openers.insert( + child, + NativeOpener { + source, + activate_when_presentable: foreground, + }, + ); + } + + /// The profile and space of the mini window showing `source`. + fn mini_origin(&self, source: ItemId) -> Option<(ProfileId, SpaceId)> { + let window = self.mini_window_of(source)?; + let mini = self.mini.windows.get(&window)?; + let profile = self.windows.get(window)?.profile; + Some((profile, mini.space)) + } + + /// Makes the window and its page. An adopted view's page takes the + /// adoption's own id. `None` means nothing opened; an adoption was + /// answered. + fn open_mini_page( + &mut self, + profile: ProfileId, + space: SpaceId, + seed: MiniSeed, + ) -> Option { + let refused = !self.bootstrapped + || !self.engine.hosts_mini_windows() + || self.mini.windows.len() >= MAX_MINI_WINDOWS + // A private page never leaves the private window. + || self.incognito_profile(profile) + || self.profile_deletion_quarantines(profile) + || self + .spaces + .get(space) + .is_none_or(|known| known.profile != profile); + let page = match &seed { + MiniSeed::Adopt { child, .. } => *child, + MiniSeed::Navigate(_) => ItemId::generate(), + }; + if refused || !self.items.insert_tab(page, Placement::Mini { profile }) { + if let MiniSeed::Adopt { adoption, .. } = seed { + adoption.finish(false); + } + return None; + } + let size = self.mini.size.unwrap_or(MINI_WINDOW_SIZE); + let window = self.windows.create_unfocused( + zephium_core::windows::WindowKind::Mini, + profile, + space, + size, + ); + if let Some(win) = self.windows.get_mut(window) { + win.active = Some(page); + } + self.mini.windows.insert( + window, + MiniWindow { + space, + page, + attached: false, + pinned: false, + focus_pending: std::cell::Cell::new(true), + }, + ); + (self.emit)(Projection::MiniOpened(zephium_ipc::MiniOpenedView { + window, + width: size.width, + height: size.height, + })); + match seed { + MiniSeed::Navigate(url) => { + self.project_mini(window); + let effects = self.items.navigate(page, &url); + self.commit(effects); + } + MiniSeed::Adopt { adoption, .. } => { + if !self.items.adopt_native_view(page) { + adoption.finish(false); + self.close_mini(window); + return None; + } + self.record_view_creation(page); + self.project_mini(window); + self.commit(Vec::new()); + adoption.finish(true); + } + } + Some(window) + } + + /// The native window for `window` exists and the engine took its handle. + pub(super) fn mini_attached(&mut self, window: WindowId, size: Size) { + let Some(mini) = self.mini.windows.get_mut(&window) else { + // Closed before the desktop finished building it. + let _ = self.engine.release_window(window); + return; + }; + // A window no screen could hold gets no page laid out in it; its + // next real size attaches it. + let Some(size) = admitted_mini_size(size) else { + return; + }; + mini.attached = true; + let page = mini.page; + if let Some(win) = self.windows.get_mut(window) { + win.size = size; + } + self.project_mini(window); + let _ = self.relayout_mini(window); + // A first document can commit before the toolbar exists to verify + // it; that toolbar is ready now. + if let Some(pending) = self + .presentation + .pending_presentations + .get(&page) + .filter(|pending| !pending.chrome_applied && !pending.chrome_request_in_flight) + .map(|pending| pending.navigation) + { + self.request_chrome_presentation(page, pending); + } + } + + pub(super) fn mini_resized(&mut self, window: WindowId, size: Size) { + let Some(size) = admitted_mini_size(size) else { + return; + }; + let Some(mini) = self.mini.windows.get(&window) else { + return; + }; + if mini.attached { + self.mini.size = Some(size); + } + if let Some(win) = self.windows.get_mut(window) { + win.size = size; + } + let _ = self.relayout_mini(window); + } + + /// Lays out every mini window's page. Main-window layouts call this, so + /// a page that gains or loses its view, or a policy that settles, reaches + /// them too. + pub(super) fn relayout_mini_windows(&self) { + for window in self.mini.windows.keys() { + let _ = self.relayout_mini(*window); + } + } + + fn relayout_mini(&self, window: WindowId) -> NativeDispatch { + let (Some(mini), Some(win)) = (self.mini.windows.get(&window), self.windows.get(window)) + else { + return NativeDispatch::Rejected; + }; + if !mini.attached { + return NativeDispatch::Rejected; + } + let page = Some(mini.page).filter(|id| { + self.items.tab(*id).is_some_and(TabState::has_view) + && self.blocker.native_policy_available(win.profile) + }); + let region = mini_page_region(win.size); + let dispatch = match page { + Some(id) => self + .engine + .set_content(window, Some(Pane::Leaf(id)), Some(region)), + None => self.engine.set_content(window, None, None), + }; + if let Some(id) = page.filter(|_| mini.focus_pending.get()) { + if self.engine.focus_page(id) == NativeDispatch::Scheduled { + mini.focus_pending.set(false); + } + } + dispatch + } + + /// Sends the mini window its page as chrome shows it. + pub(super) fn project_mini(&self, window: WindowId) { + let Some(mini) = self.mini.windows.get(&window) else { + return; + }; + let tab = Some(mini.page).and_then(|id| { + let profile = self.profile_of_item(id); + let view = self.generic_tab_view(id, self.items.tab(id)?, profile); + self.record_tab_projection_revision(id, &view.projection_revision); + Some(view) + }); + (self.emit)(Projection::Mini(self.mini_view(window, tab))); + } + + pub(super) fn mini_view( + &self, + window: WindowId, + tab: Option, + ) -> zephium_ipc::MiniView { + let profile = self.windows.get(window).map(|win| win.profile); + let spaces = profile + .map(|profile| { + self.spaces + .of(profile) + .into_iter() + .filter_map(|id| self.spaces.get(id)) + .map(|space| zephium_ipc::MiniSpaceView { + id: space.id.to_string(), + name: space.name.clone(), + }) + .collect() + }) + .unwrap_or_default(); + zephium_ipc::MiniView { + window, + tab, + spaces, + space: self.mini_target(window).map(|space| space.to_string()), + pinned: self + .mini + .windows + .get(&window) + .is_some_and(|mini| mini.pinned), + } + } + + /// The space "Open in Zephium" uses by default: the one the main window + /// shows when it is the page's profile, else the one the window opened + /// from. + fn mini_target(&self, window: WindowId) -> Option { + let profile = self.windows.get(window)?.profile; + let origin = self.mini.windows.get(&window)?.space; + self.mini_scope() + .filter(|(main, _)| *main == profile) + .map(|(_, space)| space) + .or(Some(origin)) + .filter(|space| { + self.spaces + .get(*space) + .is_some_and(|known| known.profile == profile) + }) + } + + /// Loads an address the launcher chose in a mini window's page. + pub(super) fn navigate_mini(&mut self, window: WindowId, url: &str) -> bool { + let Some(page) = self.mini.windows.get(&window).map(|mini| mini.page) else { + return false; + }; + self.cancel_discard_probe(page); + self.cancel_page_permission_for_item(page); + let effects = self.items.navigate(page, url); + self.commit(effects); + self.project_mini(window); + true + } + + pub(super) fn mini_action(&mut self, window: WindowId, action: crate::MiniAction) { + let Some(page) = self.mini.windows.get(&window).map(|mini| mini.page) else { + return; + }; + match action { + crate::MiniAction::Close => self.close_mini(window), + crate::MiniAction::OpenInMain => self.open_mini_in_main(window, None), + crate::MiniAction::OpenInSpace(space) => { + self.open_mini_in_main(window, Some(space)); + } + // The desktop could not build the window: the page still opens, + // as a tab, rather than being lost. + crate::MiniAction::Unbuilt => { + if self + .mini + .windows + .get(&window) + .is_some_and(|mini| mini.attached) + { + return; + } + self.open_mini_in_main(window, None); + } + crate::MiniAction::KeepOnTop(pinned) => { + let Some(mini) = self.mini.windows.get_mut(&window) else { + return; + }; + let pinned = pinned.unwrap_or(!mini.pinned); + if mini.pinned != pinned { + mini.pinned = pinned; + self.project_mini(window); + } + } + crate::MiniAction::Back | crate::MiniAction::Forward => { + let forward = action == crate::MiniAction::Forward; + let available = self.items.tab(page).is_some_and(|tab| { + tab.has_view() + && if forward { + tab.can_go_forward + } else { + tab.can_go_back + } + }); + if !available { + return; + } + self.cancel_discard_probe(page); + self.cancel_page_permission_for_item(page); + let _ = if forward { + self.engine.go_forward(page) + } else { + self.engine.go_back(page) + }; + } + crate::MiniAction::Reload => { + self.cancel_discard_probe(page); + self.cancel_page_permission_for_item(page); + if self.items.tab(page).is_some_and(TabState::has_view) { + let _ = self.engine.reload(page); + } else { + let effects = self.items.ensure_view(page); + self.commit(effects); + } + } + } + } + + /// Ends a mini window and the page in it. + pub(super) fn close_mini(&mut self, window: WindowId) { + let Some(mini) = self.mini.windows.remove(&window) else { + return; + }; + self.windows.remove(window); + // The page is ended before the stage that holds it is released, so + // its view goes back to the main window's keeping, never with the + // native window. + if self.items.tab(mini.page).is_some() { + self.forget_mini_page(mini.page); + let effects = self.items.remove(mini.page); + self.commit(effects); + } + let _ = self.engine.release_window(window); + (self.emit)(Projection::MiniClosed(zephium_ipc::MiniClosedView { + window, + reveal_main: false, + })); + } + + fn forget_mini_page(&mut self, id: ItemId) { + self.native_openers.remove(&id); + self.cancel_page_permission_for_item(id); + self.cancel_pending_presentation(id); + self.cancel_favicon_attempt(id); + if matches!( + self.residency.discard_probes.get(&id), + Some(PendingDiscardProbe::Closing { .. }) + ) { + self.cancel_discard_probe(id); + self.residency.discard_probes.remove(&id); + if let Some(queue) = &self.self_queue { + queue.cancel_discard_probe(id); + } + } else { + self.cancel_discard_probe(id); + } + if let Some(profile) = self.profile_of_item(id) { + self.engine.forget_discarded_state(profile, Some(id)); + } + } + + /// Moves the page into the main window as a tab in front of `target`, or + /// of the default space, keeping the live page, and closes the mini + /// window. A space of another profile is ignored. + pub(super) fn open_mini_in_main(&mut self, window: WindowId, target: Option) { + let Some(mini) = self.mini.windows.get(&window) else { + return; + }; + let id = mini.page; + let origin = mini.space; + if self.items.tab(id).is_none() { + self.close_mini(window); + return; + } + let Some(profile) = self.profile_of_item(id) else { + self.close_mini(window); + return; + }; + let target = target.filter(|space| { + self.spaces + .get(*space) + .is_some_and(|known| known.profile == profile) + }); + if self.private_shown() { + let _ = self.operation_leave_private(); + } + if self.active_browser_page().is_some() { + let _ = self.operation_show_browser_page(None); + } + if self + .windows + .focused() + .is_some_and(|main| main.profile != profile) + { + let _ = self.operation_switch_profile(profile); + } + let Some(space) = target + .or_else(|| { + self.windows + .focused() + .filter(|main| main.profile == profile) + .map(|main| main.space) + }) + .or_else(|| { + self.spaces + .get(origin) + .filter(|space| space.profile == profile) + .map(|_| origin) + }) + else { + return; + }; + if self + .windows + .focused() + .is_some_and(|main| main.space != space) + { + let _ = self.operation_space(crate::SpaceCommand::Switch(space)); + } + let before = self.today_tabs(space).into_iter().next(); + if !self.items.move_tab_to_root( + id, + Placement::Space { + space, + section: SpaceSection::Today, + }, + before, + ) { + return; + } + self.mini.windows.remove(&window); + self.windows.remove(window); + // The page leaves the mini window's stage before the main window's + // layout takes it, both on the native thread in this order. + let _ = self.engine.release_window(window); + let effects = self.focus_tab(id); + self.commit(effects); + (self.emit)(Projection::MiniClosed(zephium_ipc::MiniClosedView { + window, + reveal_main: true, + })); + } + + /// Closes mini windows whose page went away underneath them, as a + /// deleted profile's pages do. + pub(super) fn prune_mini_windows(&mut self) { + let orphaned: Vec = self + .mini + .windows + .iter() + .filter(|(_, mini)| self.items.tab(mini.page).is_none()) + .map(|(window, _)| *window) + .collect(); + for window in orphaned { + self.close_mini(window); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn only_sizes_a_window_can_have_are_admitted() { + assert_eq!( + admitted_mini_size(Size::new(800.0, 600.0)), + Some(Size::new(800.0, 600.0)) + ); + for size in [ + Size::new(0.0, 600.0), + Size::new(800.0, -1.0), + Size::new(f64::NAN, 600.0), + Size::new(800.0, f64::INFINITY), + Size::new(MINI_WINDOW_MAX_EDGE + 1.0, 600.0), + ] { + assert_eq!(admitted_mini_size(size), None, "{size:?}"); + } + } + + #[test] + fn the_page_sits_under_the_toolbar_clear_of_the_resize_edges() { + let region = mini_page_region(Size::new(760.0, 640.0)); + assert_eq!(region.x, MINI_PAGE_INSET); + assert_eq!(region.y, MINI_TOOLBAR_HEIGHT); + assert_eq!(region.width, 760.0 - 2.0 * MINI_PAGE_INSET); + assert_eq!(region.height, 640.0 - MINI_TOOLBAR_HEIGHT - MINI_PAGE_INSET); + let tiny = mini_page_region(Size::new(0.0, 10.0)); + assert_eq!((tiny.width, tiny.height), (0.0, 0.0)); + } +} diff --git a/crates/zephium-app/src/shell/mod.rs b/crates/zephium-app/src/shell/mod.rs index 362232f42..a62330df5 100644 --- a/crates/zephium-app/src/shell/mod.rs +++ b/crates/zephium-app/src/shell/mod.rs @@ -24,7 +24,12 @@ mod history; mod history_list; mod https_first; mod media; +mod mini; mod network; +pub use mini::{ + admitted_mini_size, MAX_MINI_WINDOWS, MINI_PAGE_INSET, MINI_TOOLBAR_HEIGHT, + MINI_WINDOW_MIN_SIZE, MINI_WINDOW_SIZE, +}; mod operations; mod page_permissions; mod page_requests; @@ -83,15 +88,15 @@ use crate::actor::{CallbackHandle, CommandQueue}; #[cfg(feature = "agentic-browser")] use crate::api::AgentLifecycle; use crate::api::PagePermissionPromptDecision; +#[cfg(test)] +use crate::api::PresentationChrome; use crate::api::TabAction; use crate::api::{ - ChromePresentation, ChromePresentationDispatch, Command, ContentPolicyStatusQueryOutcome, - EmitFn, SharedBlocker, SharedChrome, SharedEngine, SharedStore, ShellTerminalFailure, - ShellTerminalFailureCallback, ShutdownOutcome, + ChromePresentation, ChromePresentationCallback, ChromePresentationDispatch, Command, + ContentPolicyStatusQueryOutcome, EmitFn, SharedBlocker, SharedChrome, SharedEngine, + SharedStore, ShellTerminalFailure, ShellTerminalFailureCallback, ShutdownOutcome, }; #[cfg(test)] -use crate::api::{ChromePresentationCallback, PresentationChrome}; -#[cfg(test)] use crate::store_reads::FAVICON_CACHE_MAX_AGE_SECONDS; use crate::store_reads::{StoreReadQueue, StoreReadResult}; @@ -252,6 +257,7 @@ pub struct Shell { windows: Windows, recent_tabs: recent_tabs::RecentTabs, tab_previews: tab_previews::TabPreviews, + mini: mini::MiniState, pending_size: Size, favicons: FaviconState, history: history::HistoryState, @@ -526,6 +532,7 @@ impl Shell { items: Items::default(), recently_closed: Vec::new(), windows: Windows::default(), + mini: mini::MiniState::default(), pending_size: Size::default(), favicons: FaviconState::default(), history: history::HistoryState::default(), @@ -1392,7 +1399,11 @@ impl Shell { query, results, } => self.search_additional(*context, query, results), - Command::SearchScoped { query, context } => self.search_scoped(&query, *context), + Command::SearchScoped { + query, + context, + mini, + } => self.search_scoped(&query, *context, mini), Command::CancelSearch { session_id } => self.cancel_scoped_search(&session_id), Command::PanelLoaded => { self.forget_delivered_icons(zephium_ipc::IconSurface::Panel); @@ -1403,13 +1414,18 @@ impl Shell { action, background, replace, + new_mini, } => { - let _ = self.operation_run_search_action(*context, action, background, replace); + let _ = self + .operation_run_search_action(*context, action, background, replace, new_mini); } Command::OpenUrl { input, new_tab } => { let _ = self.operation_open_url(input, new_tab); } Command::OpenExternal(urls) => self.open_external(urls), + Command::MiniAttached { window, size } => self.mini_attached(window, size), + Command::MiniResized { window, size } => self.mini_resized(window, size), + Command::Mini { window, action } => self.mini_action(window, action), Command::Find(request) => self.find_in_page(request), Command::ShowStoreButton { tab, button } => self.show_store_button(tab, button), Command::SetAppSetting { key, value } => { diff --git a/crates/zephium-app/src/shell/operations.rs b/crates/zephium-app/src/shell/operations.rs index be0359890..c31e200e2 100644 --- a/crates/zephium-app/src/shell/operations.rs +++ b/crates/zephium-app/src/shell/operations.rs @@ -72,7 +72,8 @@ impl Shell { action, background, replace, - } => self.operation_run_search_action(*context, action, background, replace), + new_mini, + } => self.operation_run_search_action(*context, action, background, replace, new_mini), Command::InvokeExtensionAction { runtime, revision, @@ -446,7 +447,9 @@ impl Shell { } /// Opens what another application handed over, each in its own tab and - /// the last one in front, the way a clicked link opens elsewhere. + /// the last one in front, the way a clicked link opens elsewhere. With + /// mini windows chosen, each opens in one and the main window is left + /// as it was; a link no mini window can take still opens as a tab. pub(super) fn open_external(&mut self, urls: Vec) { let limit = zephium_core::navigation::MAX_EXTERNAL_TARGETS; if !self.bootstrapped { @@ -454,6 +457,16 @@ impl Shell { self.pending_external.extend(urls.into_iter().take(room)); return; } + let mut urls: Vec = urls.into_iter().take(limit).collect(); + if self.external_links_open_mini() { + urls.retain(|url| { + zephium_core::navigation::external_target(url) + .is_some_and(|url| !self.open_mini(url.to_string())) + }); + if urls.is_empty() { + return; + } + } // Another application's link is not a private page: it opens with // the regular tabs, the way a private window leaves it to another. if self.private_shown() { @@ -469,11 +482,16 @@ impl Shell { .tab_preferences .external_position .unwrap_or(self.tab_preferences.new_position); - for url in urls.into_iter().take(limit) { + let mut opened = false; + for url in urls { if let Some(url) = zephium_core::navigation::external_target(&url) { let _ = self.open_url_in_new_tab_at(url.to_string(), position); + opened = true; } } + if opened { + (self.emit)(Projection::ExternalTabsOpened); + } } /// Opens the startup list. The tab launch put in front is the first @@ -1020,6 +1038,15 @@ impl Shell { match id { "tab.new" => self.operation_open(), "window.newPrivate" => self.operation_enter_private(), + // The desktop opens the launcher for a mini window instead; this + // runs only while the private window is in front, whose pages + // never leave it, so the quick page is a private tab. + "window.newMini" => self.operation_open(), + // Keys a mini window answers; the desktop hands them to the one + // in front, and with none in front they do nothing. + "mini.openInMain" | "mini.keepOnTop" => { + operation_result(OperationOutcome::NoOp, OperationReason::StateUnchanged) + } "window.closePrivate" => self.operation_close_private(), "window.togglePrivate" => self.operation_toggle_private(), "window.showRegular" => self.operation_show_regular(), diff --git a/crates/zephium-app/src/shell/presentation.rs b/crates/zephium-app/src/shell/presentation.rs index 639d08cd8..0b591ce87 100644 --- a/crates/zephium-app/src/shell/presentation.rs +++ b/crates/zephium-app/src/shell/presentation.rs @@ -191,10 +191,44 @@ impl Shell { } } + /// The page in front of the chrome that presents `id`: the page itself in + /// a mini window, the focused window's active tab otherwise. + fn presentation_active(&self, id: ItemId) -> Option { + if self.mini_window_of(id).is_some() { + return Some(id); + } + self.windows.focused().and_then(|window| window.active) + } + + /// A mini window's page is verified by that window's own toolbar. + fn dispatch_chrome_presentation( + &self, + presentation: ChromePresentation, + done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + match self.mini_window_of(presentation.id) { + Some(window) => self + .chrome + .apply_mini_presentation(window, presentation, done), + None => self.chrome.apply_tab_for_presentation(presentation, done), + } + } + + fn emit_presented_tab(&self, id: ItemId, tab: TabView) { + match self.mini_window_of(id) { + Some(window) => (self.emit)(Projection::Mini(self.mini_view(window, Some(tab)))), + None => (self.emit)(Projection::Tab(tab)), + } + } + /// Applies the exact tab projection inside privileged chrome and waits for /// its eval callback before allowing the raw child to reveal. This method /// never blocks the shell actor or a native UI thread. - fn request_chrome_presentation(&mut self, id: ItemId, navigation: NavigationPresentationId) { + pub(super) fn request_chrome_presentation( + &mut self, + id: ItemId, + navigation: NavigationPresentationId, + ) { let Some(pending) = self .presentation .pending_presentations @@ -234,10 +268,10 @@ impl Shell { self.record_tab_projection_revision(id, &projection_revision); self.remember_tab_view(id, &projection); self.publish_icons(); - let active = self.windows.focused().and_then(|window| window.active); + let active = self.presentation_active(id); let Some(queue) = self.self_queue.clone() else { let synchronous_projection = projection.clone(); - let dispatch = self.chrome.apply_tab_for_presentation( + let dispatch = self.dispatch_chrome_presentation( ChromePresentation { settings_visible: self.active_browser_page() == Some(crate::BrowserPage::Settings), @@ -253,7 +287,7 @@ impl Shell { // A synchronous adapter already applied this exact revision; // mirror it to non-chrome projection observers afterward. // Privileged chrome ignores the equal-revision duplicate. - (self.emit)(Projection::Tab(synchronous_projection)); + self.emit_presented_tab(id, synchronous_projection); self.on_chrome_presentation_applied( id, navigation, @@ -286,7 +320,7 @@ impl Shell { current.chrome_request_in_flight = true; } let synchronous_projection = projection.clone(); - let dispatch = self.chrome.apply_tab_for_presentation( + let dispatch = self.dispatch_chrome_presentation( ChromePresentation { settings_visible: self.active_browser_page() == Some(crate::BrowserPage::Settings), id, @@ -308,7 +342,7 @@ impl Shell { ); match dispatch { ChromePresentationDispatch::Applied => { - (self.emit)(Projection::Tab(synchronous_projection)); + self.emit_presented_tab(id, synchronous_projection); self.on_chrome_presentation_applied( id, navigation, @@ -365,7 +399,7 @@ impl Shell { .last_tab_projection_revision .try_borrow() .is_ok_and(|revisions| revisions.get(&id) == Some(&projection_revision)); - let active_exact = self.windows.focused().and_then(|window| window.active) == active; + let active_exact = self.presentation_active(id) == active; if !revision_exact || !active_exact { // The original exact timer remains armed. It will clear the // in-flight bit and issue a newer projection; this stale callback diff --git a/crates/zephium-app/src/shell/private.rs b/crates/zephium-app/src/shell/private.rs index 919239820..4a6953286 100644 --- a/crates/zephium-app/src/shell/private.rs +++ b/crates/zephium-app/src/shell/private.rs @@ -32,6 +32,11 @@ impl PrivateSession { pub(super) fn regular_profile(&self) -> ProfileId { self.other.profile } + + /// The regular profile and space while the private scope is in front. + pub(super) fn regular_scope(&self) -> Option<(ProfileId, SpaceId)> { + self.shown.then_some((self.other.profile, self.other.space)) + } } impl Shell { diff --git a/crates/zephium-app/src/shell/profile_deletion.rs b/crates/zephium-app/src/shell/profile_deletion.rs index 84c755b95..6198cb5a4 100644 --- a/crates/zephium-app/src/shell/profile_deletion.rs +++ b/crates/zephium-app/src/shell/profile_deletion.rs @@ -224,9 +224,13 @@ impl Shell { .recently_closed .retain(|entry| entry.profile != profile); filtered.spaces.retain(|space| space.profile != profile); - filtered.items.retain(|item| { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = item.placement; - !removed_spaces.contains(&space) + filtered.items.retain(|item| match item.placement { + Placement::Favorites { space } | Placement::Space { space, .. } => { + !removed_spaces.contains(&space) + } + Placement::Mini { + profile: item_profile, + } => item_profile != profile, }); (session::canonicalize(filtered.clone()) == filtered).then_some(filtered) diff --git a/crates/zephium-app/src/shell/projections.rs b/crates/zephium-app/src/shell/projections.rs index 1098aa541..270ea1675 100644 --- a/crates/zephium-app/src/shell/projections.rs +++ b/crates/zephium-app/src/shell/projections.rs @@ -401,6 +401,10 @@ impl Shell { } pub(super) fn project_tab(&self, id: ItemId) { + if let Some(window) = self.mini_window_of(id) { + self.project_mini(window); + return; + } if self .windows .focused() @@ -446,7 +450,12 @@ impl Shell { } } - fn generic_tab_view(&self, id: ItemId, tab: &TabState, profile: Option) -> TabView { + pub(super) fn generic_tab_view( + &self, + id: ItemId, + tab: &TabState, + profile: Option, + ) -> TabView { let mut view = self.presentation_tab_view(id, tab, self.tab_icon(id, tab, profile)); if self .presentation diff --git a/crates/zephium-app/src/shell/scope.rs b/crates/zephium-app/src/shell/scope.rs index 4e94b75fc..3f464b74e 100644 --- a/crates/zephium-app/src/shell/scope.rs +++ b/crates/zephium-app/src/shell/scope.rs @@ -14,9 +14,12 @@ impl Shell { } pub(super) fn profile_of_item(&self, id: ItemId) -> Option { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = - self.items.get(id)?.placement; - self.spaces.get(space).map(|s| s.profile) + match self.items.get(id)?.placement { + Placement::Favorites { space } | Placement::Space { space, .. } => { + self.spaces.get(space).map(|s| s.profile) + } + Placement::Mini { profile } => Some(profile), + } } /// A space is an authorization boundary for UI-directed item IDs: its @@ -35,11 +38,14 @@ impl Shell { let Some(item) = self.items.get(id).filter(|item| item.tab().is_some()) else { return false; }; - let (Placement::Favorites { space: item_space } - | Placement::Space { - space: item_space, .. - }) = item.placement; - item_space == space + match item.placement { + Placement::Favorites { space: item_space } + | Placement::Space { + space: item_space, .. + } => item_space == space, + // A mini window's page answers only to that window. + Placement::Mini { .. } => false, + } } pub(super) fn item_in_focused_scope(&self, id: ItemId) -> bool { diff --git a/crates/zephium-app/src/shell/search.rs b/crates/zephium-app/src/shell/search.rs index dca2961b9..ccbd3cf56 100644 --- a/crates/zephium-app/src/shell/search.rs +++ b/crates/zephium-app/src/shell/search.rs @@ -29,6 +29,8 @@ pub(super) struct SearchState { /// history search still reads them. pub(super) include_history: bool, pub(super) context: Option, + /// The bound launcher is choosing a page for a mini window. + pub(super) mini: bool, pub(super) results: Vec, pub(super) pending: Option, pub(super) generation: u64, @@ -45,6 +47,11 @@ impl Shell { .map(str::to_owned) }) .flatten(); + if self.search.mini { + results + .results + .retain(|result| matches!(result.action, SearchAction::OpenUrl { .. })); + } let mut identities = std::collections::HashSet::new(); results.results.retain(|result| { identities.insert(match &result.action { @@ -166,7 +173,12 @@ impl Shell { }); } - pub(super) fn search_scoped(&mut self, query: &str, context: zephium_ipc::SearchContext) { + pub(super) fn search_scoped( + &mut self, + query: &str, + context: zephium_ipc::SearchContext, + mini: bool, + ) { if !self.search_context_current(&context) { return; } @@ -176,6 +188,9 @@ impl Shell { self.search.supplementary_pending = !query.trim().is_empty(); self.search.query = query.to_owned(); self.search.context = Some(context); + // A private session's tabs and history must not become a regular + // Mini page's address. + self.search.mini = mini && !self.private_shown(); self.search(query); } @@ -226,6 +241,7 @@ impl Shell { self.search.pending = None; self.search.supplementary_pending = false; self.search.context = None; + self.search.mini = false; self.search.results.clear(); } } @@ -236,6 +252,7 @@ impl Shell { action: SearchAction, background: bool, replace: Option, + new_mini: bool, ) -> OperationDisposition { if !self.search_context_current(&context) || self.search.context.as_ref() != Some(&context) @@ -310,6 +327,14 @@ impl Shell { { // The launcher stood in for the page's own address field. self.operation_navigate(id, url) + } else if replace + .as_deref() + .and_then(ItemId::parse) + .and_then(|id| self.mini_window_of(id)) + .is_some_and(|window| self.navigate_mini(window, &url)) + || (new_mini && !self.private_shown() && self.open_mini(url.clone())) + { + operation_result(OperationOutcome::Applied, OperationReason::OpenedInMini) } else { self.operation_open_url(url, true) } @@ -375,6 +400,15 @@ impl Shell { } stack.extend(self.items.children(id).iter().rev().copied()); } + // A blank tab is not a site, and it must not use up a row. + if self.search.mini { + tabs.retain(|id| { + self.items + .tab(*id) + .and_then(|tab| tab.url.as_ref()) + .is_some_and(|url| navigation::is_allowed_str(url.as_str())) + }); + } tabs.sort_by_key(|id| std::cmp::Reverse(self.residency.last_focus.get(id).copied())); let mut results = Vec::new(); self.search.generation = self.search.generation.wrapping_add(1); @@ -393,6 +427,7 @@ impl Shell { *id, t, self.icon_ref(self.search_surface(), t, Some(profile)), + self.search.mini, ) }) }) @@ -416,6 +451,7 @@ impl Shell { *id, t, self.icon_ref(self.search_surface(), t, Some(profile)), + self.search.mini, ) })); @@ -680,7 +716,12 @@ impl Shell { } } -fn tab_result(id: ItemId, tab: &TabState, icon: Option) -> SearchResult { +fn tab_result( + id: ItemId, + tab: &TabState, + icon: Option, + mini: bool, +) -> SearchResult { let detail = tab .url .as_ref() @@ -691,6 +732,12 @@ fn tab_result(id: ItemId, tab: &TabState, icon: Option) -> title: tab.title.clone(), detail, icon, - action: SearchAction::ActivateTab { id: id.to_string() }, + action: match tab.url.as_ref().filter(|_| mini) { + // The tab stays where it is; its site opens in the mini window. + Some(url) => SearchAction::OpenUrl { + url: url.to_string(), + }, + None => SearchAction::ActivateTab { id: id.to_string() }, + }, } } diff --git a/crates/zephium-app/src/shell/spaces.rs b/crates/zephium-app/src/shell/spaces.rs index 5780ded4e..0afd10e0a 100644 --- a/crates/zephium-app/src/shell/spaces.rs +++ b/crates/zephium-app/src/shell/spaces.rs @@ -440,6 +440,8 @@ impl Shell { }, ), Placement::Favorites { space } => (space, Placement::Favorites { space: target }), + // A mini window's page moves only through its own window. + Placement::Mini { .. } => return rejected(OperationReason::InvalidScope), }; if space == target { return unchanged(); diff --git a/crates/zephium-app/src/shell/tabs.rs b/crates/zephium-app/src/shell/tabs.rs index c5d0340d2..b58c93307 100644 --- a/crates/zephium-app/src/shell/tabs.rs +++ b/crates/zephium-app/src/shell/tabs.rs @@ -47,6 +47,9 @@ pub(super) struct TabPreferences { /// Where a link handed over by another application opens; none /// follows `new_position`. pub(super) external_position: Option, + /// A link handed over by another application opens in a mini window, + /// the default; a link no mini window can take still opens as a tab. + pub(super) external_mini: bool, pub(super) archive_after: ArchiveAfter, pub(super) after_close: AfterClose, /// Opening an address already open in this space goes to that tab. @@ -66,6 +69,7 @@ impl Default for TabPreferences { Self { new_position: NewTabPosition::default(), external_position: None, + external_mini: true, archive_after: ArchiveAfter::default(), after_close: AfterClose::default(), switch_to_open: true, @@ -124,10 +128,21 @@ impl TabPreferences { self.startup_pages = zephium_core::preferences::startup_pages(value) } ("tabs.home", value) => self.home = zephium_core::preferences::home_page(value), - ("tabs.external-position", "new-tab") => self.external_position = None, - ("tabs.external-position", "end") => self.external_position = Some(NewTabPosition::End), + ("tabs.external-position", "new-tab") => { + self.external_position = None; + self.external_mini = false; + } + ("tabs.external-position", "end") => { + self.external_position = Some(NewTabPosition::End); + self.external_mini = false; + } ("tabs.external-position", "after-current") => { - self.external_position = Some(NewTabPosition::AfterCurrent) + self.external_position = Some(NewTabPosition::AfterCurrent); + self.external_mini = false; + } + ("tabs.external-position", "mini") => { + self.external_position = None; + self.external_mini = true; } ("tabs.archive", "never") => self.archive_after = ArchiveAfter::Never, ("tabs.archive", "12h") => self.archive_after = ArchiveAfter::HalfDay, @@ -788,6 +803,10 @@ impl Shell { foreground: bool, adoption: zephium_core::ports::engine::NativeTabAdoption, ) { + if self.mini_window_of(source).is_some() { + self.adopt_linked_mini(source, child, foreground, adoption); + return; + } let Some((profile, space)) = self.windows.focused().map(|win| (win.profile, win.space)) else { return; @@ -900,6 +919,12 @@ impl Shell { /// source, routed through the same navigation policy. The split group /// survives: the new tab shows alone, the group stays a tab away. pub(super) fn open_linked_tab(&mut self, source: ItemId, url: &str) { + if self.mini_window_of(source).is_some() { + if !self.open_linked_mini(source, url) { + self.open_mini_link_as_tab(source, url); + } + return; + } let Some((profile, space)) = self.windows.focused().map(|win| (win.profile, win.space)) else { return; diff --git a/crates/zephium-app/src/shell/tests/favicons.rs b/crates/zephium-app/src/shell/tests/favicons.rs index 45d602509..63d170b62 100644 --- a/crates/zephium-app/src/shell/tests/favicons.rs +++ b/crates/zephium-app/src/shell/tests/favicons.rs @@ -740,6 +740,7 @@ fn the_launcher_is_sent_its_icons_again_only_after_its_page_loads_afresh() { }; let present = |shell: &mut Shell, session: &str| { shell.handle(Command::SearchScoped { + mini: false, query: String::new(), context: Box::new(zephium_ipc::SearchContext { window_id: window_id.to_string(), diff --git a/crates/zephium-app/src/shell/tests/mini.rs b/crates/zephium-app/src/shell/tests/mini.rs new file mode 100644 index 000000000..60e00dec5 --- /dev/null +++ b/crates/zephium-app/src/shell/tests/mini.rs @@ -0,0 +1,832 @@ +use super::*; + +/// Records which chrome verified each presentation. +#[derive(Default)] +struct WindowChrome { + verified: Mutex, ItemId)>>, +} + +impl GeometryChrome for WindowChrome { + fn position(&self, _frame: ChromeFrame) -> bool { + true + } +} + +impl PresentationChrome for WindowChrome { + fn apply_tab_for_presentation( + &self, + presentation: ChromePresentation, + _done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + self.verified.lock().unwrap().push((None, presentation.id)); + ChromePresentationDispatch::Applied + } + + fn apply_mini_presentation( + &self, + window: WindowId, + presentation: ChromePresentation, + _done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + assert_eq!(presentation.active, Some(presentation.id)); + self.verified + .lock() + .unwrap() + .push((Some(window), presentation.id)); + ChromePresentationDispatch::Applied + } +} + +type Log = Arc>>; + +struct Mini { + shell: Shell, + engine: Arc, + chrome: Arc, + screen: Screen, + log: Log, + store: Arc, +} + +fn mini(hosts: bool) -> Mini { + let store = Arc::new(FakeStore::default()); + let engine = Arc::new(FakeEngine::default()); + engine + .hosts_mini_windows + .store(hosts, std::sync::atomic::Ordering::Release); + let chrome = Arc::new(WindowChrome::default()); + let screen: Screen = Arc::new(Mutex::new(ItemsState { + projection_revision: String::new(), + profile: None, + spaces: Vec::new(), + active_space_id: None, + nodes: Vec::new(), + tabs: Vec::new(), + active: None, + split_group: None, + })); + let log: Log = Arc::new(Mutex::new(Vec::new())); + let (sink, record) = (screen.clone(), log.clone()); + let mut shell = Shell::new_with_failure( + engine.clone(), + store.clone(), + Arc::new(ImmediateAllowAllCompiler), + Box::new(|_| {}), + chrome.clone(), + Box::new(move |projection| { + record.lock().unwrap().push(projection.clone()); + apply_projection(&mut sink.lock().unwrap(), projection); + }), + ); + shell.handle(Command::SetWindowSize(Size::new(1200.0, 800.0))); + shell.handle(Command::Bootstrap); + shell.handle(Command::SetAppSetting { + key: "tabs.external-position".into(), + value: "mini".into(), + }); + Mini { + shell, + engine, + chrome, + screen, + log, + store, + } +} + +impl Mini { + fn opened(&self) -> Vec { + self.log + .lock() + .unwrap() + .iter() + .filter_map(|projection| match projection { + Projection::MiniOpened(opened) => Some(*opened), + _ => None, + }) + .collect() + } + + fn closed(&self) -> Vec { + self.log + .lock() + .unwrap() + .iter() + .filter_map(|projection| match projection { + Projection::MiniClosed(closed) => Some(*closed), + _ => None, + }) + .collect() + } + + fn last_view(&self, window: WindowId) -> Option { + self.log + .lock() + .unwrap() + .iter() + .rev() + .find_map(|projection| match projection { + Projection::Mini(view) if view.window == window => Some(view.clone()), + _ => None, + }) + } + + fn page(&self, window: WindowId) -> ItemId { + let view = self.last_view(window).expect("a mini window projection"); + ItemId::parse(&view.tab.expect("a page").id).unwrap() + } + + /// Runs what the launcher offers for `query`, as Enter does. + fn launcher( + &mut self, + query: &str, + replace: Option, + new_mini: bool, + ) -> OperationDisposition { + let window = self.shell.windows.focused().unwrap(); + let context = zephium_ipc::SearchContext { + window_id: window.id.to_string(), + session_id: "0000000000000001".into(), + request_id: "one".into(), + profile_id: window.profile.to_string(), + space_id: window.space.to_string(), + }; + self.shell.handle(Command::SearchScoped { + mini: new_mini, + query: query.into(), + context: Box::new(context.clone()), + }); + let action = self + .shell + .search + .results + .iter() + .find(|result| matches!(result.action, SearchAction::OpenUrl { .. })) + .map(|result| result.action.clone()) + .expect("the typed address is offered"); + self.shell.handle_operation(Command::RunSearchAction { + context: Box::new(context), + action, + background: false, + replace, + new_mini, + }) + } + + fn search_mini(&mut self, query: &str, mini: bool) { + let window = self.shell.windows.focused().unwrap(); + let context = zephium_ipc::SearchContext { + window_id: window.id.to_string(), + session_id: "0000000000000001".into(), + request_id: "one".into(), + profile_id: window.profile.to_string(), + space_id: window.space.to_string(), + }; + self.shell.handle(Command::SearchScoped { + mini, + query: query.into(), + context: Box::new(context), + }); + } + + fn external_tabs_opened(&self) -> bool { + self.log + .lock() + .unwrap() + .iter() + .any(|projection| matches!(projection, Projection::ExternalTabsOpened)) + } + + /// Opens a link handed over by another application, then builds its + /// window and shows its first document. + fn open_shown(&mut self, url: &str) -> (WindowId, ItemId) { + self.shell.handle(Command::OpenExternal(vec![url.into()])); + let window = self.opened().last().expect("a mini window").window; + self.shell.handle(Command::MiniAttached { + window, + size: Size::new(720.0, 640.0), + }); + let page = self.page(window); + commit_url(&mut self.shell, page, url); + present_committed(&mut self.shell, page, url); + (window, page) + } +} + +#[test] +fn a_link_from_another_app_opens_in_a_mini_window_outside_the_sidebar() { + let mut mini = mini(true); + let tabs_before = last(&mini.screen).tabs.len(); + let active_before = last(&mini.screen).active.clone(); + + mini.shell + .handle(Command::OpenExternal(vec!["https://example.com/".into()])); + + let opened = mini.opened(); + assert_eq!(opened.len(), 1); + let page = mini.page(opened[0].window); + assert!(mini + .engine + .calls() + .iter() + .any(|call| call.starts_with(&format!("create {page} https://example.com/ ")))); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before); + assert_eq!(last(&mini.screen).active, active_before); + assert!(!mini.external_tabs_opened()); +} + +#[test] +fn the_mini_toolbar_verifies_the_page_before_it_appears_in_its_window() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + + assert_eq!( + mini.chrome.verified.lock().unwrap().as_slice(), + &[(Some(window), page)] + ); + let calls = mini.engine.calls(); + assert!(calls + .iter() + .any(|call| call.starts_with(&format!("present {page} ")))); + assert!(calls.contains(&format!("layout@{window} {page}"))); + let shown = mini.last_view(window).unwrap().tab.unwrap(); + assert_eq!(shown.url.as_deref(), Some("https://example.com/")); +} + +#[test] +fn a_mini_window_lays_out_only_once_its_native_window_exists() { + let mut mini = mini(true); + mini.shell + .handle(Command::OpenExternal(vec!["https://example.com/".into()])); + let window = mini.opened()[0].window; + assert!(!mini + .engine + .calls() + .iter() + .any(|call| call.starts_with(&format!("layout@{window} ")))); + + mini.shell.handle(Command::MiniAttached { + window, + size: Size::new(720.0, 640.0), + }); + + assert!(mini + .engine + .layout_regions + .lock() + .unwrap() + .contains(&Some(Rect::new( + 0.0, + crate::MINI_TOOLBAR_HEIGHT, + 720.0, + 640.0 - crate::MINI_TOOLBAR_HEIGHT, + )))); +} + +#[test] +fn opening_in_the_main_window_keeps_the_live_page_and_puts_it_in_front() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::OpenInMain, + }); + + let calls = mini.engine.calls(); + assert!(calls.contains(&format!("release@{window}"))); + assert!(!calls.contains(&format!("close {page}"))); + assert_eq!( + calls + .iter() + .filter(|call| call.starts_with(&format!("create {page} "))) + .count(), + 1 + ); + assert_eq!(active_id(&mini.screen), page); + assert!(last(&mini.screen) + .tabs + .iter() + .any(|tab| tab.id == page.to_string())); + assert_eq!( + mini.closed(), + vec![zephium_ipc::MiniClosedView { + window, + reveal_main: true, + }] + ); + let release = calls + .iter() + .rposition(|call| *call == format!("release@{window}")) + .unwrap(); + let main_layout = calls + .iter() + .rposition(|call| call.starts_with("layout@1 ") && call.contains(&page.to_string())) + .unwrap(); + assert!(release < main_layout); +} + +#[test] +fn closing_a_mini_window_ends_its_page() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::Close, + }); + + let calls = mini.engine.calls(); + assert!(calls.contains(&format!("close {page}"))); + assert!(calls.contains(&format!("release@{window}"))); + assert!(mini.shell.items.tab(page).is_none()); + assert_eq!( + mini.closed(), + vec![zephium_ipc::MiniClosedView { + window, + reveal_main: false, + }] + ); +} + +#[test] +fn a_mini_page_is_out_of_the_main_windows_reach_and_never_saved() { + let mut mini = mini(true); + let (_window, page) = mini.open_shown("https://example.com/"); + + mini.shell.handle(Command::Close(page)); + mini.shell.handle(Command::Activate(page)); + mini.shell.persist(); + + assert!(mini.shell.items.tab(page).is_some()); + assert_ne!(last(&mini.screen).active, Some(page.to_string())); + let saved = mini.store.saved.lock().unwrap().clone().expect("a save"); + assert!(saved.items.iter().all(|item| item.id != page)); +} + +#[test] +fn a_mini_page_is_kept_awake_while_its_window_is_open() { + let mut mini = mini(true); + let (_window, page) = mini.open_shown("https://example.com/"); + + assert!(mini.shell.discard_protected_leaves().contains(&page)); +} + +#[test] +fn the_toolbar_goes_back_and_reloads_only_its_own_page() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + mini.shell.handle(Command::Engine(EngineEvent::NavState { + id: page, + can_go_back: true, + can_go_forward: false, + })); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::Back, + }); + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::Reload, + }); + mini.shell.handle(Command::Mini { + window: window + 100, + action: crate::MiniAction::Reload, + }); + + let calls = mini.engine.calls(); + assert!(calls.contains(&format!("back {page}"))); + assert_eq!( + calls + .iter() + .filter(|call| **call == format!("reload {page}")) + .count(), + 1 + ); +} + +#[test] +fn without_engine_support_links_open_as_tabs_and_bring_the_window_forward() { + let mut mini = mini(false); + let tabs_before = last(&mini.screen).tabs.len(); + + mini.shell + .handle(Command::OpenExternal(vec!["https://example.com/".into()])); + + assert!(mini.opened().is_empty()); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); + assert!(mini.external_tabs_opened()); +} + +#[test] +fn links_past_the_window_limit_open_as_tabs() { + let mut mini = mini(true); + let urls: Vec = (0..=super::super::mini::MAX_MINI_WINDOWS) + .map(|index| format!("https://site{index}.example/")) + .collect(); + let tabs_before = last(&mini.screen).tabs.len(); + + mini.shell.handle(Command::OpenExternal(urls)); + + assert_eq!(mini.opened().len(), super::super::mini::MAX_MINI_WINDOWS); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); + assert!(mini.external_tabs_opened()); +} + +#[test] +fn open_in_zephium_puts_the_page_in_the_space_the_person_picks() { + let mut mini = mini(true); + let home = mini.shell.windows.focused().unwrap().space; + let created = + mini.shell + .handle_operation(Command::Space(Box::new(crate::SpaceCommand::Create { + name: "Work".into(), + look: zephium_core::spaces::SpaceLook::default(), + }))); + assert_ne!(created.outcome, OperationOutcome::Rejected); + let work = mini.shell.windows.focused().unwrap().space; + mini.shell + .handle_operation(Command::Space(Box::new(crate::SpaceCommand::Switch(home)))); + let (window, page) = mini.open_shown("https://example.com/"); + + let view = mini.last_view(window).unwrap(); + assert_eq!( + view.spaces + .iter() + .map(|space| space.id.clone()) + .collect::>(), + vec![home.to_string(), work.to_string()] + ); + assert_eq!(view.space, Some(home.to_string())); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::OpenInSpace(work), + }); + + assert_eq!(mini.shell.windows.focused().unwrap().space, work); + assert!(mini + .shell + .items + .roots(Placement::Space { + space: work, + section: SpaceSection::Today, + }) + .contains(&page)); + assert_eq!(active_id(&mini.screen), page); +} + +#[test] +fn the_mini_launcher_offers_an_open_site_as_a_page_for_a_mini_window() { + let mut mini = mini(true); + let site = active_id(&mini.screen); + commit_url(&mut mini.shell, site, "https://example.com/"); + present_committed(&mut mini.shell, site, "https://example.com/"); + + mini.search_mini("", true); + let row = mini + .shell + .search + .results + .iter() + .find(|result| result.kind == "tab") + .expect("the open site is offered"); + assert_eq!( + row.action, + SearchAction::OpenUrl { + url: "https://example.com/".into() + } + ); + + mini.search_mini("", false); + assert!(mini + .shell + .search + .results + .iter() + .any(|result| matches!(result.action, SearchAction::ActivateTab { .. }))); +} + +#[test] +fn the_mini_launcher_chooses_an_open_site_without_moving_its_tab() { + let mut mini = mini(true); + let site = active_id(&mini.screen); + commit_url(&mut mini.shell, site, "https://example.com/"); + present_committed(&mut mini.shell, site, "https://example.com/"); + let tabs_before = last(&mini.screen).tabs.len(); + + let opened = mini.launcher("example.com", None, true); + + assert_eq!(opened.reason, zephium_ipc::OperationReason::OpenedInMini); + assert_eq!(mini.opened().len(), 1); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before); + assert_eq!(active_id(&mini.screen), site); +} + +#[test] +fn the_mini_launcher_offers_neither_a_blank_tab_nor_a_command() { + let mut mini = mini(true); + assert!(mini + .shell + .items + .tab(active_id(&mini.screen)) + .unwrap() + .url + .is_none()); + + mini.search_mini("", true); + assert!(mini.shell.search.results.is_empty()); + + mini.search_mini("new", true); + assert!(mini + .shell + .search + .results + .iter() + .all(|result| matches!(result.action, SearchAction::OpenUrl { .. }))); + + mini.search_mini("new", false); + assert!(mini + .shell + .search + .results + .iter() + .any(|result| result.kind == "command")); +} + +#[test] +fn an_address_chosen_in_the_mini_launcher_opens_a_mini_window_not_a_tab() { + let mut mini = mini(true); + let tabs_before = last(&mini.screen).tabs.len(); + + let opened = mini.launcher("example.org", None, true); + + assert_eq!(opened.reason, OperationReason::OpenedInMini); + let window = mini.opened().last().expect("a mini window").window; + let page = mini.page(window); + assert!(mini + .engine + .calls() + .iter() + .any(|call| call.starts_with(&format!("create {page} https://example.org")))); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before); +} + +#[test] +fn the_launcher_replaces_the_page_of_the_mini_window_it_edits() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + let tabs_before = last(&mini.screen).tabs.len(); + + let opened = mini.launcher("iana.org", Some(page.to_string()), false); + + assert_eq!(opened.reason, OperationReason::OpenedInMini); + assert!(mini.closed().is_empty()); + assert_eq!(mini.opened().len(), 1); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before); + assert!(mini.shell.items.pending_navigation_request(page).is_some()); + commit_url(&mut mini.shell, page, "https://www.iana.org/"); + present_committed(&mut mini.shell, page, "https://www.iana.org/"); + assert_eq!(mini.page(window), page); + assert!(!mini.engine.calls().contains(&format!("close {page}"))); +} + +#[test] +fn a_private_session_keeps_what_it_searches_out_of_a_mini_window() { + let mut mini = mini(true); + mini.shell.handle(Command::Run("window.newPrivate".into())); + let tabs_before = last(&mini.screen).tabs.len(); + + let opened = mini.launcher("example.org", None, true); + + assert_ne!(opened.reason, OperationReason::OpenedInMini); + assert!(mini.opened().is_empty()); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); +} + +#[test] +fn past_the_window_limit_the_launcher_opens_a_tab_and_the_main_window_comes_forward() { + let mut mini = mini(true); + for index in 0..super::super::mini::MAX_MINI_WINDOWS { + mini.launcher(&format!("site{index}.example"), None, true); + } + let tabs_before = last(&mini.screen).tabs.len(); + + let opened = mini.launcher("one-more.example", None, true); + + assert_ne!(opened.reason, OperationReason::OpenedInMini); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); +} + +#[test] +fn without_mini_windows_the_command_opens_a_new_tab() { + let mut mini = mini(false); + let tabs_before = last(&mini.screen).tabs.len(); + + mini.shell.handle(Command::Run("window.newMini".into())); + + assert!(mini.opened().is_empty()); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); +} + +#[test] +fn keep_on_top_is_the_shells_to_toggle_and_project() { + let mut mini = mini(true); + let (window, _) = mini.open_shown("https://example.com/"); + assert!(!mini.last_view(window).unwrap().pinned); + + for (action, pinned) in [ + (crate::MiniAction::KeepOnTop(None), true), + (crate::MiniAction::KeepOnTop(Some(true)), true), + (crate::MiniAction::KeepOnTop(None), false), + ] { + mini.shell.handle(Command::Mini { window, action }); + assert_eq!(mini.last_view(window).unwrap().pinned, pinned); + } +} + +#[test] +fn the_page_takes_focus_once_its_window_is_built() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + mini.shell.handle(Command::MiniResized { + window, + size: Size::new(700.0, 500.0), + }); + + let focus = format!("focus {page}"); + let calls = mini.engine.calls(); + assert_eq!(calls.iter().filter(|call| **call == focus).count(), 1); +} + +#[test] +fn a_new_mini_window_opens_at_the_size_the_last_one_was_given() { + let mut mini = mini(true); + let (window, _) = mini.open_shown("https://one.example/"); + assert_eq!( + (mini.opened()[0].width, mini.opened()[0].height), + (MINI_WINDOW_SIZE.width, MINI_WINDOW_SIZE.height) + ); + mini.shell.handle(Command::MiniResized { + window, + size: Size::new(500.0, 900.0), + }); + // A size no window can have changes nothing. + for size in [ + Size::new(f64::NAN, 900.0), + Size::new(500.0, -4.0), + Size::new(0.0, 0.0), + Size::new(1.0e9, 900.0), + ] { + mini.shell.handle(Command::MiniResized { window, size }); + } + + mini.shell + .handle(Command::OpenExternal(vec!["https://two.example/".into()])); + + let second = *mini.opened().last().unwrap(); + assert_ne!(second.window, window); + assert_eq!((second.width, second.height), (500.0, 900.0)); +} + +#[test] +fn a_toolbar_reporting_a_size_no_window_has_does_not_attach() { + let mut mini = mini(true); + mini.shell + .handle(Command::OpenExternal(vec!["https://example.com/".into()])); + let window = mini.opened()[0].window; + + mini.shell.handle(Command::MiniAttached { + window, + size: Size::new(f64::INFINITY, 400.0), + }); + + assert!(!mini.shell.mini.windows[&window].attached); + assert!(!mini + .engine + .calls() + .iter() + .any(|call| call.starts_with(&format!("layout@{window} ")))); +} + +#[test] +fn a_window_that_could_not_be_built_hands_its_page_to_the_main_window() { + let mut mini = mini(true); + mini.shell + .handle(Command::OpenExternal(vec!["https://example.com/".into()])); + let window = mini.opened()[0].window; + let page = mini.page(window); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::Unbuilt, + }); + + assert!(mini.shell.mini.windows.is_empty()); + assert!(mini.shell.items.tab(page).is_some()); + assert!(last(&mini.screen) + .tabs + .iter() + .any(|tab| tab.id == page.to_string())); + assert_eq!( + mini.closed(), + vec![zephium_ipc::MiniClosedView { + window, + reveal_main: true, + }] + ); +} + +#[test] +fn a_built_window_ignores_a_late_report_that_it_could_not_be_built() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + + mini.shell.handle(Command::Mini { + window, + action: crate::MiniAction::Unbuilt, + }); + + assert_eq!(mini.shell.mini.windows[&window].page, page); + assert!(mini.closed().is_empty()); +} + +#[test] +fn actions_for_a_window_that_is_not_a_mini_window_do_nothing() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + let main = mini.shell.windows.focused().unwrap().id; + let calls = mini.engine.calls().len(); + + for target in [main, window + 40] { + for action in [ + crate::MiniAction::Close, + crate::MiniAction::OpenInMain, + crate::MiniAction::Reload, + crate::MiniAction::KeepOnTop(None), + crate::MiniAction::Unbuilt, + ] { + mini.shell.handle(Command::Mini { + window: target, + action, + }); + } + } + + assert_eq!(mini.engine.calls().len(), calls); + assert!(mini.closed().is_empty()); + assert_eq!(mini.shell.mini.windows[&window].page, page); +} + +#[test] +fn a_link_a_mini_page_opens_gets_its_own_mini_window() { + let mut mini = mini(true); + let (window, page) = mini.open_shown("https://example.com/"); + let tabs_before = last(&mini.screen).tabs.len(); + + mini.shell + .handle(Command::Engine(EngineEvent::NewWindowRequested { + id: page, + url: "https://popup.example/".into(), + })); + + let opened = mini.opened(); + assert_eq!(opened.len(), 2); + let popup = opened[1].window; + assert_ne!(popup, window); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before); + let child = mini.page(popup); + assert_eq!( + mini.shell.items.get(child).map(|item| item.placement), + mini.shell.items.get(page).map(|item| item.placement) + ); +} + +#[test] +fn past_the_window_limit_a_mini_pages_link_opens_as_a_background_tab() { + let mut mini = mini(true); + let urls: Vec = (0..super::super::mini::MAX_MINI_WINDOWS) + .map(|index| format!("https://site{index}.example/")) + .collect(); + mini.shell.handle(Command::OpenExternal(urls)); + let window = mini.opened()[0].window; + mini.shell.handle(Command::MiniAttached { + window, + size: Size::new(720.0, 640.0), + }); + let page = mini.page(window); + commit_url(&mut mini.shell, page, "https://site0.example/"); + let active = mini.shell.windows.focused().unwrap().active; + let tabs_before = last(&mini.screen).tabs.len(); + + mini.shell + .handle(Command::Engine(EngineEvent::NewWindowRequested { + id: page, + url: "https://popup.example/".into(), + })); + + assert_eq!(mini.opened().len(), super::super::mini::MAX_MINI_WINDOWS); + assert_eq!(last(&mini.screen).tabs.len(), tabs_before + 1); + assert_eq!(mini.shell.windows.focused().unwrap().active, active); +} diff --git a/crates/zephium-app/src/shell/tests/mod.rs b/crates/zephium-app/src/shell/tests/mod.rs index 76c6a659d..2d518cbcb 100644 --- a/crates/zephium-app/src/shell/tests/mod.rs +++ b/crates/zephium-app/src/shell/tests/mod.rs @@ -383,6 +383,7 @@ pub(crate) struct FakeEngine { >, pub(crate) extension_data_changes: Mutex>, + hosts_mini_windows: std::sync::atomic::AtomicBool, } #[derive(Clone, Copy, Debug, PartialEq)] @@ -893,6 +894,18 @@ impl Engine for FakeEngine { self.previews.lock().unwrap().push(preview); self.native_admission() } + fn hosts_mini_windows(&self) -> bool { + self.hosts_mini_windows + .load(std::sync::atomic::Ordering::Acquire) + } + fn release_window(&self, window: WindowId) -> NativeDispatch { + self.log(format!("release@{window}")); + self.native_admission() + } + fn focus_page(&self, id: ItemId) -> NativeDispatch { + self.log(format!("focus {id}")); + NativeDispatch::Scheduled + } fn raise_chrome( &self, window: WindowId, @@ -2340,6 +2353,10 @@ fn apply_projection(view: &mut ItemsState, p: Projection) { Projection::RecentlyClosed(_) => {} Projection::MediaPlayer(_) => {} Projection::OpenNote { .. } => {} + Projection::MiniOpened(_) + | Projection::Mini(_) + | Projection::MiniClosed(_) + | Projection::ExternalTabsOpened => {} } } @@ -2674,6 +2691,7 @@ mod history; mod history_list; mod lookup; mod media; +mod mini; #[path = "navigation.rs"] mod navigation_tests; mod notes; diff --git a/crates/zephium-app/src/shell/tests/operations.rs b/crates/zephium-app/src/shell/tests/operations.rs index cafef2b95..928d66988 100644 --- a/crates/zephium-app/src/shell/tests/operations.rs +++ b/crates/zephium-app/src/shell/tests/operations.rs @@ -1032,6 +1032,7 @@ fn scoped_launcher_actions_reject_stale_requests_and_unoffered_actions() { space_id: window.space.to_string(), }; shell.handle(Command::SearchScoped { + mini: false, query: String::new(), context: Box::new(context.clone()), }); @@ -1043,6 +1044,7 @@ fn scoped_launcher_actions_reject_stale_requests_and_unoffered_actions() { }, background: false, replace: None, + new_mini: false, }); assert_eq!(forged.reason, OperationReason::InvalidScope); shell.handle(Command::CancelSearch { @@ -1053,6 +1055,7 @@ fn scoped_launcher_actions_reject_stale_requests_and_unoffered_actions() { action: SearchAction::ActivateTab { id: id.to_string() }, background: false, replace: None, + new_mini: false, }); assert_eq!(stale.reason, OperationReason::InvalidScope); } @@ -1071,6 +1074,7 @@ fn a_background_launcher_open_keeps_the_current_tab_and_the_search() { space_id: window.space.to_string(), }; shell.handle(Command::SearchScoped { + mini: false, query: "example.com".into(), context: Box::new(context.clone()), }); @@ -1088,6 +1092,7 @@ fn a_background_launcher_open_keeps_the_current_tab_and_the_search() { action: action.clone(), background: true, replace: None, + new_mini: false, }); // Deferred: the new view settles once native has created it. assert!(matches!( @@ -1115,6 +1120,7 @@ fn an_address_chosen_while_editing_replaces_the_page_in_front() { space_id: window.space.to_string(), }; shell.handle(Command::SearchScoped { + mini: false, query: "example.com".into(), context: Box::new(context.clone()), }); @@ -1141,6 +1147,7 @@ fn an_address_chosen_while_editing_replaces_the_page_in_front() { action, background: false, replace: Some(active.to_string()), + new_mini: false, }); assert!(matches!( opened.outcome, diff --git a/crates/zephium-app/src/shell/tests/search.rs b/crates/zephium-app/src/shell/tests/search.rs index ad56b2fa2..b3627cc9d 100644 --- a/crates/zephium-app/src/shell/tests/search.rs +++ b/crates/zephium-app/src/shell/tests/search.rs @@ -316,6 +316,7 @@ fn newtab_search_cannot_execute_after_its_tab_has_navigated() { request_id: "request-1".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "example.com".into(), context: Box::new(context.clone()), }); @@ -326,7 +327,7 @@ fn newtab_search_cannot_execute_after_its_tab_has_navigated() { id, input: "other.example".into(), }); - let disposition = shell.operation_run_search_action(context, action, false, None); + let disposition = shell.operation_run_search_action(context, action, false, None, false); assert_eq!(disposition.outcome, OperationOutcome::Rejected); } @@ -377,6 +378,7 @@ fn empty_local_scope_stays_pending_until_its_providers_finish() { request_id: "first".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "@notes first".into(), context: Box::new(context.clone()), }); @@ -386,6 +388,7 @@ fn empty_local_scope_stays_pending_until_its_providers_finish() { ..context.clone() }; shell.handle(Command::SearchScoped { + mini: false, query: "@notes second".into(), context: Box::new(next.clone()), }); @@ -436,6 +439,7 @@ fn late_providers_extend_their_own_section_without_reordering_the_list() { request_id: "first".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "example".into(), context: Box::new(context.clone()), }); @@ -517,6 +521,7 @@ fn one_talkative_provider_cannot_starve_the_other_sections() { request_id: "first".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "example".into(), context: Box::new(context.clone()), }); @@ -568,6 +573,7 @@ fn new_tab_offers_places_to_go_and_leaves_commands_to_the_launcher() { request_id: "request-1".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "reload".into(), context: Box::new(newtab.clone()), }); @@ -589,6 +595,7 @@ fn new_tab_offers_places_to_go_and_leaves_commands_to_the_launcher() { ..newtab }; shell.handle(Command::SearchScoped { + mini: false, query: "reload".into(), context: Box::new(panel), }); @@ -637,6 +644,7 @@ fn history_reaches_the_field_through_the_real_store_and_read_queue() { request_id: "request-1".into(), }; shell.handle(Command::SearchScoped { + mini: false, query: "notion".into(), context: Box::new(context), }); diff --git a/crates/zephium-app/src/shell/view_lifecycle.rs b/crates/zephium-app/src/shell/view_lifecycle.rs index e1dd028f4..7e5723036 100644 --- a/crates/zephium-app/src/shell/view_lifecycle.rs +++ b/crates/zephium-app/src/shell/view_lifecycle.rs @@ -715,6 +715,7 @@ impl Shell { // rechecks URL, loading, visibility, idle age, and the current budget. pub(super) fn maintain_views(&mut self) -> bool { self.expire_tab_preview(std::time::Instant::now()); + self.prune_mini_windows(); self.crash .crashes .retain(|id, _| self.items.tab(*id).is_some()); @@ -735,7 +736,7 @@ impl Shell { .capacity_blocked .retain(|id, _| self.items.tab(*id).is_some_and(|tab| !tab.has_view())); self.retry_capacity_requests(); - let shown: std::collections::HashSet = if self.window_visible { + let mut shown: std::collections::HashSet = if self.window_visible { let mut shown: std::collections::HashSet = self .visible_tree() .map(|t| t.tabs().into_iter().collect()) @@ -756,6 +757,9 @@ impl Shell { } else { std::collections::HashSet::new() }; + // A mini window is its own window: the main one being minimized + // does not hide its page. + shown.extend(self.mini_pages()); self.residency .recent .retain(|id| self.items.tab(*id).is_some()); @@ -994,7 +998,7 @@ impl Shell { } pub(super) fn discard_protected_leaves(&self) -> std::collections::HashSet { - let mut protected = std::collections::HashSet::new(); + let mut protected: std::collections::HashSet = self.mini_pages().collect(); let Some(window) = self.windows.focused() else { return protected; }; diff --git a/crates/zephium-app/src/shell/window_layout.rs b/crates/zephium-app/src/shell/window_layout.rs index 063b50a80..7fb8f4214 100644 --- a/crates/zephium-app/src/shell/window_layout.rs +++ b/crates/zephium-app/src/shell/window_layout.rs @@ -67,8 +67,15 @@ impl Shell { } /// A relayout that is one step of a deliberate change of shape, which - /// the chrome and the content carry out as a journey. + /// the chrome and the content carry out as a journey. mini windows lay + /// out with it, since what changed may be their page. pub(super) fn relayout_with(&self, travel: bool) -> NativeDispatch { + let main = self.relayout_main_with(travel); + self.relayout_mini_windows(); + main + } + + fn relayout_main_with(&self, travel: bool) -> NativeDispatch { let filling = self.window_filling_fullscreen(); let Some(win) = self.windows.focused() else { return NativeDispatch::Rejected; diff --git a/crates/zephium-app/src/shell/work_authoring.rs b/crates/zephium-app/src/shell/work_authoring.rs index c8fefacba..f08ce322b 100644 --- a/crates/zephium-app/src/shell/work_authoring.rs +++ b/crates/zephium-app/src/shell/work_authoring.rs @@ -112,7 +112,10 @@ impl crate::Shell { .. } => self.items.get(*tab).is_some_and(|item| { let (zephium_core::item::Placement::Favorites { space } - | zephium_core::item::Placement::Space { space, .. }) = item.placement; + | zephium_core::item::Placement::Space { space, .. }) = item.placement + else { + return false; + }; item.tab().is_some() && self .spaces diff --git a/crates/zephium-core/src/commands.rs b/crates/zephium-core/src/commands.rs index 508b3c913..ea980b7a4 100644 --- a/crates/zephium-core/src/commands.rs +++ b/crates/zephium-core/src/commands.rs @@ -137,6 +137,27 @@ pub const REGISTRY: &[CommandSpec] = &[ Keys::same("CmdOrCtrl+Shift+N"), Group::File, ), + // Opens the launcher for a page of its own in a mini window. + command( + "window.newMini", + "New Mini Window", + Keys::same("CmdOrCtrl+Shift+M"), + Group::File, + ), + // Keys a mini window answers while it is in front. Elsewhere they do + // nothing, so they stay out of the menus. + command( + "mini.openInMain", + "Open Mini Window in Zephium", + Keys::same("CmdOrCtrl+O"), + Group::Keys, + ), + command( + "mini.keepOnTop", + "Keep Mini Window on Top", + Keys::NONE, + Group::Keys, + ), command( "window.closePrivate", "Close Private Window", diff --git a/crates/zephium-core/src/item.rs b/crates/zephium-core/src/item.rs index 5d4a888cd..16935ed68 100644 --- a/crates/zephium-core/src/item.rs +++ b/crates/zephium-core/src/item.rs @@ -3,7 +3,7 @@ use url::Url; -use crate::ids::{ItemId, SpaceId}; +use crate::ids::{ItemId, ProfileId, SpaceId}; pub const MAX_PAGE_TITLE_CHARS: usize = 512; @@ -99,8 +99,9 @@ pub enum SpaceSection { Today, } -/// Where an item lives: a space's Essentials (`Favorites`), or a section of a -/// space. Children of a folder share the folder's placement. +/// Where an item lives: a space's Essentials (`Favorites`), a section of a +/// space, or a mini window. Children of a folder share the folder's +/// placement. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum Placement { Favorites { @@ -110,6 +111,12 @@ pub enum Placement { space: SpaceId, section: SpaceSection, }, + /// The one page of a mini window: never in the sidebar, never saved + /// with the session, and out of every space's scope until it moves into + /// one. + Mini { + profile: ProfileId, + }, } #[derive(Clone, Debug)] diff --git a/crates/zephium-core/src/items.rs b/crates/zephium-core/src/items.rs index 69d030433..a8bd8506b 100644 --- a/crates/zephium-core/src/items.rs +++ b/crates/zephium-core/src/items.rs @@ -357,9 +357,13 @@ impl Items { .items .iter() .filter_map(|(id, item)| { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = - item.placement; - removed_spaces.contains(&space).then_some(*id) + let owned = match item.placement { + Placement::Favorites { space } | Placement::Space { space, .. } => { + removed_spaces.contains(&space) + } + Placement::Mini { profile } => profile == spaces.profile(), + }; + owned.then_some(*id) }) .collect(); if owned.is_empty() { diff --git a/crates/zephium-core/src/ports/engine.rs b/crates/zephium-core/src/ports/engine.rs index aa1269b8d..8f926ada0 100644 --- a/crates/zephium-core/src/ports/engine.rs +++ b/crates/zephium-core/src/ports/engine.rs @@ -952,6 +952,21 @@ pub trait Engine { region: Option, ) -> NativeDispatch; fn set_drop_indicator(&self, window: WindowId, preview: Option) -> NativeDispatch; + /// Whether a window other than the main one can host a page in its own + /// native window, as a mini window does. + fn hosts_mini_windows(&self) -> bool { + false + } + /// Retires the stage of a window other than the main one before its + /// native window goes away. A later layout for it is refused. + fn release_window(&self, _window: WindowId) -> NativeDispatch { + NativeDispatch::Unsupported + } + /// Gives a page the keyboard inside its own window, as a mini window's + /// page takes it when the window opens. + fn focus_page(&self, _id: ItemId) -> NativeDispatch { + NativeDispatch::Unsupported + } /// A transient guide in window coordinates; never changes pane geometry. fn set_resize_guide(&self, _window: WindowId, _zone: Option) -> NativeDispatch { NativeDispatch::Unsupported diff --git a/crates/zephium-core/src/preferences.rs b/crates/zephium-core/src/preferences.rs index 8341e231d..693560c4b 100644 --- a/crates/zephium-core/src/preferences.rs +++ b/crates/zephium-core/src/preferences.rs @@ -242,7 +242,9 @@ pub fn value_allowed(key: &str, value: &str) -> bool { "ui.theme-contrast" => crate::theme::contrast_allowed(value), "tabs.new-position" => matches!(value, "end" | "after-current"), // Where a link handed over by another application opens. - "tabs.external-position" => matches!(value, "new-tab" | "end" | "after-current"), + "tabs.external-position" => { + matches!(value, "new-tab" | "end" | "after-current" | "mini") + } // How long a Today tab may sit unused before it closes into History. "tabs.archive" => matches!(value, "never" | "12h" | "1d" | "7d"), "tabs.close-button" => matches!(value, "hover" | "always"), @@ -612,7 +614,7 @@ mod tests { for value in ["", "0", "30d", "12 hours", "Never"] { assert!(!value_allowed("tabs.archive", value), "{value:?}"); } - for value in ["new-tab", "end", "after-current"] { + for value in ["new-tab", "end", "after-current", "mini"] { assert!(value_allowed("tabs.external-position", value)); } assert!(!value_allowed("tabs.external-position", "window")); diff --git a/crates/zephium-core/src/session.rs b/crates/zephium-core/src/session.rs index 97aa8c232..f335b28b1 100644 --- a/crates/zephium-core/src/session.rs +++ b/crates/zephium-core/src/session.rs @@ -294,8 +294,15 @@ pub fn restore(state: SessionState) -> Restored { let mut items = Items::default(); let mut browser_tabs = HashSet::new(); for i in state.items.into_iter().take(MAX_SESSION_ITEMS) { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = i.placement; - if spaces.get(space).is_none() { + let placement_ok = match i.placement { + Placement::Favorites { space } | Placement::Space { space, .. } => { + spaces.get(space).is_some() + } + // A mini window's page is never saved; one in a session came + // from somewhere else. + Placement::Mini { .. } => false, + }; + if !placement_ok { continue; } let kind = match i.kind { @@ -431,11 +438,13 @@ fn item_in_space_scope(items: &Items, spaces: &Spaces, id: ItemId, space: SpaceI let Some(item) = items.get(id).filter(|item| item.tab().is_some()) else { return false; }; - let (Placement::Favorites { space: item_space } - | Placement::Space { - space: item_space, .. - }) = item.placement; - item_space == space + match item.placement { + Placement::Favorites { space: item_space } + | Placement::Space { + space: item_space, .. + } => item_space == space, + Placement::Mini { .. } => false, + } } fn valid_split_tree(tree: &Pane, items: &Items, spaces: &Spaces, space: SpaceId) -> bool { diff --git a/crates/zephium-core/src/windows.rs b/crates/zephium-core/src/windows.rs index eb74cec91..6cd2b41e1 100644 --- a/crates/zephium-core/src/windows.rs +++ b/crates/zephium-core/src/windows.rs @@ -12,7 +12,7 @@ use crate::split::Pane; pub enum WindowKind { Main, App { origin: String }, - Little, + Mini, } #[derive(Debug)] @@ -68,6 +68,30 @@ impl Windows { id } + /// A window that leaves focus where it was, as a mini window does: the + /// main window stays the one commands and layout follow. + pub fn create_unfocused( + &mut self, + kind: WindowKind, + profile: ProfileId, + space: SpaceId, + size: Size, + ) -> WindowId { + let focused = self.focused; + let id = self.create(kind, profile, space, size); + self.focused = focused; + id + } + + /// Removes a window that is not focused. The focused window stays. + pub fn remove(&mut self, id: WindowId) -> Option { + if self.focused == Some(id) { + return None; + } + self.order.retain(|window| *window != id); + self.map.remove(&id) + } + pub fn get(&self, id: WindowId) -> Option<&Window> { self.map.get(&id) } @@ -93,3 +117,28 @@ impl Windows { self.map.values_mut() } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::ids::{ProfileId, SpaceId}; + + #[test] + fn an_unfocused_window_leaves_focus_and_is_removed_alone() { + let mut windows = Windows::default(); + let profile = ProfileId::generate(); + let space = SpaceId::generate(); + let main = windows.create(WindowKind::Main, profile, space, Size::new(800.0, 600.0)); + let mini = + windows.create_unfocused(WindowKind::Mini, profile, space, Size::new(400.0, 300.0)); + assert_ne!(main, mini); + assert_eq!(windows.focused().map(|window| window.id), Some(main)); + assert!(windows.remove(main).is_none()); + assert_eq!( + windows.remove(mini).map(|window| window.kind), + Some(WindowKind::Mini) + ); + assert_eq!(windows.iter().count(), 1); + assert_eq!(windows.focused().map(|window| window.id), Some(main)); + } +} diff --git a/crates/zephium-engine/src/host/dispatch.rs b/crates/zephium-engine/src/host/dispatch.rs index 5ce8bb1ff..c8f6afd94 100644 --- a/crates/zephium-engine/src/host/dispatch.rs +++ b/crates/zephium-engine/src/host/dispatch.rs @@ -513,6 +513,8 @@ pub(crate) fn install( #[cfg(target_os = "macos")] next_fullscreen_retirement: 0, stages: HashMap::new(), + #[cfg(any(target_os = "macos", target_os = "windows"))] + window_parents: HashMap::new(), native_terminal_failure, #[cfg(not(target_os = "windows"))] shutdown_completion: None, diff --git a/crates/zephium-engine/src/host/mod.rs b/crates/zephium-engine/src/host/mod.rs index 798b56e23..b5d108b97 100644 --- a/crates/zephium-engine/src/host/mod.rs +++ b/crates/zephium-engine/src/host/mod.rs @@ -680,6 +680,11 @@ pub(crate) struct EngineHost { next_fullscreen_retirement: u64, #[cfg(target_os = "macos")] stages: HashMap>, + // Windows other than the main one, such as a mini window, host their + // stage in their own native window. A missing entry is the main window; + // `None` is a window that was released and may not have a stage again. + #[cfg(any(target_os = "macos", target_os = "windows"))] + window_parents: HashMap>, #[cfg(not(target_os = "macos"))] stages: HashMap, // Native callback admission failure, exhausted stage retries, or diff --git a/crates/zephium-engine/src/host/page_ops.rs b/crates/zephium-engine/src/host/page_ops.rs index ee50f8514..dac8bf705 100644 --- a/crates/zephium-engine/src/host/page_ops.rs +++ b/crates/zephium-engine/src/host/page_ops.rs @@ -244,6 +244,34 @@ impl EngineHost { } } + /// Gives the page the keyboard inside the window that shows it. False + /// when it is in no window yet. + #[cfg(any(target_os = "macos", target_os = "windows"))] + pub(crate) fn focus_page(&self, id: ItemId) -> bool { + let Some(view) = self.views.get(&id) else { + return false; + }; + #[cfg(target_os = "macos")] + { + let page = crate::platform::imp::native_webview(view); + page.window() + .is_some_and(|window| window.makeFirstResponder(Some(&page))) + } + #[cfg(target_os = "windows")] + { + use webview2_com::Microsoft::Web::WebView2::Win32::COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC; + use wry::WebViewExtWindows; + // SAFETY: the controller belongs to this live view and this runs + // on its UI thread. + unsafe { + view.view + .controller() + .MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC) + } + .is_ok() + } + } + /// One step of finding text in `id`. Results travel the view's own event /// permit, so a result from a view since replaced is never delivered. pub(crate) fn find(&mut self, id: ItemId, request: Option) { diff --git a/crates/zephium-engine/src/host/stages.rs b/crates/zephium-engine/src/host/stages.rs index 772bf58e4..924e86c27 100644 --- a/crates/zephium-engine/src/host/stages.rs +++ b/crates/zephium-engine/src/host/stages.rs @@ -3,7 +3,7 @@ use std::sync::Arc; #[cfg(any(target_os = "macos", target_os = "windows"))] use raw_window_handle::RawWindowHandle; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "windows"))] use wry::WebView; use zephium_core::geometry::Rect; @@ -18,7 +18,7 @@ use super::dispatch::try_with_stage_failure; #[cfg(target_os = "windows")] use super::dispatch::with_renderer_exit; use super::EngineHost; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "windows"))] use super::ParentHandle; #[cfg(target_os = "macos")] @@ -267,7 +267,11 @@ impl EngineHost { } return applied; }; - if !stage_set_frame(&stage, &self.parent, r, motion) { + let Some(parent) = self.parent_for(window) else { + stage.abort_content_update(update_epoch); + return false; + }; + if !stage_set_frame(&stage, parent, r, motion) { stage.abort_content_update(update_epoch); return false; } @@ -287,6 +291,17 @@ impl EngineHost { }; let mut inserted = false; if !stage.has_view(*id) { + // A page moving between windows, as a mini window's page + // does when it opens in the main window, leaves its old stage + // first so no two stages ever claim one native view. + for (other, previous) in &self.stages { + if *other != window && previous.has_view(*id) { + previous.remove_view(*id); + } + } + if !stage.content_update_is_current(update_epoch) { + return !stage.has_terminal_failure(); + } if let Some(native_view) = webview_nsview(view) { if !stage.insert_view(*id, native_view, view.presentation_permit.clone()) { stage.abort_content_update(update_epoch); @@ -410,6 +425,13 @@ impl EngineHost { let Some(generation) = view.event_permit.active_token() else { return false; }; + // A page moving between windows, as a mini window's page + // does when it opens in the main window, leaves its old + // stage and moves under this stage's window first, so no + // two stages ever claim one native view. + if !self.move_view_to_stage(window, *id, view, &stage) { + return false; + } if !stage.insert_view(*id, view, generation, view.presentation_permit.clone()) { return false; } @@ -502,10 +524,7 @@ impl EngineHost { if let Some(stage) = self.stages.get(&window) { return Some(stage.clone()); } - let RawWindowHandle::Win32(h) = self.parent.0 else { - return None; - }; - let parent = HWND(h.hwnd.get() as *mut _); + let parent = win32_parent(self.parent_for(window)?)?; let native_terminal_failure = self.native_terminal_failure.clone(); let stage = Stage::new(parent, GAP, move |id, generation| { let admitted = with_renderer_exit(id, move |host| { @@ -584,7 +603,7 @@ impl EngineHost { return Some(stage.clone()); } let mtm = MainThreadMarker::new()?; - let content = content_view(&self.parent)?; + let content = content_view(self.parent_for(window)?)?; let native_terminal_failure = self.native_terminal_failure.clone(); let stage = ContentStage::new( mtm, @@ -614,6 +633,142 @@ impl EngineHost { } } +#[cfg(any(target_os = "macos", target_os = "windows"))] +impl EngineHost { + /// `None` for a window already released: a late layout for it must not + /// build a stage in the main window instead. + fn parent_for(&self, window: WindowId) -> Option<&ParentHandle> { + match self.window_parents.get(&window) { + Some(parent) => parent.as_ref(), + None => Some(&self.parent), + } + } + + /// Gives `window` its own native window. Its stage is built inside that + /// window on its first layout. The main window, a window already given + /// one, and a handle of another platform's kind are refused. + pub(crate) fn attach_window(&mut self, window: WindowId, handle: RawWindowHandle) -> bool { + if self.window_parents.contains_key(&window) + || self.stages.contains_key(&window) + || !native_window_handle(&handle) + || same_native_window(&handle, &self.parent.0) + { + return false; + } + self.window_parents + .insert(window, Some(ParentHandle(handle))); + true + } + + /// Retires the stage of a window that is going away. A page still on it + /// leaves with the stage and joins another window on its next layout; + /// until then it is kept, hidden, by the main window, so it never goes + /// with the native window it was shown in. + pub(crate) fn release_window(&mut self, window: WindowId) { + if !self + .window_parents + .get(&window) + .is_some_and(Option::is_some) + { + return; + } + if let Some(stage) = self.stages.remove(&window) { + #[cfg(target_os = "macos")] + { + for id in stage.attached_items().unwrap_or_default() { + stage.remove_view(id); + } + stage.retire(); + } + #[cfg(target_os = "windows")] + { + use wry::WebViewExtWindows; + let main = win32_parent(&self.parent); + for id in stage.attached_items() { + stage.remove_view(id); + if let (Some(view), Some(main)) = (self.views.get(&id), main) { + let _ = view.set_visible(false); + if view.reparent(main.0 as isize).is_err() { + eprintln!("engine: a released window's page stayed in place"); + } + } + } + if let Some(parent) = stage.parent_window() { + crate::platform::imp::forget_window_caption_offset(parent.0 as isize); + } + } + } + self.window_parents.insert(window, None); + } +} + +#[cfg(any(target_os = "macos", target_os = "windows"))] +fn native_window_handle(handle: &RawWindowHandle) -> bool { + if cfg!(target_os = "macos") { + matches!(handle, RawWindowHandle::AppKit(_)) + } else { + matches!(handle, RawWindowHandle::Win32(_)) + } +} + +#[cfg(any(target_os = "macos", target_os = "windows"))] +fn same_native_window(left: &RawWindowHandle, right: &RawWindowHandle) -> bool { + match (left, right) { + (RawWindowHandle::AppKit(left), RawWindowHandle::AppKit(right)) => { + left.ns_view == right.ns_view + } + (RawWindowHandle::Win32(left), RawWindowHandle::Win32(right)) => left.hwnd == right.hwnd, + _ => false, + } +} + +#[cfg(target_os = "windows")] +fn win32_parent(parent: &ParentHandle) -> Option { + let RawWindowHandle::Win32(h) = parent.0 else { + return None; + }; + Some(HWND(h.hwnd.get() as *mut _)) +} + +#[cfg(target_os = "windows")] +impl EngineHost { + /// Takes `id` off every other window's stage and puts its native window + /// under `stage`'s window. False when the move was refused natively; the + /// page then stays where it was and the layout is not applied. + fn move_view_to_stage( + &self, + window: WindowId, + id: ItemId, + view: &WebView, + stage: &Stage, + ) -> bool { + use wry::WebViewExtWindows; + for (other, previous) in &self.stages { + if *other != window && previous.has_view(id) { + previous.remove_view(id); + } + } + let Some(parent) = stage.parent_window() else { + return false; + }; + // A page already under this window, as every main-window tab is, + // is left alone: only a page crossing windows is reparented. + let mut current = HWND::default(); + // SAFETY: the controller belongs to this live view and this runs on + // its UI thread. + if unsafe { view.controller().ParentWindow(&mut current) }.is_ok() && current == parent { + return true; + } + match view.reparent(parent.0 as isize) { + Ok(()) => true, + Err(error) => { + eprintln!("engine: a page could not move to its window: {error}"); + false + } + } + } +} + #[cfg(target_os = "macos")] fn content_view(parent: &ParentHandle) -> Option> { if let RawWindowHandle::AppKit(h) = parent.0 { diff --git a/crates/zephium-engine/src/lib.rs b/crates/zephium-engine/src/lib.rs index 0f8050018..f092d0702 100644 --- a/crates/zephium-engine/src/lib.rs +++ b/crates/zephium-engine/src/lib.rs @@ -559,7 +559,8 @@ pub fn run_windows_agentic_semantic_probe( pub use platform::windows::{ browser_process_record, detach_privileged_environment_update, finalize_privileged_environment_registrations, generation_report_lines, - install_privileged_environment_registration, WindowsLeftoverProcesses, + install_privileged_environment_registration, privileged_environment_process, + WindowsLeftoverProcesses, }; /// Runs the isolated-principal native WebKit probe on the process main thread. @@ -1831,6 +1832,20 @@ impl WebviewEngine { }); } + /// Gives `window` its own native window, such as a mini window, on the + /// main thread before its first layout. `false` leaves it without one. + #[cfg(any(target_os = "macos", target_os = "windows"))] + pub fn attach_window(&self, window: WindowId, handle: RawWindowHandle) -> bool { + #[cfg(target_os = "macos")] + if objc2_foundation::MainThreadMarker::new().is_none() { + return false; + } + let attached = std::rc::Rc::new(std::cell::Cell::new(false)); + let result = attached.clone(); + host::try_with(move |host| result.set(host.attach_window(window, handle))); + attached.get() + } + /// Installs the profile-scoped download service before raw views are made. pub fn initialize_downloads( &self, @@ -3307,6 +3322,46 @@ impl Engine for WebviewEngine { } } + fn hosts_mini_windows(&self) -> bool { + cfg!(any(target_os = "macos", target_os = "windows")) + } + + fn focus_page(&self, id: ItemId) -> NativeDispatch { + #[cfg(any(target_os = "macos", target_os = "windows"))] + { + NativeDispatch::from_scheduled(self.run(move || { + let _ = host::try_with(move |host| { + if !host.focus_page(id) { + eprintln!("engine: a page was in no window to take the keyboard"); + } + }); + })) + } + #[cfg(not(any(target_os = "macos", target_os = "windows")))] + { + let _ = id; + NativeDispatch::Unsupported + } + } + + fn release_window(&self, window: WindowId) -> NativeDispatch { + #[cfg(any(target_os = "macos", target_os = "windows"))] + { + self.stage_motion + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .remove(&window); + NativeDispatch::from_scheduled(self.run(move || { + let _ = host::try_with(move |host| host.release_window(window)); + })) + } + #[cfg(not(any(target_os = "macos", target_os = "windows")))] + { + let _ = window; + NativeDispatch::Unsupported + } + } + fn hint_stage_motion(&self, window: WindowId, motion: StageMotion) -> NativeDispatch { self.stage_motion .lock() diff --git a/crates/zephium-engine/src/platform/windows/mod.rs b/crates/zephium-engine/src/platform/windows/mod.rs index 55d03931d..8d953d81d 100644 --- a/crates/zephium-engine/src/platform/windows/mod.rs +++ b/crates/zephium-engine/src/platform/windows/mod.rs @@ -1767,6 +1767,19 @@ pub fn install_privileged_environment_registration( } } +/// The browser process of the privileged environment registered for +/// `label`, whose exit the final teardown proves. A WebView that joins that +/// process, as a mini window's toolbar joins the launcher's, is covered by +/// that proof and registers nothing of its own. +pub fn privileged_environment_process(label: &str) -> Option { + PRIVILEGED_ENVIRONMENT_REGISTRATIONS.with(|registrations| { + let registrations = registrations.try_borrow().ok()?; + registrations + .get(label) + .map(|registration| registration.exit_guard.expected_process_id()) + }) +} + /// Remove only the runtime-update event when a privileged window is /// destroyed. Its exact Environment5/HANDLE proof stays registered through /// `run_return` and the bounded final apartment pump. diff --git a/crates/zephium-engine/src/platform/windows/stage.rs b/crates/zephium-engine/src/platform/windows/stage.rs index 2316e5537..680ab7c6d 100644 --- a/crates/zephium-engine/src/platform/windows/stage.rs +++ b/crates/zephium-engine/src/platform/windows/stage.rs @@ -547,6 +547,14 @@ impl Stage { self.state.borrow().views.contains_key(&id) } + /// The pages this stage holds now. + pub fn attached_items(&self) -> Vec { + self.state + .try_borrow() + .map(|state| state.views.keys().copied().collect()) + .unwrap_or_default() + } + /// Marks the page shown fullscreen, which the shell lays over the whole /// window: it loses its rounded corners and is raised above siblings. pub fn set_fullscreen(&self, id: Option) { diff --git a/crates/zephium-ipc/src/lib.rs b/crates/zephium-ipc/src/lib.rs index 327cc87f0..17e87e20b 100644 --- a/crates/zephium-ipc/src/lib.rs +++ b/crates/zephium-ipc/src/lib.rs @@ -803,6 +803,8 @@ pub struct PanelState { pub seed: Option, /// The tab whose address is being edited; it is no destination of its own. pub seed_tab: Option, + /// An address chosen in this presentation opens in a new mini window. + pub mini: bool, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] @@ -1308,6 +1310,47 @@ pub enum WorkFolderAdmitV1 { Refused { not_a_folder: bool }, } +/// A mini window's chrome: its window and the one page in it, if any yet. +/// The page's URL and title are untrusted and only ever shown as text. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] +pub struct MiniView { + #[specta(type = f64)] + pub window: u64, + pub tab: Option, + /// Where "Open in Zephium" can put the page: its profile's spaces, in + /// sidebar order. + pub spaces: Vec, + /// The space "Open in Zephium" uses unless the person picks another. + pub space: Option, + /// The window stays above other applications' windows. + pub pinned: bool, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)] +pub struct MiniSpaceView { + pub id: String, + pub name: String, +} + +/// The shell made a mini window; the desktop builds its native window with +/// this content size. +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Type)] +pub struct MiniOpenedView { + #[specta(type = f64)] + pub window: u64, + pub width: f64, + pub height: f64, +} + +/// The shell let a mini window go. `reveal_main` brings the main window +/// forward because the page just moved into it. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)] +pub struct MiniClosedView { + #[specta(type = f64)] + pub window: u64, + pub reveal_main: bool, +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Type)] pub struct LayoutState { pub dividers: Vec, @@ -1348,6 +1391,8 @@ pub enum OperationOutcome { #[serde(rename_all = "snake_case")] pub enum OperationReason { MutationApplied, + /// The address went to a mini window, so the main window stays behind. + OpenedInMini, StateUnchanged, InvalidScope, NoFocusedWindow, @@ -1818,6 +1863,12 @@ pub enum Projection { RecentlyClosed(Vec), /// The sidebar's player, sent when it changes; `None` hides it. MediaPlayer(Option), + MiniOpened(MiniOpenedView), + Mini(MiniView), + MiniClosed(MiniClosedView), + /// Links another application handed over opened as tabs, so the main + /// window comes forward. A link that opened a mini window does not. + ExternalTabsOpened, } /// Shared Rust-owned Notes/Tasks wire model. diff --git a/crates/zephium-store/src/essentials.rs b/crates/zephium-store/src/essentials.rs index aa827c88b..521472ec0 100644 --- a/crates/zephium-store/src/essentials.rs +++ b/crates/zephium-store/src/essentials.rs @@ -48,8 +48,14 @@ pub(crate) fn spread( let mut unplaced = Vec::new(); let known: std::collections::HashSet = spaces.iter().map(|space| space.id).collect(); for item in items { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = item.placement; - if known.contains(&space) { + let placed = match item.placement { + Placement::Favorites { space } | Placement::Space { space, .. } => { + known.contains(&space) + } + // A mini window's page is never saved. + Placement::Mini { .. } => false, + }; + if placed { by_placement.entry(item.placement).or_default().push(item); } else { unplaced.push(item); diff --git a/crates/zephium-store/src/hub/compatibility.rs b/crates/zephium-store/src/hub/compatibility.rs index 5e508b5fb..b0b241549 100644 --- a/crates/zephium-store/src/hub/compatibility.rs +++ b/crates/zephium-store/src/hub/compatibility.rs @@ -79,6 +79,11 @@ impl Hub { Placement::Space { space, section } => { (Some(space.to_string()), section_to_str(section)) } + Placement::Mini { .. } => { + return Err(invalid_data( + "legacy session writer cannot encode a mini window page", + )); + } }; let (kind, name, url, title, zoom) = match &item.kind { PersistedKind::Folder { name } => { @@ -547,10 +552,14 @@ pub(super) fn clear_legacy_session_rows_once(conn: &mut Connection) -> rusqlite: } fn owns_placement(profile: ProfileId, s: &SessionState, placement: Placement) -> bool { - let (Placement::Favorites { space } | Placement::Space { space, .. }) = placement; - s.spaces - .iter() - .any(|x| x.id == space && x.profile == profile) + match placement { + Placement::Favorites { space } | Placement::Space { space, .. } => s + .spaces + .iter() + .any(|x| x.id == space && x.profile == profile), + // Never saved: a mini window's page belongs to no session. + Placement::Mini { .. } => false, + } } fn section_to_str(section: SpaceSection) -> &'static str { diff --git a/desktop/capabilities/mini.json b/desktop/capabilities/mini.json new file mode 100644 index 000000000..f30a86fa5 --- /dev/null +++ b/desktop/capabilities/mini.json @@ -0,0 +1,11 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "mini", + "description": "Zone-2 mini window toolbars: dragging their own window only", + "windows": [ + "mini-*" + ], + "permissions": [ + "core:window:allow-start-dragging" + ] +} diff --git a/desktop/src/external_links.rs b/desktop/src/external_links.rs index 8fa319b0a..4261093c8 100644 --- a/desktop/src/external_links.rs +++ b/desktop/src/external_links.rs @@ -3,6 +3,7 @@ //! admits every address before the shell sees it. use super::*; +use std::sync::atomic::AtomicBool; use std::sync::Mutex; use zephium_core::navigation::{external_target, MAX_EXTERNAL_TARGETS}; @@ -10,6 +11,10 @@ use zephium_core::navigation::{external_target, MAX_EXTERNAL_TARGETS}; /// launched the app through the run loop, which can precede setup. static WAITING: Mutex> = Mutex::new(Vec::new()); +/// A running instance received links and wants the window that shows them +/// in front. The shell says which window that is once it has opened them. +static FORWARD: AtomicBool = AtomicBool::new(false); + /// Admits `arguments` and opens them. `forward` brings the window to the /// front, which a running instance wants and a launch leaves to its own /// startup reveal. @@ -35,11 +40,28 @@ pub(crate) fn hand_off( waiting.extend(urls.into_iter().take(room)); return; }; - if shell.dispatch(Command::OpenExternal(urls)) && forward { - bring_forward(app); + if forward { + FORWARD.store(true, Ordering::Release); + } + if !shell.dispatch(Command::OpenExternal(urls)) { + FORWARD.store(false, Ordering::Release); } } +/// Links opened as tabs: the main window comes forward to show them. +pub(crate) fn forward_pending(app: &tauri::AppHandle) { + if FORWARD.swap(false, Ordering::AcqRel) { + let handle = app.clone(); + let _ = app.run_on_main_thread(move || bring_forward(&handle)); + } +} + +/// A link opened in a mini window, which comes forward on its own; the +/// main window stays where it is. +pub(crate) fn forward_handled() { + FORWARD.store(false, Ordering::Release); +} + /// Runs once the shell is managed: what arrived early, then this launch's own /// command line (Windows and Linux pass a clicked link as an argument). pub(crate) fn adopt(app: &tauri::AppHandle) { diff --git a/desktop/src/frame_sources.rs b/desktop/src/frame_sources.rs index 98c7fca2b..559e1b1e4 100644 --- a/desktop/src/frame_sources.rs +++ b/desktop/src/frame_sources.rs @@ -6,6 +6,7 @@ pub const SRC_FEATURES_DOCK_TOOLSHELF_SVELTE: &str = pub const SRC_STYLES_TOKENS_CSS: &str = include_str!("../../frame/src/styles/tokens.css"); pub const SRC_BOOTSTRAP_CSS: &str = include_str!("../../frame/src/styles/axes/bootstrap.css"); pub const PANEL_HTML: &str = include_str!("../../frame/panel.html"); +pub const MINI_HTML: &str = include_str!("../../frame/mini.html"); pub const INDEX_HTML: &str = include_str!("../../frame/browser.html"); pub const ONBOARDING_HTML: &str = include_str!("../../frame/onboarding.html"); pub const SRC_APP_APP_SVELTE: &str = include_str!("../../frame/src/app/browser/BrowserApp.svelte"); diff --git a/desktop/src/lib.rs b/desktop/src/lib.rs index d67dac157..427c6732b 100644 --- a/desktop/src/lib.rs +++ b/desktop/src/lib.rs @@ -102,6 +102,7 @@ mod material; mod media; mod memory_pressure; mod menu_text; +mod mini; mod notes; #[cfg(target_os = "windows")] mod onboarding_host; @@ -1783,6 +1784,9 @@ struct ItemsChanged(zephium_ipc::ItemsState); #[derive(Clone, Debug, Serialize, Deserialize, specta::Type, Event)] struct TabChanged(zephium_ipc::TabView); +#[derive(Clone, Debug, Serialize, Deserialize, specta::Type, Event)] +struct MiniChanged(zephium_ipc::MiniView); + #[derive(Clone, Debug, Serialize, Deserialize, specta::Type, Event)] struct FaviconsChanged(zephium_ipc::FaviconsView); @@ -2250,7 +2254,10 @@ fn specta_builder() -> tauri_specta::Builder { divider_grab, divider_drag, divider_release, - swipe::swipe_region + swipe::swipe_region, + mini::mini_ready, + mini::mini_action, + mini::mini_space_menu ]) .events(collect_events![ keymap::KeymapChanged, @@ -2272,6 +2279,7 @@ fn specta_builder() -> tauri_specta::Builder { DownloadsChanged, NoteOpenRequested, TabChanged, + MiniChanged, ExtensionActionsChanged, ExtensionActionFailed, ExtensionActionShortcut, @@ -2666,6 +2674,9 @@ fn emit_ui_command(app: &tauri::AppHandle, id: &str) { // Only consumed settings wake the hidden launcher WebView. if launcher_follows_ui_command(id) { emit_to_privileged(app, overlay::PANEL_LABEL, EVENT_UI, &id); + for label in mini::labels(app) { + emit_to_privileged(app, &label, EVENT_UI, &id); + } } } @@ -2775,6 +2786,10 @@ enum CallerPolicy { Main, Panel, Both, + /// A mini window's toolbar; the command acts on that window alone. + Mini, + /// Any privileged chrome, for read-only appearance and language state. + AnyChrome, } // `WebviewWindow` is injected from Tauri's invoke message (and omitted by @@ -2784,6 +2799,10 @@ fn caller_allowed(policy: CallerPolicy, label: &str) -> bool { CallerPolicy::Main => label == MAIN_LABEL, CallerPolicy::Panel => label == overlay::PANEL_LABEL, CallerPolicy::Both => matches!(label, MAIN_LABEL | overlay::PANEL_LABEL), + CallerPolicy::Mini => mini::window_of(label).is_some(), + CallerPolicy::AnyChrome => { + matches!(label, MAIN_LABEL | overlay::PANEL_LABEL) || mini::window_of(label).is_some() + } } } @@ -4191,6 +4210,9 @@ fn execute_command_or( if id == "tab.close" && tab_switcher::close_selected(app) { return accepted_ui_operation(); } + if mini::route(app, id) { + return accepted_ui_operation(); + } if matches!(id, "tab.recent.next" | "tab.recent.previous") { return if tab_switcher::step(app, id == "tab.recent.previous", true) { accepted_ui_operation() @@ -4360,6 +4382,13 @@ fn execute_command_or( dispatch_operation(app, &shell, Command::ShowBrowserPage(page)) }); } + if id == "window.newMini" { + return if overlay::request(app, |panel| panel.toggle_mini()) { + accepted_ui_operation() + } else { + rejected_operation() + }; + } if id == "launcher.toggle" { return if overlay::request(app, |panel| panel.toggle()) { accepted_ui_operation() @@ -4569,6 +4598,7 @@ fn newtab_search( let accepted = shell.dispatch(Command::SearchScoped { query: query.clone(), context: Box::new(context.clone()), + mini: false, }); if accepted { search_providers::schedule(caller, app, shell.inner().clone(), query, context); @@ -4634,6 +4664,7 @@ fn newtab_run( action, background: false, replace: None, + new_mini: false, }, ) } @@ -4652,16 +4683,18 @@ fn launcher_search( { return false; } - let Some(context) = app - .try_state::() - .and_then(|overlay| overlay.search_context(&request_id)) - else { + let Some((context, mini)) = app.try_state::().and_then(|overlay| { + overlay + .search_context(&request_id) + .map(|context| (context, overlay.mini())) + }) else { diagnostic!("launcher: search refused outside a presented session"); return false; }; let accepted = shell.dispatch(Command::SearchScoped { query: query.clone(), context: Box::new(context.clone()), + mini, }); if !accepted { diagnostic!("launcher: search refused by a full actor queue"); @@ -4685,6 +4718,10 @@ fn launcher_run( { return rejected_operation(); } + // Offered as a command, it turns this launcher into the one it opens. + if matches!(&action, zephium_ipc::SearchAction::RunCommand { id } if id == "window.newMini") { + return execute_command(&app, "window.newMini"); + } let (Some(shell), Some(overlay), Some(ledger)) = ( app.try_state::(), app.try_state::(), @@ -4703,7 +4740,9 @@ fn launcher_run( } // Only an address can be sent behind the current tab; every other action // is about where the user is going next. - let background = background && matches!(action, zephium_ipc::SearchAction::OpenUrl { .. }); + let background = background + && !overlay.mini() + && matches!(action, zephium_ipc::SearchAction::OpenUrl { .. }); // Armed before either path runs, so one action at a time reaches the // launcher's outcome, wherever it is carried out. if !overlay.arm_action(&operation_id, &context, background) { @@ -4807,6 +4846,7 @@ fn run_in_shell( action, background, replace: overlay.editing_tab(), + new_mini: overlay.mini(), }, ); if !accepted { @@ -4823,7 +4863,7 @@ struct UiInfo { #[tauri::command] #[specta::specta] fn ui_info(caller: WebviewWindow) -> UiInfo { - if !authorize(&caller, CallerPolicy::Both, "ui_info") { + if !authorize(&caller, CallerPolicy::AnyChrome, "ui_info") { return UiInfo { material: material::Material::None, }; @@ -5456,7 +5496,7 @@ fn setting_value_for_frame(key: &str, stored: Option) -> Option #[tauri::command] #[specta::specta] async fn setting_get(caller: WebviewWindow, key: String) -> Option { - if !authorize(&caller, CallerPolicy::Both, "setting_get") { + if !authorize(&caller, CallerPolicy::AnyChrome, "setting_get") { return None; } if !SETTING_KEYS.contains(&key.as_str()) { @@ -5938,7 +5978,7 @@ fn launcher_edit( { return false; } - overlay::request(&app, move |panel| panel.edit(tab_id, url)) + overlay::request(&app, move |panel| panel.edit(tab_id, url, false)) } #[tauri::command] @@ -6293,6 +6333,7 @@ fn build_menu( let file = SubmenuBuilder::new(handle, menu_text::label("File")) .item(&item("tab.new")?) .item(&item("window.newPrivate")?) + .item(&item("window.newMini")?) .item(&item("note.new")?) .item(&item("split.choose")?) .separator() @@ -7304,10 +7345,12 @@ fn finish_browser_setup( if zephium_engine::foreground_rendering_policy_event(&event) { return; } - if let zephium_core::ports::engine::EngineEvent::ShortcutPressed { command, .. } = + if let zephium_core::ports::engine::EngineEvent::ShortcutPressed { item, command } = &event { - let _ = execute_command(&sink_app, command); + if !mini::route_page_key(&sink_app, &item.to_string(), command) { + let _ = execute_command(&sink_app, command); + } return; } if let Some(shell) = sink_slot.get() { @@ -7361,7 +7404,10 @@ fn finish_browser_setup( #[cfg(target_os = "macos")] install_menu_bar(&handle, &keymap, false)?; app.on_menu_event(|app, event| { - let _ = execute_command(app, event.id().0.as_str()); + let id = event.id().0.as_str(); + if !mini::on_menu(app, id) { + let _ = execute_command(app, id); + } }); let keys_engine = engine.clone(); app.state::() @@ -7631,6 +7677,13 @@ fn finish_browser_setup( Projection::MediaPlayer(player) => { emit_to_privileged(&emit_handle, MAIN_LABEL, EVENT_MEDIA_PLAYER, &player) } + Projection::MiniOpened(opened) => { + external_links::forward_handled(); + mini::open(&emit_handle, opened) + } + Projection::Mini(view) => mini::project(&emit_handle, &view), + Projection::MiniClosed(closed) => mini::close(&emit_handle, closed), + Projection::ExternalTabsOpened => external_links::forward_pending(&emit_handle), }); let chrome: SharedChrome = platform::imp::make_chrome(&window, dispatch.clone()); @@ -7795,6 +7848,13 @@ fn finish_browser_setup( } #[cfg(feature = "work-product")] page_assist::install(app, engine.clone(), store.clone()); + mini::install( + app, + engine.clone(), + privileged_app_url(app, &tauri::WebviewUrl::App("mini.html".into()))?, + #[cfg(target_os = "windows")] + privileged_runtime.panel.clone(), + ); notes::install(app, &data_dir, store.clone(), &shell); external_links::adopt(app); #[cfg(feature = "work-product")] @@ -8099,7 +8159,7 @@ fn finish_browser_setup( platform::imp::harden_privileged( &panel_window, &privileged_runtime.panel, - runtime_update_notifier.clone(), + platform::imp::PrivilegedEnvironment::Own(runtime_update_notifier.clone()), )?; platform::imp::apply_material(&panel_window, true); } @@ -8366,7 +8426,7 @@ pub fn run() { #[cfg(target_os = "macos")] let builder = builder.on_web_content_process_terminate(|webview| { let label = webview.label().to_owned(); - if !renderer_recovery::owns(&label) { + if !renderer_recovery::owns(&label) && mini::window_of(&label).is_none() { let _ = webview.reload(); return; } @@ -9369,6 +9429,7 @@ mod tests { for html in [ crate::frame_sources::INDEX_HTML, crate::frame_sources::PANEL_HTML, + crate::frame_sources::MINI_HTML, crate::frame_sources::ONBOARDING_HTML, ] { assert!( @@ -9379,6 +9440,7 @@ mod tests { for css in [ include_str!("../../frame/src/styles/global.css"), include_str!("../../frame/src/styles/panel.css"), + include_str!("../../frame/src/styles/mini.css"), ] { assert!(css.starts_with("@import \"./axes/bootstrap.css\";")); } diff --git a/desktop/src/mini.rs b/desktop/src/mini.rs new file mode 100644 index 000000000..89b5b662d --- /dev/null +++ b/desktop/src/mini.rs @@ -0,0 +1,800 @@ +//! Mini windows: the native window around one page the shell keeps out of +//! the sidebar. Each has its own privileged toolbar (`mini.html`) above a +//! content stage the engine builds inside it. The window is named by its +//! label, `mini-`, so a toolbar can only ever act on its own page. +//! +//! macOS gives the window a transparent title bar, its lights inside the +//! toolbar. Windows draws no frame: the toolbar carries the window's +//! controls and drags it, and Tauri's resize ring stays reachable around the +//! page. On Windows every toolbar joins the launcher's WebView2 browser, so +//! no window adds a privileged browser that teardown would not prove gone. + +use serde::Deserialize; +use std::collections::HashMap; +use std::sync::{Arc, Mutex, MutexGuard}; +use tauri::{Manager, State, WebviewWindow}; +use zephium_app::{ + ChromePresentation, ChromePresentationCallback, ChromePresentationDispatch, Command, Handle, + MiniAction, +}; +use zephium_core::geometry::Size; +use zephium_ipc::{MiniClosedView, MiniOpenedView, MiniView}; + +use crate::{authorize, emit_to_privileged, shutdown_started, CallerPolicy}; + +const LABEL_PREFIX: &str = "mini-"; +pub(crate) const EVENT_MINI: &str = "zephium:mini"; +const EVENT_MINI_PRESENTATION: &str = "zephium:mini-presentation"; +/// Space menu items: `mini.space=:`. +const SPACE_MENU: &str = "mini.space="; +/// How far each further open mini window steps from the last, so a new one +/// never lands exactly on another. +const CASCADE: f64 = 28.0; + +/// Each open window's latest view, which its space menu is built from, and +/// whether it was last put above other windows. +static VIEWS: Mutex>> = Mutex::new(None); + +fn views() -> MutexGuard<'static, Option>> { + VIEWS + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) +} + +pub(crate) fn label(window: u64) -> String { + format!("{LABEL_PREFIX}{window}") +} + +/// The window a label names: canonical decimal only, so no two labels name +/// one window. +pub(crate) fn window_of(label: &str) -> Option { + let digits = label.strip_prefix(LABEL_PREFIX)?; + if digits.is_empty() + || digits.len() > 20 + || digits.starts_with('0') + || !digits.bytes().all(|byte| byte.is_ascii_digit()) + { + return None; + } + digits.parse().ok() +} + +/// Labels of the mini windows open now. +pub(crate) fn labels(app: &tauri::AppHandle) -> Vec { + app.webview_windows() + .into_keys() + .filter(|label| window_of(label).is_some()) + .collect() +} + +/// What a command means for a mini window: the page actions, the address, +/// and the keys only a mini window answers. Others go to the main window. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Routed { + Act(MiniAction), + EditAddress, +} + +fn routed(id: &str) -> Option { + Some(match zephium_core::commands::runs_as(id) { + "tab.close" => Routed::Act(MiniAction::Close), + "nav.reload" | "nav.hardReload" => Routed::Act(MiniAction::Reload), + "nav.back" => Routed::Act(MiniAction::Back), + "nav.forward" => Routed::Act(MiniAction::Forward), + "mini.openInMain" => Routed::Act(MiniAction::OpenInMain), + "mini.keepOnTop" => Routed::Act(MiniAction::KeepOnTop(None)), + "url.focus" => Routed::EditAddress, + _ => return None, + }) +} + +/// Carries out `id` for the mini window in front, when one is and the +/// command is one it answers. Menu key equivalents and the browser's own +/// keys reach whichever window is in front, so without this Cmd+W in a mini +/// window would close the main window's tab. +pub(crate) fn route(app: &tauri::AppHandle, id: &str) -> bool { + let Some(route) = routed(id) else { + return false; + }; + let Some(window) = focused(app) else { + return false; + }; + carry_out(app, window, route) +} + +/// The same for a key a page pressed: it acts on that page's own mini +/// window, wherever focus is reported. +pub(crate) fn route_page_key(app: &tauri::AppHandle, page: &str, id: &str) -> bool { + let Some(route) = routed(id) else { + return false; + }; + let Some(window) = window_showing(page) else { + return false; + }; + carry_out(app, window, route) +} + +fn carry_out(app: &tauri::AppHandle, window: u64, route: Routed) -> bool { + match route { + Routed::EditAddress => edit_address(app, window), + Routed::Act(action) => app + .try_state::() + .is_some_and(|shell| shell.dispatch(Command::Mini { window, action })), + } +} + +/// The window and space a space menu item names. +fn space_choice(id: &str) -> Option<(u64, zephium_core::ids::SpaceId)> { + let (window, space) = id.strip_prefix(SPACE_MENU)?.split_once(':')?; + Some(( + window_of(&format!("{LABEL_PREFIX}{window}"))?, + zephium_core::ids::SpaceId::parse(space)?, + )) +} + +/// Handles a space picked from a mini window's space menu. Returns whether +/// the menu event was one. +pub(crate) fn on_menu(app: &tauri::AppHandle, id: &str) -> bool { + if !id.starts_with(SPACE_MENU) { + return false; + } + if let (Some((window, space)), Some(shell)) = (space_choice(id), app.try_state::()) { + shell.dispatch(Command::Mini { + window, + action: MiniAction::OpenInSpace(space), + }); + } + true +} + +/// The mini window in front, if one is. +pub(crate) fn focused(app: &tauri::AppHandle) -> Option { + app.webview_windows() + .into_iter() + .find_map(|(label, window)| { + let id = window_of(&label)?; + window.is_focused().unwrap_or(false).then_some(id) + }) +} + +/// The mini window showing a page. +fn window_showing(page: &str) -> Option { + views().as_ref().and_then(|views| { + views + .values() + .find(|(view, _)| view.tab.as_ref().is_some_and(|tab| tab.id == page)) + .map(|(view, _)| view.window) + }) +} + +/// Brings forward the mini window showing a page. Returns whether one does. +pub(crate) fn focus_page(app: &tauri::AppHandle, page: &str) -> bool { + window_showing(page) + .and_then(|window| app.get_webview_window(&label(window))) + .is_some_and(|window| window.set_focus().is_ok()) +} + +/// Opens the launcher on the page's address, as an address bar would. The +/// page may have no address yet; the field then starts empty. +fn edit_address(app: &tauri::AppHandle, window: u64) -> bool { + let Some(tab) = views() + .as_ref() + .and_then(|views| views.get(&window)?.0.tab.clone()) + else { + return false; + }; + let url = tab.url.unwrap_or_default(); + crate::overlay::request(app, move |panel| panel.edit(tab.id, url, true)) +} + +/// The size of a window's content area in logical points. +fn content_size(window: &WebviewWindow) -> Option { + #[cfg(target_os = "macos")] + { + crate::platform::imp::window_content_size(window) + } + #[cfg(not(target_os = "macos"))] + { + let size = window.inner_size().ok()?; + let scale = window.scale_factor().ok()?; + (scale.is_finite() && scale > 0.0).then(|| { + Size::new( + f64::from(size.width) / scale, + f64::from(size.height) / scale, + ) + }) + } +} + +/// Pops the spaces "Open in Zephium" can put the page in, under the +/// toolbar's button at `x`, `y`. +#[tauri::command] +#[specta::specta] +pub(crate) fn mini_space_menu(caller: WebviewWindow, x: f64, y: f64) -> bool { + if !authorize(&caller, CallerPolicy::Mini, "mini_space_menu") { + return false; + } + let Some(window) = window_of(caller.label()) else { + return false; + }; + let Some(size) = content_size(&caller) else { + return false; + }; + let Some(anchor) = crate::menu_popup_anchor(x, y, size.width, size.height) else { + return false; + }; + let Some(view) = views() + .as_ref() + .and_then(|views| views.get(&window).map(|(view, _)| view.clone())) + else { + return false; + }; + if view.tab.is_none() || view.spaces.len() < 2 { + return false; + } + let menu = space_menu(caller.app_handle(), window, &view); + menu.is_ok_and(|menu| caller.popup_menu_at(&menu, anchor).is_ok()) +} + +fn space_menu( + app: &tauri::AppHandle, + window: u64, + view: &MiniView, +) -> tauri::Result> { + use tauri::menu::{CheckMenuItemBuilder, IsMenuItem, Menu}; + // A space's name is the person's own text, shown as it is. + let items = view + .spaces + .iter() + .map(|space| { + CheckMenuItemBuilder::with_id(format!("{SPACE_MENU}{window}:{}", space.id), &space.name) + .checked(view.space.as_deref() == Some(space.id.as_str())) + .build(app) + }) + .collect::>>()?; + let refs: Vec<&dyn IsMenuItem> = items + .iter() + .map(|item| item as &dyn IsMenuItem) + .collect(); + Menu::with_items(app, &refs) +} + +/// What builds mini windows: the toolbar's address, the engine that hosts +/// their pages and, on Windows, the launcher's user-data folder they share. +struct Factory { + url: tauri::Url, + engine: Arc, + #[cfg(target_os = "windows")] + runtime: std::path::PathBuf, +} + +pub(crate) fn install( + app: &tauri::AppHandle, + engine: Arc, + url: tauri::Url, + #[cfg(target_os = "windows")] runtime: std::path::PathBuf, +) { + app.manage(Factory { + url, + engine, + #[cfg(target_os = "windows")] + runtime, + }); +} + +/// Builds the native window for a mini window the shell opened. A window +/// that cannot be built hands its page back to the shell, which opens it as +/// a tab instead. +pub(crate) fn open(app: &tauri::AppHandle, opened: MiniOpenedView) { + let window = opened.window; + let handle = app.clone(); + let build_on_main = move || { + if !build(&handle, opened) { + unbuilt(&handle, window); + } + }; + // Windows: the toolbar joins the launcher's browser, so that browser is + // made and registered first. The request runs on the main thread. + #[cfg(target_os = "windows")] + let scheduled = crate::overlay::request(app, move |_| build_on_main()); + #[cfg(not(target_os = "windows"))] + let scheduled = app.run_on_main_thread(build_on_main).is_ok(); + if !scheduled { + unbuilt(app, window); + } +} + +fn unbuilt(app: &tauri::AppHandle, window: u64) { + crate::write_diagnostic(format_args!("mini: window {window} not built")); + if let Some(shell) = app.try_state::() { + let _ = shell.dispatch(Command::Mini { + window, + action: MiniAction::Unbuilt, + }); + } +} + +fn build(app: &tauri::AppHandle, opened: MiniOpenedView) -> bool { + use raw_window_handle::HasWindowHandle; + + // Only macOS and Windows harden a toolbar window; nowhere else builds one. + if cfg!(not(any(target_os = "macos", target_os = "windows"))) || shutdown_started(app) { + return false; + } + let Some(factory) = app.try_state::() else { + return false; + }; + let label = label(opened.window); + if app.get_webview_window(&label).is_some() { + return false; + } + let Ok(bootstrap) = tauri::Url::parse(crate::PRIVILEGED_BOOTSTRAP_URL) else { + return false; + }; + let Some(size) = zephium_app::admitted_mini_size(Size::new(opened.width, opened.height)) else { + return false; + }; + let min = zephium_app::MINI_WINDOW_MIN_SIZE; + let builder = + tauri::WebviewWindowBuilder::new(app, &label, tauri::WebviewUrl::External(bootstrap)) + .title("Zephium") + .incognito(true) + .devtools(cfg!(debug_assertions)) + .general_autofill_enabled(false) + .initialization_script_for_all_frames(zephium_engine::PAGE_PRINT_DENY_SCRIPT) + .on_download(|_, _| false) + .on_new_window(|_, _| tauri::webview::NewWindowResponse::Deny) + .on_web_resource_request(|_, response| { + crate::harden_privileged_headers(response.headers_mut()) + }) + .inner_size(size.width.max(min.width), size.height.max(min.height)) + .min_inner_size(min.width, min.height) + .maximizable(false) + .fullscreen(false) + .visible(false); + #[cfg(target_os = "macos")] + let builder = builder + .title_bar_style(tauri::TitleBarStyle::Overlay) + .hidden_title(true) + // Measured on screen: this centres the lights on the toolbar. + .traffic_light_position(tauri::LogicalPosition::new(14.0, 20.0)); + #[cfg(target_os = "windows")] + let builder = builder + .decorations(false) + .shadow(true) + .data_directory(factory.runtime.clone()) + .additional_browser_args(crate::PRIVILEGED_WEBVIEW2_BROWSER_ARGS); + let window = match builder.build() { + Ok(window) => window, + Err(error) => { + crate::write_diagnostic(format_args!("mini: window build failed: {error}")); + return false; + } + }; + let fail = |window: &WebviewWindow| { + let _ = window.destroy(); + false + }; + #[cfg(target_os = "macos")] + if !crate::platform::imp::harden_privileged(&window) + || !crate::platform::imp::fit_toolbar(&window, zephium_app::MINI_TOOLBAR_HEIGHT) + { + return fail(&window); + } + #[cfg(target_os = "windows")] + { + crate::platform::imp::round_corners(&window); + if let Err(error) = crate::platform::imp::harden_privileged( + &window, + &factory.runtime, + crate::platform::imp::PrivilegedEnvironment::Joined(crate::overlay::PANEL_LABEL), + ) { + crate::write_diagnostic(format_args!("mini: toolbar refused: {error}")); + return fail(&window); + } + } + place(app, &window, opened.window); + let Ok(handle) = window.window_handle().map(|handle| handle.as_raw()) else { + return fail(&window); + }; + if !factory.engine.attach_window(opened.window, handle) { + return fail(&window); + } + let events = window.clone(); + let id = opened.window; + window.on_window_event(move |event| { + let app = events.app_handle(); + let Some(shell) = app.try_state::() else { + return; + }; + match event { + tauri::WindowEvent::CloseRequested { api, .. } if !shutdown_started(app) => { + api.prevent_close(); + let _ = shell.dispatch(Command::Mini { + window: id, + action: MiniAction::Close, + }); + } + // Moving to this window puts the launcher away. + tauri::WindowEvent::Focused(_) => { + if let Some(panel) = app.try_state::() { + panel.focus_changed(); + } + } + tauri::WindowEvent::Resized(_) | tauri::WindowEvent::ScaleFactorChanged { .. } => { + if let Some(size) = content_size(&events) { + let _ = shell.dispatch(Command::MiniResized { window: id, size }); + } + } + _ => {} + } + }); + if window.navigate(factory.url.clone()).is_err() { + return fail(&window); + } + true +} + +/// Centres the first mini window on the screen the main window is on, and +/// steps each further one down and across so none hides another. +fn place(app: &tauri::AppHandle, window: &WebviewWindow, id: u64) { + let _ = window.center(); + let others = labels(app) + .iter() + .filter(|other| window_of(other) != Some(id)) + .count(); + if others == 0 { + return; + } + let (Ok(position), Ok(scale)) = (window.outer_position(), window.scale_factor()) else { + return; + }; + let step = cascade_step(others) * scale; + let _ = window.set_position(tauri::PhysicalPosition::new( + f64::from(position.x) + step, + f64::from(position.y) + step, + )); +} + +/// The logical offset for a window opening beside `others`, wrapping after +/// a few steps so it stays near the middle of the screen. +fn cascade_step(others: usize) -> f64 { + // Bounded by MAX_MINI_WINDOWS; the cast cannot lose anything. + (others % 6) as f64 * CASCADE +} + +/// Toolbar reloads a mini window gets before its page moves to the main +/// window instead, so a toolbar that keeps failing never loops. +const MAX_TOOLBAR_RELOADS: u8 = 3; + +static RELOADS: Mutex>> = Mutex::new(None); + +/// Counts one more reload of a window's toolbar; false once it had its share. +fn take_reload(reloads: &mut HashMap, window: u64) -> bool { + let count = reloads.entry(window).or_default(); + if *count >= MAX_TOOLBAR_RELOADS { + return false; + } + *count += 1; + true +} + +/// The toolbar of a mini window lost its renderer. It loads again and +/// reports ready, which shows the page again; the page itself never stopped. +/// When the toolbar cannot come back, its page moves to the main window, so +/// nothing the person had open is lost. +pub(crate) fn recover(app: &tauri::AppHandle, toolbar: &str) { + let Some(id) = window_of(toolbar) else { + return; + }; + if shutdown_started(app) { + return; + } + let reload = take_reload( + RELOADS + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .get_or_insert_with(Default::default), + id, + ); + let reloaded = reload + && app + .get_webview_window(toolbar) + .zip(app.try_state::()) + .is_some_and(|(window, factory)| window.navigate(factory.url.clone()).is_ok()); + crate::write_diagnostic(format_args!( + "mini: toolbar {id} renderer ended, {}", + if reloaded { + "reloading" + } else { + "moving its page" + } + )); + if !reloaded { + if let Some(shell) = app.try_state::() { + let _ = shell.dispatch(Command::Mini { + window: id, + action: MiniAction::OpenInMain, + }); + } + } +} + +/// Takes the native window away once the shell let it go. When its page +/// moved into the main window, that window comes forward to show it. +pub(crate) fn close(app: &tauri::AppHandle, closed: MiniClosedView) { + if let Some(views) = views().as_mut() { + views.remove(&closed.window); + } + if let Some(reloads) = RELOADS + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .as_mut() + { + reloads.remove(&closed.window); + } + let handle = app.clone(); + let _ = app.run_on_main_thread(move || { + if let Some(window) = handle.get_webview_window(&label(closed.window)) { + let _ = window.destroy(); + } + if closed.reveal_main { + crate::external_links::bring_forward(&handle); + } + }); +} + +pub(crate) fn project(app: &tauri::AppHandle, view: &MiniView) { + let raise = { + let mut views = views(); + let views = views.get_or_insert_with(Default::default); + let was = views.get(&view.window).map(|(_, pinned)| *pinned); + views.insert(view.window, (view.clone(), view.pinned)); + (was != Some(view.pinned)).then_some(view.pinned) + }; + if let Some(pinned) = raise { + let handle = app.clone(); + let window = view.window; + let _ = app.run_on_main_thread(move || { + if let Some(window) = handle.get_webview_window(&label(window)) { + let _ = window.set_always_on_top(pinned); + // Kept on top, it follows the person across desktops. + let _ = window.set_visible_on_all_workspaces(pinned); + } + }); + } + emit_to_privileged(app, &label(view.window), EVENT_MINI, view); +} + +/// The presentation barrier for a mini window's page. The toolbar applies +/// the exact revision and the eval reads its DOM back in the same turn: the +/// page id, its URL, its title and the host it shows must all match before +/// the shell lets the page appear. +pub(crate) fn apply_presentation( + app: &tauri::AppHandle, + window: u64, + presentation: ChromePresentation, + done: ChromePresentationCallback, +) -> ChromePresentationDispatch { + if presentation.tab.id != presentation.id.to_string() + || presentation.tab.url.as_deref() != Some(presentation.url.as_str()) + || presentation.active != Some(presentation.id) + { + return ChromePresentationDispatch::Rejected; + } + let Some(toolbar) = app.get_webview_window(&label(window)) else { + return ChromePresentationDispatch::Rejected; + }; + let (Ok(event), Ok(payload)) = ( + serde_json::to_string(EVENT_MINI_PRESENTATION), + serde_json::to_string(&presentation.tab), + ) else { + return ChromePresentationDispatch::Rejected; + }; + let nonce = format!( + "zephium-mini-presentation-v1:{window}:{}:{:032x}", + presentation.id, + presentation.navigation.into_raw() + ); + let Ok(serialized_nonce) = serde_json::to_string(&nonce) else { + return ChromePresentationDispatch::Rejected; + }; + let script = format!( + r#"(() => {{ + "use strict"; + const rejected = "zephium-presentation-rejected"; + try {{ + const tab = {payload}; + window.dispatchEvent(new CustomEvent({event}, {{ detail: {{ tab }} }})); + const shell = document.querySelector("[data-zephium-mini-tab]"); + if (!shell || shell.dataset.zephiumMiniTab !== tab.id) return rejected; + if (shell.dataset.zephiumTabUrl !== (tab.url ?? "") || + shell.dataset.zephiumProjectionRevision !== tab.projection_revision) return rejected; + const label = shell.querySelector("[data-zephium-tab-label]"); + if (!label || label.textContent !== tab.title) return rejected; + let expected = ""; + try {{ expected = new URL(tab.url).host; }} catch (_) {{ return rejected; }} + const address = shell.querySelector("[data-zephium-address]"); + if (!address || address.textContent !== expected) return rejected; + void document.documentElement.getBoundingClientRect(); + return {serialized_nonce}; + }} catch (_) {{ + return rejected; + }} +}})()"# + ); + let expected = nonce; + let done = Mutex::new(Some(done)); + match toolbar.eval_with_callback(script, move |result| { + let applied = + serde_json::from_str::(&result).is_ok_and(|returned| returned == expected); + if let Some(done) = done + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .take() + { + done(applied); + } + }) { + Ok(()) => ChromePresentationDispatch::Scheduled, + Err(_) => ChromePresentationDispatch::Rejected, + } +} + +/// What a mini window's toolbar may ask of its page or its window. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, specta::Type)] +#[serde(rename_all = "snake_case")] +pub(crate) enum MiniIntent { + Back, + Forward, + Reload, + OpenInMain, + Close, + /// Opens the launcher on the page's address. + EditAddress, + /// Keeps the window above other windows, or stops. + KeepOnTop, + /// Windows only: the toolbar carries the window's own controls. + Minimize, +} + +/// The toolbar finished its first render: the window shows, and the shell +/// lays its page out and lets it be verified. +#[tauri::command] +#[specta::specta] +pub(crate) fn mini_ready(caller: WebviewWindow, shell: State<'_, Handle>) -> bool { + if !authorize(&caller, CallerPolicy::Mini, "mini_ready") + || shutdown_started(caller.app_handle()) + { + return false; + } + let (Some(window), Some(size)) = (window_of(caller.label()), content_size(&caller)) else { + return false; + }; + let _ = caller.show(); + let _ = caller.set_focus(); + shell.dispatch(Command::MiniAttached { window, size }) +} + +#[tauri::command] +#[specta::specta] +pub(crate) fn mini_action( + caller: WebviewWindow, + shell: State<'_, Handle>, + action: MiniIntent, +) -> bool { + if !authorize(&caller, CallerPolicy::Mini, "mini_action") { + return false; + } + let Some(window) = window_of(caller.label()) else { + return false; + }; + let action = match action { + MiniIntent::EditAddress => return edit_address(caller.app_handle(), window), + MiniIntent::Minimize => return caller.minimize().is_ok(), + MiniIntent::Back => MiniAction::Back, + MiniIntent::Forward => MiniAction::Forward, + MiniIntent::Reload => MiniAction::Reload, + MiniIntent::OpenInMain => MiniAction::OpenInMain, + MiniIntent::Close => MiniAction::Close, + MiniIntent::KeepOnTop => MiniAction::KeepOnTop(None), + }; + shell.dispatch(Command::Mini { window, action }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_space_menu_item_names_its_window_and_space() { + let space = zephium_core::ids::SpaceId::generate(); + assert_eq!( + space_choice(&format!("{SPACE_MENU}3:{space}")), + Some((3, space)) + ); + for id in [ + format!("{SPACE_MENU}03:{space}"), + format!("{SPACE_MENU}3"), + format!("{SPACE_MENU}3:not-a-space"), + format!("{SPACE_MENU}0:{space}"), + format!("{SPACE_MENU}:{space}"), + format!("{SPACE_MENU}-3:{space}"), + format!("{SPACE_MENU}99999999999999999999999:{space}"), + format!("mini.spaces=3:{space}"), + ] { + assert_eq!(space_choice(&id), None, "{id}"); + } + } + + #[test] + fn page_and_window_commands_act_on_the_mini_window() { + let act = |id| match routed(id) { + Some(Routed::Act(action)) => Some(action), + _ => None, + }; + assert_eq!(act("tab.close"), Some(MiniAction::Close)); + assert_eq!(act("nav.reload"), Some(MiniAction::Reload)); + assert_eq!(act("nav.reload.alt"), Some(MiniAction::Reload)); + assert_eq!(act("nav.hardReload"), Some(MiniAction::Reload)); + assert_eq!(act("nav.back"), Some(MiniAction::Back)); + assert_eq!(act("nav.back.alt"), Some(MiniAction::Back)); + assert_eq!(act("nav.forward"), Some(MiniAction::Forward)); + assert_eq!(act("mini.openInMain"), Some(MiniAction::OpenInMain)); + assert_eq!(act("mini.keepOnTop"), Some(MiniAction::KeepOnTop(None))); + assert_eq!(routed("url.focus"), Some(Routed::EditAddress)); + // The main window's own commands still reach it. + for id in [ + "tab.new", + "window.newMini", + "window.newPrivate", + "", + "mini.", + ] { + assert_eq!(routed(id), None, "{id}"); + } + } + + #[test] + fn only_canonical_labels_name_a_window() { + assert_eq!(window_of("mini-2"), Some(2)); + assert_eq!(window_of(&label(41)), Some(41)); + for label in [ + "mini-", + "mini-0", + "mini-02", + "mini-2a", + "mini--2", + "mini-+2", + "mini- 2", + "main", + "panel", + "Mini-2", + "little-2", + "mini-99999999999999999999999", + ] { + assert_eq!(window_of(label), None, "{label}"); + } + } + + #[test] + fn a_failing_toolbar_reloads_a_bounded_number_of_times() { + let mut reloads = HashMap::new(); + for _ in 0..MAX_TOOLBAR_RELOADS { + assert!(take_reload(&mut reloads, 4)); + } + assert!(!take_reload(&mut reloads, 4)); + assert!(!take_reload(&mut reloads, 4)); + // Each window has its own share. + assert!(take_reload(&mut reloads, 5)); + } + + #[test] + fn further_windows_step_aside_and_wrap() { + assert_eq!(cascade_step(0), 0.0); + assert_eq!(cascade_step(1), CASCADE); + assert_eq!(cascade_step(5), 5.0 * CASCADE); + assert_eq!(cascade_step(6), 0.0); + assert_eq!(cascade_step(7), CASCADE); + } +} diff --git a/desktop/src/overlay.rs b/desktop/src/overlay.rs index 85849ad5a..6c510b86f 100644 --- a/desktop/src/overlay.rs +++ b/desktop/src/overlay.rs @@ -16,8 +16,8 @@ use tauri::{LogicalSize, Manager, WebviewWindow}; #[cfg(target_os = "macos")] use zephium_core::ports::store::Store; use zephium_ipc::{ - OperationDisposition, OperationOutcome, PanelIntent, PanelLayout, PanelOwner, PanelState, - SearchContext, ToolKind, + OperationDisposition, OperationOutcome, OperationReason, PanelIntent, PanelLayout, PanelOwner, + PanelState, SearchContext, ToolKind, }; pub const PANEL_LABEL: &str = "panel"; pub const PANEL_SIZE: (f64, f64) = (geometry::WIDTH, geometry::INITIAL_HEIGHT); @@ -249,9 +249,9 @@ impl Overlay { } PanelIntent::Search => this.state().begin(), PanelIntent::Dismiss => { + let editing = this.state().model.editing_tab(); this.state().model.hide(); - #[cfg(target_os = "macos")] - crate::panel::return_to_previous(); + this.return_from(editing); } PanelIntent::Open { tool } => { this.state().model.hide(); @@ -267,7 +267,7 @@ impl Overlay { }); } /// Opens on the current page's address, the way an address bar would. - pub fn edit(&self, tab: String, url: String) { + pub fn edit(&self, tab: String, url: String, mini: bool) { self.on_main(move |this| { crate::tab_switcher::cancel(this.window_app()); if crate::resource_close::is_closing() { @@ -280,7 +280,11 @@ impl Overlay { if state.model.switcher.is_some() { state.content_height = geometry::INITIAL_HEIGHT; } - state.model.edit(tab, url); + if mini { + state.model.edit_mini(tab, url); + } else { + state.model.edit(tab, url); + } } this.cancel_search(old); this.present(); @@ -330,6 +334,61 @@ impl Overlay { pub fn editing_tab(&self) -> Option { self.state().model.editing_tab() } + /// Whether this presentation chooses a page for a mini window. + pub fn mini(&self) -> bool { + self.state().model.mini() + } + /// Opens to choose the address of a new mini window, or puts that away. + /// A private session in front keeps its own launcher: what it searches + /// must not leave for a regular profile's window. + pub fn toggle_mini(&self) { + self.on_main(|this| { + if crate::resource_close::is_closing() { + return; + } + let old = this.state().model.session(); + let dismissing = { + let state = this.state(); + state.model.mini() && state.model.editing_tab().is_none() + }; + { + let mut state = this.state(); + state.pending = None; + if dismissing { + state.model.hide(); + } else if state + .model + .owner + .as_ref() + .is_some_and(|owner| owner.private) + { + state.begin(); + } else { + state.model.search_mini(); + } + } + this.cancel_search(old); + this.present(); + #[cfg(target_os = "macos")] + if dismissing { + crate::panel::return_to_previous(); + } + }); + } + /// Gives focus back after the launcher is put away: to the mini window + /// whose address it was editing, else to where it was before. + fn return_from(&self, editing: Option) { + let mini = + editing.is_some_and(|tab| crate::mini::focus_page(self.window.app_handle(), &tab)); + #[cfg(target_os = "macos")] + if mini { + crate::panel::forget_previous(); + } else { + crate::panel::return_to_previous(); + } + #[cfg(not(target_os = "macos"))] + let _ = mini; + } pub fn toggle(&self) { self.on_main(|this| { crate::tab_switcher::cancel(this.window_app()); @@ -341,6 +400,7 @@ impl Overlay { let state = this.state(); state.model.presented && state.model.switcher.is_none() }; + let editing = this.state().model.editing_tab(); if dismissing { this.state().model.hide(); } else { @@ -348,12 +408,9 @@ impl Overlay { } this.cancel_search(old); this.present(); - #[cfg(target_os = "macos")] if dismissing { - crate::panel::return_to_previous(); + this.return_from(editing); } - #[cfg(not(target_os = "macos"))] - let _ = dismissing; }); } #[cfg(target_os = "linux")] @@ -607,11 +664,22 @@ impl Overlay { if pending.background { return; } + let editing = state.model.editing_tab(); state.model.hide(); drop(state); this.cancel_search(old_session); this.present(); - this.raise_browser(); + // The page is in a mini window: that window is what comes + // forward, and the main window stays where it is. + if result.reason == OperationReason::OpenedInMini { + #[cfg(target_os = "macos")] + crate::panel::forget_previous(); + if let Some(tab) = editing { + crate::mini::focus_page(this.window.app_handle(), &tab); + } + } else { + this.raise_browser(); + } }); } pub fn focus_changed(&self) { @@ -650,11 +718,14 @@ impl Overlay { return; } let panel_focused = this.window.is_focused().unwrap_or(false); + // A mini window is a browser window like the main one: + // moving to it puts the launcher away. let main_focused = this .window .app_handle() .get_webview_window(crate::MAIN_LABEL) - .is_some_and(|window| window.is_focused().unwrap_or(false)); + .is_some_and(|window| window.is_focused().unwrap_or(false)) + || crate::mini::focused(this.window.app_handle()).is_some(); let app_active = application_active(panel_focused, main_focused); let old = this.snapshot(); let old_session = this.state().model.session(); diff --git a/desktop/src/overlay/model.rs b/desktop/src/overlay/model.rs index aba03a51e..0d9cd35f8 100644 --- a/desktop/src/overlay/model.rs +++ b/desktop/src/overlay/model.rs @@ -28,6 +28,9 @@ pub struct Model { /// The tab whose address this presentation edits, and that address. editing: Option<(String, String)>, pub switcher: Option, + /// This presentation chooses a page for a mini window: a new one, or + /// the one whose address it edits. + mini: bool, } impl Model { pub fn session(&self) -> String { @@ -37,6 +40,10 @@ impl Model { pub fn editing_tab(&self) -> Option { self.editing.as_ref().map(|(tab, _)| tab.clone()) } + /// Whether this presentation chooses a page for a mini window. + pub fn mini(&self) -> bool { + self.mini + } pub fn snapshot(&self) -> PanelState { PanelState { switcher: self.switcher.clone(), @@ -51,6 +58,7 @@ impl Model { corner_radius: RADIUS, seed: self.editing.as_ref().map(|(_, url)| url.clone()), seed_tab: self.editing_tab(), + mini: self.mini, } } pub fn reject(&mut self) { @@ -96,6 +104,12 @@ impl Model { self.error = false; self.editing = None; self.switcher = None; + self.mini = false; + } + /// Opens to choose the address of a new mini window. + pub fn search_mini(&mut self) { + self.search(); + self.mini = self.presented; } /// Opens on a tab's address, so a chosen result replaces that tab's page. pub fn edit(&mut self, tab: String, url: String) { @@ -111,6 +125,11 @@ impl Model { self.publication = self.publication.saturating_add(1); self.switcher = Some(switcher); } + /// Opens on the address of a mini window's page. + pub fn edit_mini(&mut self, tab: String, url: String) { + self.edit(tab, url); + self.mini = self.presented; + } pub fn hide(&mut self) { if !self.advance() { return; @@ -119,6 +138,7 @@ impl Model { self.error = false; self.editing = None; self.switcher = None; + self.mini = false; } pub fn record_focus_change(&mut self) -> FocusChange { self.focus_change = FocusChange { @@ -326,6 +346,29 @@ mod tests { assert!(!m.snapshot().visible); } + #[test] + fn editing_a_mini_page_is_a_mini_presentation() { + let mut m = Model::default(); + m.edit_mini("tab".into(), "https://example.com/".into()); + assert!(m.presented && m.mini() && m.editing_tab().is_some()); + m.edit("tab".into(), "https://example.com/".into()); + assert!(m.presented && !m.mini()); + } + #[test] + fn a_mini_presentation_ends_with_its_session() { + let mut m = Model::default(); + m.search_mini(); + assert!(m.presented && m.mini() && m.snapshot().mini); + m.hide(); + assert!(!m.mini()); + m.search_mini(); + m.search(); + assert!(m.presented && !m.mini()); + m.search_mini(); + m.edit("tab".into(), "https://example.com/".into()); + assert!(!m.mini()); + } + #[test] fn editing_seeds_the_address_and_keeps_the_panel_session() { let mut m = Model::default(); diff --git a/desktop/src/platform/macos.rs b/desktop/src/platform/macos.rs index 7637fca46..fbc64807e 100644 --- a/desktop/src/platform/macos.rs +++ b/desktop/src/platform/macos.rs @@ -37,7 +37,8 @@ static CHROME_GENERATION: AtomicU64 = AtomicU64::new(0); static NEXT_CHROME_GENERATION: AtomicU64 = AtomicU64::new(1); static NEXT_PRIVILEGED_DELEGATE_GENERATION: AtomicU64 = AtomicU64::new(1); static CHROME_ORIGIN: Mutex = Mutex::new(ChromeOrigin::empty()); -const MAX_PRIVILEGED_UI_DELEGATES: usize = 2; +/// Main chrome, the launcher, and one toolbar per mini window. +const MAX_PRIVILEGED_UI_DELEGATES: usize = 2 + zephium_app::MAX_MINI_WINDOWS; struct ChromeViewState { generation: u64, @@ -366,6 +367,52 @@ pub fn restart_content_process(window: &WebviewWindow) { }); } +/// Pins a mini window's toolbar WebView to the top `height` points of its +/// window, so it never overlaps the page stage below it (the cursor-fight +/// rule). AppKit keeps it there as the window resizes. +pub fn fit_toolbar(window: &WebviewWindow, height: f64) -> bool { + let (send, receive) = std::sync::mpsc::sync_channel(1); + let scheduled = window.with_webview(move |webview| { + use objc2_app_kit::NSAutoresizingMaskOptions as Mask; + use objc2_foundation::{NSPoint, NSRect, NSSize}; + // SAFETY: Tauri supplies a live WKWebView pointer for the duration + // of this main-thread callback. + let webkit: &WKWebView = unsafe { &*webview.inner().cast() }; + let Some(superview) = (unsafe { webkit.superview() }) else { + let _ = send.send(false); + return; + }; + let bounds = superview.bounds(); + let frame = NSRect::new( + NSPoint::new(0.0, (bounds.size.height - height).max(0.0)), + NSSize::new(bounds.size.width, height.min(bounds.size.height)), + ); + webkit.setTranslatesAutoresizingMaskIntoConstraints(true); + webkit.setAutoresizingMask(Mask::ViewWidthSizable | Mask::ViewMinYMargin); + webkit.setFrame(frame); + let _ = send.send(true); + }); + scheduled.is_ok() && receive.try_recv().unwrap_or(false) +} + +/// The size of any window's content area in points, read from AppKit rather +/// than from a WebView that may have been resized inside it. +pub fn window_content_size(window: &WebviewWindow) -> Option { + MainThreadMarker::new()?; + let pointer = window.ns_window().ok()?; + if pointer.is_null() { + return None; + } + // SAFETY: Tauri returns the live NSWindow it owns; this runs on the main + // thread and only reads its content view's bounds. + let ns_window: &objc2_app_kit::NSWindow = unsafe { &*pointer.cast() }; + let bounds = ns_window.contentView()?.bounds(); + Some(zephium_core::geometry::Size::new( + bounds.size.width, + bounds.size.height, + )) +} + pub fn harden_privileged(window: &WebviewWindow) -> bool { let installed = Arc::new(AtomicU64::new(0)); let completed = installed.clone(); @@ -536,6 +583,15 @@ impl PresentationChrome for ChromeAdapter { ) -> ChromePresentationDispatch { crate::apply_chrome_presentation(&self.window, presentation, done) } + + fn apply_mini_presentation( + &self, + window: u64, + presentation: ChromePresentation, + done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + crate::mini::apply_presentation(self.window.app_handle(), window, presentation, done) + } } fn dispatch_chrome_layout( diff --git a/desktop/src/platform/windows.rs b/desktop/src/platform/windows.rs index 668948082..304eb283c 100644 --- a/desktop/src/platform/windows.rs +++ b/desktop/src/platform/windows.rs @@ -161,7 +161,11 @@ pub fn init( // A visual enhancement must never remove access to window controls. let _ = window.set_decorations(true); } - let hardened = harden_privileged(window, expected_user_data_folder, on_runtime_update); + let hardened = harden_privileged( + window, + expected_user_data_folder, + PrivilegedEnvironment::Own(on_runtime_update), + ); apply_material(window, true); hardened } @@ -183,13 +187,23 @@ fn bridge_caption_keys(window: &WebviewWindow) { } } +/// Whose browser process a privileged WebView runs in. +pub enum PrivilegedEnvironment { + /// Its own: the WebView registers it, so teardown proves its exit. + Own(RuntimeUpdateCallback), + /// The one already registered under this label, which it shares through + /// the same user-data folder and arguments, as a mini window's toolbar + /// shares the launcher's. Teardown's proof for that label covers it. + Joined(&'static str), +} + /// Tauri does not expose Wry's permission callback. Install the WebView2 /// policy directly for privileged chrome so an XSS cannot prompt for ambient /// capabilities or persist password/form suggestions in its shared UDF. pub fn harden_privileged( window: &WebviewWindow, expected_user_data_folder: &Path, - on_runtime_update: RuntimeUpdateCallback, + environment_owner: PrivilegedEnvironment, ) -> Result<(), StartupFailure> { let installed = Arc::new(AtomicBool::new(false)); let completed = installed.clone(); @@ -434,15 +448,34 @@ pub fn harden_privileged( })), &mut external_token, )?; - zephium_engine::install_privileged_environment_registration( - label, - &environment, - on_runtime_update, - )?; - let mut browser = 0_u32; - // An id left unread records nothing, which invalidates the record. - let _ = core.BrowserProcessId(&mut browser); - crate::privileged_runtime_windows::record_browser_process(browser); + match environment_owner { + PrivilegedEnvironment::Own(on_runtime_update) => { + zephium_engine::install_privileged_environment_registration( + label, + &environment, + on_runtime_update, + )?; + let mut browser = 0_u32; + // An id left unread records nothing, which invalidates the record. + let _ = core.BrowserProcessId(&mut browser); + crate::privileged_runtime_windows::record_browser_process(browser); + } + PrivilegedEnvironment::Joined(owner) => { + // A browser this run's record and exit proof do not + // cover must never host privileged chrome. + let mut browser = 0_u32; + core.BrowserProcessId(&mut browser)?; + if browser == 0 + || zephium_engine::privileged_environment_process(owner) != Some(browser) + { + return Err(windows::core::Error::new( + windows::Win32::Foundation::E_ACCESSDENIED, + "privileged WebView2 did not join its registered browser process", + ) + .into()); + } + } + } Ok(()) })(); if let Err(error) = result { @@ -861,6 +894,15 @@ impl PresentationChrome for ChromeAdapter { ) -> ChromePresentationDispatch { crate::apply_chrome_presentation(&self.window, presentation, done) } + + fn apply_mini_presentation( + &self, + window: u64, + presentation: ChromePresentation, + done: ChromePresentationCallback, + ) -> ChromePresentationDispatch { + crate::mini::apply_presentation(self.window.app_handle(), window, presentation, done) + } } pub fn content_size(_window: &WebviewWindow) -> Option { diff --git a/desktop/src/renderer_recovery.rs b/desktop/src/renderer_recovery.rs index b560d3ede..16d55908c 100644 --- a/desktop/src/renderer_recovery.rs +++ b/desktop/src/renderer_recovery.rs @@ -150,6 +150,14 @@ pub(crate) fn failed(app: &AppHandle, label: &str, browser_exited: bool) { if crate::shutdown_started(app) { return; } + // A mini window's toolbar recovers on its own terms; with the whole + // browser gone the launcher's recovery speaks for both. + if crate::mini::window_of(label).is_some() { + if !browser_exited { + crate::mini::recover(app, label); + } + return; + } let Some(renderers) = app.try_state::() else { return; }; diff --git a/docs/architecture.md b/docs/architecture.md index a6d77b225..30715e302 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -76,6 +76,21 @@ Engine callbacks and native object access must respect their platform thread and lifetime requirements. Keep platform-specific operations in the appropriate `platform/` and `host/` modules, with application policy expressed through ports. +**Mini windows.** A mini window holds one page outside the sidebar. Links +from other apps open in one by default (`tabs.external-position = mini`); +`window.newMini` opens the launcher in mini mode, which offers only sites, and +a link a mini page opens gets its own mini window of the same profile. The +page is `Placement::Mini`: never saved, kept awake while its window is open. +`desktop/src/mini.rs` builds each window, `mini-`, with a privileged +toolbar (`frame/mini.html`) above a content stage the engine attaches to it. +`zephium-app` owns admission (cap, profile, private refusal), the pin and the +remembered size; "Open in Zephium" moves the live page into the main window +without a reload, and a window that cannot be built hands its page back as a +tab. On macOS the stage is reparented as an NSView; on Windows the page's +WebView2 controller is reparented to the mini window's HWND, the window draws +no frame, and its toolbar joins the launcher's privileged WebView2 browser +instead of starting another. + ## 4. State, commands, and IPC The typical path is: diff --git a/frame/bootstrap-report.ts b/frame/bootstrap-report.ts index 8e734bf09..39c4ab1d7 100644 --- a/frame/bootstrap-report.ts +++ b/frame/bootstrap-report.ts @@ -10,7 +10,7 @@ import type { Plugin } from "vite"; const BUDGETS = new URL("./bundle-budgets.json", import.meta.url); /** A page native loads into a privileged WebView. */ -export type Page = "browser" | "panel" | "onboarding"; +export type Page = "browser" | "panel" | "mini" | "onboarding"; /** Inspect emitted graphs: source folders alone cannot guarantee startup isolation. */ export function bootstrapReport(pages: readonly Page[]): Plugin { @@ -79,10 +79,10 @@ export function bootstrapReport(pages: readonly Page[]): Plugin { surface: false, }); } - const panel = roots.find((root) => root.name === "panel"); - // The launcher's WebView is resident all day. Anything it can load - // at all, not just at startup, is paid again on top of the browser's - // copy, so an editor or a tool view must be unreachable from it. + // The launcher's WebView is resident all day, and a mini window's + // toolbar lives as long as its page. Anything either can load at all, + // not just at startup, is paid again on top of the browser's copy, so + // an editor or a tool view must be unreachable from them. const reachable = new Set(); const reach = (file: string) => { if (reachable.has(file)) return; @@ -94,10 +94,10 @@ export function bootstrapReport(pages: readonly Page[]): Plugin { /\/(?:@tiptap|prosemirror-[a-z]+|@xyflow|layerchart)\//u.test(id) || /\/src\/features\/(?:notes|tools|work|history|downloads)\//u.test(id) ) - this.error(`Panel can load ${id}, which the browser already hosts`); + this.error(`A side window can load ${id}, which the browser already hosts`); for (const child of [...item.imports, ...item.dynamicImports]) reach(child); }; - if (panel) reach(panel.file); + for (const root of roots) if (root.name === "panel" || root.name === "mini") reach(root.file); // A first run has its own page and build; nothing of it may be loadable // from the browser, eagerly or lazily, so no later launch carries it. const browser = roots.find((root) => root.name === "browser"); @@ -162,8 +162,8 @@ export function bootstrapReport(pages: readonly Page[]): Plugin { "src/session/tool-drafts.svelte.ts", ].includes(id), ); - if (name === "panel" && forbidden.length) - this.error(`Panel eagerly loads browser/tool code: ${forbidden.join(", ")}`); + if ((name === "panel" || name === "mini") && forbidden.length) + this.error(`${name} eagerly loads browser/tool code: ${forbidden.join(", ")}`); graphs.set(name, { visited, css }); const js = bytes(visited); diff --git a/frame/bundle-budgets.json b/frame/bundle-budgets.json index 997957724..a4a6670ab 100644 --- a/frame/bundle-budgets.json +++ b/frame/bundle-budgets.json @@ -1,470 +1,474 @@ { - "browser-panel": { + "onboarding": { + "onboarding": { + "js": 249755, + "css": 127557 + } + }, + "browser-panel-mini": { "browser": { - "js": 517238, - "css": 159147 + "js": 522918, + "css": 159079 }, "lazy:app/browser/WorkWorkspace.svelte": { - "js": 38319, + "js": 43787, "css": 364 }, "lazy:domain/notes/index.ts": { - "js": 14752, + "js": 14754, "css": 0 }, "lazy:domain/work-environment/index.ts": { - "js": 34903, + "js": 40469, "css": 0 }, "lazy:features/account/components/AccountButton.svelte": { - "js": 8720, + "js": 8501, "css": 7458 }, "lazy:features/account/index.ts": { - "js": 149, + "js": 151, "css": 0 }, "lazy:features/address/components/PageRequestCard.svelte": { - "js": 12100, + "js": 12584, "css": 2377 }, "lazy:features/address/components/SiteDetailsBody.svelte": { - "js": 10029, + "js": 9839, "css": 2200 }, "lazy:features/assist/components/AssistPanel.svelte": { - "js": 275160, - "css": 47445 + "js": 270352, + "css": 48424 }, "lazy:features/assist/components/PageStyles.svelte": { - "js": 8990, + "js": 8920, "css": 3698 }, "lazy:features/blocker/components/ProtectionMenu.svelte": { - "js": 16096, - "css": 4492 + "js": 17371, + "css": 5187 }, "lazy:features/bookmarks/components/BookmarksPanel.svelte": { - "js": 21135, + "js": 20759, "css": 6190 }, "lazy:features/downloads/components/DownloadsList.svelte": { - "js": 13973, + "js": 13717, "css": 4459 }, "lazy:features/history/components/HistoryPage.svelte": { - "js": 143455, - "css": 10803 + "js": 143908, + "css": 12235 }, "lazy:features/history/components/HistoryPanel.svelte": { - "js": 16263, + "js": 15972, "css": 4565 }, "lazy:features/library/components/LibraryPage.svelte": { - "js": 2412, + "js": 2257, "css": 0 }, "lazy:features/media/components/MediaPlayer.svelte": { - "js": 8399, + "js": 8335, "css": 7012 }, "lazy:features/newtab/components/CustomBackground.svelte": { - "js": 715, + "js": 716, "css": 241 }, "lazy:features/newtab/components/NewTab.svelte": { - "js": 52390, + "js": 52047, "css": 15855 }, "lazy:features/notes/components/editor/NoteEditor.svelte": { - "js": 439012, + "js": 452170, "css": 11897 }, "lazy:features/notes/components/NoteHost.svelte": { - "js": 23753, + "js": 23707, "css": 3598 }, "lazy:features/notes/components/Notes.svelte": { - "js": 142814, - "css": 14971 + "js": 144918, + "css": 16403 }, "lazy:features/notes/components/NotesPage.svelte": { - "js": 165834, - "css": 21061 + "js": 167942, + "css": 22493 }, "lazy:features/notes/index.ts": { - "js": 388, + "js": 390, "css": 0 }, "lazy:features/search/components/LauncherPanel.svelte": { - "js": 121170, - "css": 14424 + "js": 122324, + "css": 15043 }, "lazy:features/search/components/NewTabSearch.svelte": { - "js": 116916, + "js": 118789, "css": 10108 }, "lazy:features/settings/components/account/AccountAvatarCrop.svelte": { - "js": 9486, + "js": 9349, "css": 5508 }, "lazy:features/settings/components/account/AccountCredits.svelte": { - "js": 4575, + "js": 4367, "css": 3522 }, "lazy:features/settings/components/account/AccountEmailFlow.svelte": { - "js": 5001, + "js": 4826, "css": 322 }, "lazy:features/settings/components/account/AccountHistory.svelte": { - "js": 12360, + "js": 12236, "css": 2717 }, "lazy:features/settings/components/account/AccountPlanChange.svelte": { - "js": 11543, + "js": 11206, "css": 1398 }, "lazy:features/settings/components/account/AccountPlans.svelte": { - "js": 5520, + "js": 5389, "css": 2176 }, "lazy:features/settings/components/ClearSiteData.svelte": { - "js": 4426, + "js": 4101, "css": 944 }, "lazy:features/settings/components/sections/AboutPage.svelte": { - "js": 22508, + "js": 22040, "css": 2383 }, "lazy:features/settings/components/sections/AccountPage.svelte": { - "js": 73399, + "js": 72695, "css": 20966 }, "lazy:features/settings/components/sections/AiPage.svelte": { - "js": 75613, + "js": 77322, "css": 5586 }, "lazy:features/settings/components/sections/AppearancePage.svelte": { - "js": 32976, + "js": 32866, "css": 17553 }, "lazy:features/settings/components/sections/ConnectionsPage.svelte": { - "js": 65718, + "js": 67117, "css": 8881 }, "lazy:features/settings/components/sections/FeaturesPage.svelte": { - "js": 6742, + "js": 6342, "css": 3085 }, "lazy:features/settings/components/sections/FocusPage.svelte": { - "js": 4109, + "js": 3964, "css": 52 }, "lazy:features/settings/components/sections/GeneralPage.svelte": { - "js": 58404, - "css": 7547 + "js": 58473, + "css": 7657 }, "lazy:features/settings/components/sections/KeyboardPage.svelte": { - "js": 22354, + "js": 22561, "css": 1976 }, "lazy:features/settings/components/sections/MemoryPage.svelte": { - "js": 16116, + "js": 15975, "css": 4096 }, "lazy:features/settings/components/sections/PerformancePage.svelte": { - "js": 6755, + "js": 6554, "css": 1856 }, "lazy:features/settings/components/sections/PrivacyPage.svelte": { - "js": 50254, + "js": 50133, "css": 6866 }, "lazy:features/settings/components/sections/ProfilesPage.svelte": { - "js": 26220, + "js": 25944, "css": 7064 }, "lazy:features/settings/components/sections/SearchPage.svelte": { - "js": 15488, + "js": 16091, "css": 3784 }, "lazy:features/settings/components/sections/SitesPage.svelte": { - "js": 11906, + "js": 11730, "css": 1661 }, "lazy:features/settings/components/sections/SkillsPage.svelte": { - "js": 19408, + "js": 19242, "css": 5284 }, "lazy:features/settings/components/sections/TabsPage.svelte": { - "js": 3202, + "js": 3153, "css": 0 }, "lazy:features/settings/components/sections/WorkPage.svelte": { - "js": 13718, + "js": 13175, "css": 3760 }, "lazy:features/settings/components/Settings.svelte": { - "js": 144857, - "css": 9599 + "js": 145530, + "css": 11031 }, "lazy:features/settings/components/SettingsIdentity.svelte": { - "js": 2318, + "js": 2214, "css": 611 }, "lazy:features/source/components/SourcePage.svelte": { - "js": 3670, + "js": 3599, "css": 1140 }, "lazy:features/tabs/components/NavigationError.svelte": { - "js": 8068, + "js": 7875, "css": 452 }, "lazy:features/tabs/components/SpaceEditor.svelte": { - "js": 10883, + "js": 10812, "css": 5623 }, "lazy:features/tabs/components/SpaceSwitcher.svelte": { - "js": 5219, + "js": 5155, "css": 4029 }, "lazy:features/tabs/components/TabCapacityState.svelte": { - "js": 1601, + "js": 1546, "css": 340 }, "lazy:features/tasks/components/TaskBoard.svelte": { - "js": 10454, + "js": 10391, "css": 5136 }, "lazy:features/tasks/components/TaskDetail.svelte": { - "js": 18628, + "js": 18651, "css": 7369 }, "lazy:features/tasks/components/Tasks.svelte": { - "js": 279630, - "css": 27236 + "js": 282069, + "css": 28668 }, "lazy:features/tasks/components/TasksPage.svelte": { - "js": 331450, - "css": 37415 + "js": 333255, + "css": 38847 }, "lazy:features/tasks/lib/capture.ts": { - "js": 34551, + "js": 34553, "css": 0 }, "lazy:features/time/components/FocusCover.svelte": { - "js": 4850, + "js": 4582, "css": 2053 }, "lazy:features/time/components/TimePage.svelte": { - "js": 151314, - "css": 21140 + "js": 153125, + "css": 22572 }, "lazy:features/time/components/TimePanel.svelte": { - "js": 142549, - "css": 19228 + "js": 144469, + "css": 20660 }, "lazy:features/tools/components/previews/BookmarksView.svelte": { - "js": 10830, - "css": 3822 + "js": 15511, + "css": 4121 }, "lazy:features/tools/components/previews/ChatView.svelte": { - "js": 6561, - "css": 3256 + "js": 11087, + "css": 3555 }, "lazy:features/tools/components/previews/DownloadsView.svelte": { - "js": 6635, - "css": 3256 + "js": 11109, + "css": 3555 }, "lazy:features/tools/components/previews/HistoryView.svelte": { - "js": 6941, - "css": 3256 + "js": 11410, + "css": 3555 }, "lazy:features/tools/components/previews/NotesView.svelte": { - "js": 143242, - "css": 9308 + "js": 33460, + "css": 5167 }, "lazy:features/tools/components/previews/TasksView.svelte": { - "js": 148336, - "css": 9070 + "js": 154046, + "css": 10354 }, "lazy:features/tools/components/previews/TimeView.svelte": { - "js": 121621, - "css": 7696 + "js": 11901, + "css": 3555 }, "lazy:features/tools/components/ToolSlot.svelte": { - "js": 7737, + "js": 7180, "css": 369 }, "lazy:features/updates/components/UpdateCards.svelte": { - "js": 14308, + "js": 13731, "css": 4707 }, "lazy:features/updates/components/UpdateGlyph.svelte": { - "js": 11442, + "js": 10931, "css": 1816 }, "lazy:features/webext/components/WebExtensionManager.svelte": { - "js": 223289, - "css": 13351 + "js": 225498, + "css": 14783 }, "lazy:features/work/components/AgentLine.svelte": { - "js": 66636, + "js": 66192, "css": 26429 }, "lazy:features/work/components/bar/ModelPicker.svelte": { - "js": 175043, - "css": 34536 + "js": 175598, + "css": 35968 }, "lazy:features/work/components/bar/VoiceView.svelte": { - "js": 17087, + "js": 17331, "css": 4685 }, "lazy:features/work/components/local/CommandInspector.svelte": { - "js": 8394, + "js": 8208, "css": 1582 }, "lazy:features/work/components/local/CommandRecord.svelte": { - "js": 3890, + "js": 3763, "css": 838 }, "lazy:features/work/components/objects/Code.svelte": { - "js": 15770, + "js": 15644, "css": 3697 }, "lazy:features/work/components/objects/Diagram.svelte": { - "js": 47273, + "js": 46729, "css": 4941 }, "lazy:features/work/components/objects/Diff.svelte": { - "js": 14674, + "js": 14510, "css": 3384 }, "lazy:features/work/components/objects/Document.svelte": { - "js": 3610, + "js": 3574, "css": 1716 }, "lazy:features/work/components/objects/Draft.svelte": { - "js": 10880, + "js": 10756, "css": 5127 }, "lazy:features/work/components/objects/File.svelte": { - "js": 17714, + "js": 17629, "css": 4705 }, "lazy:features/work/components/objects/Folder.svelte": { - "js": 1958, + "js": 1899, "css": 1607 }, "lazy:features/work/components/objects/List.svelte": { - "js": 10985, + "js": 10711, "css": 7237 }, "lazy:features/work/components/objects/Media.svelte": { - "js": 6465, + "js": 6343, "css": 3442 }, "lazy:features/work/components/objects/Note.svelte": { - "js": 3397, + "js": 3354, "css": 908 }, "lazy:features/work/components/objects/ObjectCentre.svelte": { - "js": 10908, + "js": 10835, "css": 6250 }, "lazy:features/work/components/objects/Page.svelte": { - "js": 5165, + "js": 5155, "css": 2538 }, "lazy:features/work/components/objects/Picks.svelte": { - "js": 45282, + "js": 44780, "css": 22782 }, "lazy:features/work/components/objects/Plan.svelte": { - "js": 23992, + "js": 23770, "css": 12118 }, "lazy:features/work/components/objects/Plot.svelte": { - "js": 1559, + "js": 1564, "css": 457 }, "lazy:features/work/components/objects/Project.svelte": { - "js": 9407, + "js": 9232, "css": 5472 }, "lazy:features/work/components/objects/Sheet.svelte": { - "js": 20868, + "js": 20668, "css": 8733 }, "lazy:features/work/components/objects/Subject.svelte": { - "js": 10328, + "js": 10181, "css": 3033 }, "lazy:features/work/components/objects/TableBlock.svelte": { - "js": 3990, + "js": 3950, "css": 2120 }, "lazy:features/work/components/pane/TakeoverPane.svelte": { - "js": 6235, + "js": 6159, "css": 3332 }, "lazy:features/work/components/parts/ComputerPart.svelte": { - "js": 10379, + "js": 10211, "css": 4830 }, "lazy:features/work/components/parts/ConnectionPart.svelte": { - "js": 8998, + "js": 8921, "css": 1659 }, "lazy:features/work/components/start/WorkStart.svelte": { - "js": 33174, + "js": 33083, "css": 6727 }, "lazy:features/work/components/WorkCanvas.svelte": { - "js": 444200, - "css": 123415 + "js": 447544, + "css": 123408 }, "lazy:features/work/components/WorkEnvironmentWorkspace.svelte": { - "js": 574615, - "css": 53157 + "js": 581484, + "css": 54589 }, "lazy:features/work/components/WorkFileInspector.svelte": { - "js": 7209, + "js": 6998, "css": 1135 }, "lazy:features/work/components/WorkResultInspector.svelte": { - "js": 62672, + "js": 61956, "css": 29168 }, "lazy:features/work/components/WorkSubjectInspector.svelte": { - "js": 13868, + "js": 13785, "css": 4388 }, "lazy:features/work/lib/diagram-worker.ts": { - "js": 15881, + "js": 15880, "css": 0 }, "lazy:shared/ui/data/Artifact/WorkChart.svelte": { - "js": 45454, + "js": 45177, "css": 10496 }, "lazy:shared/ui/data/Chart/Chart.svelte": { - "js": 44527, + "js": 44299, "css": 10496 }, "lazy:shared/ui/data/Code/CodeBlock.svelte": { - "js": 13269, + "js": 13200, "css": 2750 }, + "mini": { + "js": 208374, + "css": 49530 + }, "panel": { - "js": 134179, - "css": 54537 - } - }, - "onboarding": { - "onboarding": { - "js": 245643, - "css": 127714 + "js": 136419, + "css": 54285 } } } diff --git a/frame/messages/de.json b/frame/messages/de.json index 07d799a43..d6fd0d964 100644 --- a/frame/messages/de.json +++ b/frame/messages/de.json @@ -234,6 +234,7 @@ "command_browser_settings": "Einstellungen", "command_tab_new": "Neuer Tab", "command_window_new_private": "Neues privates Fenster", + "command_window_new_mini": "Neues kleines Fenster", "command_window_close_private": "Privates Fenster schließen", "command_window_toggle_private": "Privates Fenster umschalten", "command_window_show_regular": "Zum normalen Fenster wechseln", @@ -903,6 +904,7 @@ "panel_action_failed": "Diese Aktion konnte nicht abgeschlossen werden. Bitte versuch es erneut.", "panel_search_mode": "Suche", "panel_search_placeholder": "Suchen oder Adresse eingeben", + "panel_mini_placeholder": "In einem kleinen Fenster öffnen", "panel_clear_search": "Suche löschen", "panel_results": "Suchergebnisse", "panel_no_results": "Keine passenden Ergebnisse", @@ -3279,6 +3281,7 @@ "window_maximize": "Maximieren", "window_restore": "Wiederherstellen", "window_close": "Schließen", + "mini_open_in_main": "In Zephium öffnen", "profile_incognito": "Inkognito", "settings_identity_sign_in": "Anmelden", "settings_identity_sign_in_desc": "Zephium AI und deine Geräte", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Wie bei neuen Tabs", "tabs_external_option_end": "Neuer Tab am Ende", "tabs_external_option_next": "Neben dem aktuellen Tab", + "tabs_external_option_mini": "Kleines Fenster", "tabs_close_buttons": "Schaltflächen zum Schließen", "tabs_close_buttons_help": "Zeige die Schaltfläche zum Schließen eines Tabs, wenn du mit dem Zeiger darauf zeigst, oder bei jedem Tab.", "tabs_close_buttons_option_hover": "Beim Darüberfahren", @@ -3571,6 +3575,9 @@ "native_settings_more": "Einstellungen…", "native_new_tab": "Neuer Tab", "native_new_private_window": "Neues privates Fenster", + "native_new_mini_window": "Neues kleines Fenster", + "native_open_mini_window_in_zephium": "Kleines Fenster in Zephium öffnen", + "native_keep_mini_window_on_top": "Kleines Fenster im Vordergrund halten", "native_close_private_window": "Privates Fenster schließen", "native_toggle_private_window": "Privates Fenster umschalten", "native_regular_window": "Normales Fenster", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Im Vordergrund halten", + "mini_open_in_main_hint": "Diese Seite als Tab in Zephium verschieben", + "mini_choose_space": "Space wählen", + "command_mini_open_in_main": "Kleines Fenster in Zephium öffnen", + "command_mini_keep_on_top": "Kleines Fenster im Vordergrund halten" } diff --git a/frame/messages/en.json b/frame/messages/en.json index 54b39c0e8..98b003654 100644 --- a/frame/messages/en.json +++ b/frame/messages/en.json @@ -257,6 +257,7 @@ "command_browser_settings": "Settings", "command_tab_new": "New tab", "command_window_new_private": "New private window", + "command_window_new_mini": "New mini window", "command_window_close_private": "Close private window", "command_window_toggle_private": "Toggle private window", "command_window_show_regular": "Switch to regular window", @@ -932,6 +933,7 @@ "panel_action_failed": "That action could not be completed. Please try again.", "panel_search_mode": "Search", "panel_search_placeholder": "Search or enter an address", + "panel_mini_placeholder": "Open in a mini window", "panel_clear_search": "Clear search", "panel_results": "Search results", "panel_no_results": "No matching results", @@ -3322,6 +3324,7 @@ "window_maximize": "Maximize", "window_restore": "Restore Down", "window_close": "Close", + "mini_open_in_main": "Open in Zephium", "profile_incognito": "Incognito", "settings_identity_sign_in": "Sign in", "settings_identity_sign_in_desc": "Zephium AI and your devices", @@ -3339,6 +3342,7 @@ "tabs_external_option_same": "Same as new tabs", "tabs_external_option_end": "New tab at the end", "tabs_external_option_next": "Next to the current tab", + "tabs_external_option_mini": "Mini window", "tabs_close_buttons": "Close buttons", "tabs_close_buttons_help": "Show a tab’s close button when you point at it, or on every tab.", "tabs_close_buttons_option_hover": "On hover", @@ -3616,6 +3620,9 @@ "native_settings_more": "Settings…", "native_new_tab": "New Tab", "native_new_private_window": "New Private Window", + "native_new_mini_window": "New Mini Window", + "native_open_mini_window_in_zephium": "Open Mini Window in Zephium", + "native_keep_mini_window_on_top": "Keep Mini Window on Top", "native_close_private_window": "Close Private Window", "native_toggle_private_window": "Toggle Private Window", "native_regular_window": "Regular Window", @@ -3998,5 +4005,10 @@ "blocker_hiding_hidden": "{label} hidden", "blocker_hiding_pick": "Click anything on the page", "blocker_hiding_undo": "Undo", - "blocker_hiding_done": "Done" + "blocker_hiding_done": "Done", + "mini_keep_on_top": "Keep on top", + "mini_open_in_main_hint": "Move this page into Zephium as a tab", + "mini_choose_space": "Choose a space", + "command_mini_open_in_main": "Open mini window in Zephium", + "command_mini_keep_on_top": "Keep mini window on top" } diff --git a/frame/messages/es.json b/frame/messages/es.json index 0dbc8c0e6..43caa5231 100644 --- a/frame/messages/es.json +++ b/frame/messages/es.json @@ -234,6 +234,7 @@ "command_browser_settings": "Ajustes", "command_tab_new": "Nueva pestaña", "command_window_new_private": "Nueva ventana privada", + "command_window_new_mini": "Nueva ventana pequeña", "command_window_close_private": "Cerrar ventana privada", "command_window_toggle_private": "Alternar ventana privada", "command_window_show_regular": "Cambiar a la ventana normal", @@ -903,6 +904,7 @@ "panel_action_failed": "No se pudo completar esa acción. Inténtalo de nuevo.", "panel_search_mode": "Buscar", "panel_search_placeholder": "Busca o escribe una dirección", + "panel_mini_placeholder": "Abrir en una ventana pequeña", "panel_clear_search": "Borrar búsqueda", "panel_results": "Resultados de búsqueda", "panel_no_results": "No hay resultados coincidentes", @@ -3279,6 +3281,7 @@ "window_maximize": "Maximizar", "window_restore": "Restaurar", "window_close": "Cerrar", + "mini_open_in_main": "Abrir en Zephium", "profile_incognito": "Incógnito", "settings_identity_sign_in": "Iniciar sesión", "settings_identity_sign_in_desc": "Zephium AI y tus dispositivos", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Igual que las pestañas nuevas", "tabs_external_option_end": "Nueva pestaña al final", "tabs_external_option_next": "Junto a la pestaña actual", + "tabs_external_option_mini": "Ventana pequeña", "tabs_close_buttons": "Botones de cerrar", "tabs_close_buttons_help": "Muestra el botón de cerrar de una pestaña al señalarla, o en todas las pestañas.", "tabs_close_buttons_option_hover": "Al pasar el cursor", @@ -3571,6 +3575,9 @@ "native_settings_more": "Ajustes…", "native_new_tab": "Nueva pestaña", "native_new_private_window": "Nueva ventana privada", + "native_new_mini_window": "Nueva ventana pequeña", + "native_open_mini_window_in_zephium": "Abrir la ventana pequeña en Zephium", + "native_keep_mini_window_on_top": "Mantener la ventana pequeña encima", "native_close_private_window": "Cerrar ventana privada", "native_toggle_private_window": "Alternar ventana privada", "native_regular_window": "Ventana normal", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Mantener encima", + "mini_open_in_main_hint": "Mover esta página a Zephium como pestaña", + "mini_choose_space": "Elegir un espacio", + "command_mini_open_in_main": "Abrir la ventana pequeña en Zephium", + "command_mini_keep_on_top": "Mantener la ventana pequeña encima" } diff --git a/frame/messages/fr.json b/frame/messages/fr.json index 8a7917f54..1de54bf9d 100644 --- a/frame/messages/fr.json +++ b/frame/messages/fr.json @@ -234,6 +234,7 @@ "command_browser_settings": "Réglages", "command_tab_new": "Nouvel onglet", "command_window_new_private": "Nouvelle fenêtre privée", + "command_window_new_mini": "Nouvelle petite fenêtre", "command_window_close_private": "Fermer la fenêtre privée", "command_window_toggle_private": "Basculer la fenêtre privée", "command_window_show_regular": "Passer à la fenêtre normale", @@ -903,6 +904,7 @@ "panel_action_failed": "Cette action n'a pas pu aboutir. Réessayez.", "panel_search_mode": "Rechercher", "panel_search_placeholder": "Rechercher ou saisir une adresse", + "panel_mini_placeholder": "Ouvrir dans une petite fenêtre", "panel_clear_search": "Effacer la recherche", "panel_results": "Résultats de recherche", "panel_no_results": "Aucun résultat correspondant", @@ -3279,6 +3281,7 @@ "window_maximize": "Agrandir", "window_restore": "Restaurer", "window_close": "Fermer", + "mini_open_in_main": "Ouvrir dans Zephium", "profile_incognito": "Incognito", "settings_identity_sign_in": "Se connecter", "settings_identity_sign_in_desc": "Zephium AI et vos appareils", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Comme les nouveaux onglets", "tabs_external_option_end": "Nouvel onglet à la fin", "tabs_external_option_next": "À côté de l’onglet actuel", + "tabs_external_option_mini": "Petite fenêtre", "tabs_close_buttons": "Boutons de fermeture", "tabs_close_buttons_help": "Afficher le bouton de fermeture d’un onglet quand vous le survolez, ou sur chaque onglet.", "tabs_close_buttons_option_hover": "Au survol", @@ -3571,6 +3575,9 @@ "native_settings_more": "Réglages…", "native_new_tab": "Nouvel onglet", "native_new_private_window": "Nouvelle fenêtre privée", + "native_new_mini_window": "Nouvelle petite fenêtre", + "native_open_mini_window_in_zephium": "Ouvrir la mini-fenêtre dans Zephium", + "native_keep_mini_window_on_top": "Garder la mini-fenêtre au premier plan", "native_close_private_window": "Fermer la fenêtre privée", "native_toggle_private_window": "Basculer la fenêtre privée", "native_regular_window": "Fenêtre normale", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Garder au premier plan", + "mini_open_in_main_hint": "Déplacer cette page dans Zephium en onglet", + "mini_choose_space": "Choisir un espace", + "command_mini_open_in_main": "Ouvrir la mini-fenêtre dans Zephium", + "command_mini_keep_on_top": "Garder la mini-fenêtre au premier plan" } diff --git a/frame/messages/it.json b/frame/messages/it.json index 63c01ce03..0ef54eb33 100644 --- a/frame/messages/it.json +++ b/frame/messages/it.json @@ -234,6 +234,7 @@ "command_browser_settings": "Impostazioni", "command_tab_new": "Nuova scheda", "command_window_new_private": "Nuova finestra privata", + "command_window_new_mini": "Nuova finestra piccola", "command_window_close_private": "Chiudi finestra privata", "command_window_toggle_private": "Alterna finestra privata", "command_window_show_regular": "Passa alla finestra normale", @@ -903,6 +904,7 @@ "panel_action_failed": "Impossibile completare l'azione. Riprova.", "panel_search_mode": "Cerca", "panel_search_placeholder": "Cerca o inserisci un indirizzo", + "panel_mini_placeholder": "Apri in una finestra piccola", "panel_clear_search": "Cancella ricerca", "panel_results": "Risultati di ricerca", "panel_no_results": "Nessun risultato corrispondente", @@ -3279,6 +3281,7 @@ "window_maximize": "Ingrandisci", "window_restore": "Ripristina", "window_close": "Chiudi", + "mini_open_in_main": "Apri in Zephium", "profile_incognito": "Incognito", "settings_identity_sign_in": "Accedi", "settings_identity_sign_in_desc": "Zephium AI e i tuoi dispositivi", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Come le nuove schede", "tabs_external_option_end": "Nuova scheda alla fine", "tabs_external_option_next": "Accanto alla scheda attuale", + "tabs_external_option_mini": "Finestra piccola", "tabs_close_buttons": "Pulsanti di chiusura", "tabs_close_buttons_help": "Mostra il pulsante di chiusura di una scheda quando ci passi sopra, oppure su ogni scheda.", "tabs_close_buttons_option_hover": "Al passaggio", @@ -3571,6 +3575,9 @@ "native_settings_more": "Impostazioni…", "native_new_tab": "Nuova scheda", "native_new_private_window": "Nuova finestra privata", + "native_new_mini_window": "Nuova finestra piccola", + "native_open_mini_window_in_zephium": "Apri la mini finestra in Zephium", + "native_keep_mini_window_on_top": "Mantieni la mini finestra in primo piano", "native_close_private_window": "Chiudi finestra privata", "native_toggle_private_window": "Alterna finestra privata", "native_regular_window": "Finestra normale", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Mantieni in primo piano", + "mini_open_in_main_hint": "Sposta questa pagina in Zephium come scheda", + "mini_choose_space": "Scegli uno spazio", + "command_mini_open_in_main": "Apri la mini finestra in Zephium", + "command_mini_keep_on_top": "Mantieni la mini finestra in primo piano" } diff --git a/frame/messages/ja.json b/frame/messages/ja.json index ad55f9b2b..78c287756 100644 --- a/frame/messages/ja.json +++ b/frame/messages/ja.json @@ -234,6 +234,7 @@ "command_browser_settings": "設定", "command_tab_new": "新規タブ", "command_window_new_private": "新規プライベートウインドウ", + "command_window_new_mini": "新規ミニウインドウ", "command_window_close_private": "プライベートウインドウを閉じる", "command_window_toggle_private": "プライベートウインドウを切り替える", "command_window_show_regular": "通常のウインドウに切り替える", @@ -903,6 +904,7 @@ "panel_action_failed": "操作を完了できませんでした。もう一度お試しください。", "panel_search_mode": "検索", "panel_search_placeholder": "検索またはアドレスを入力", + "panel_mini_placeholder": "ミニウインドウで開く", "panel_clear_search": "検索をクリア", "panel_results": "検索結果", "panel_no_results": "一致する結果はありません", @@ -3279,6 +3281,7 @@ "window_maximize": "最大化", "window_restore": "元のサイズに戻す", "window_close": "閉じる", + "mini_open_in_main": "Zephiumで開く", "profile_incognito": "シークレット", "settings_identity_sign_in": "サインイン", "settings_identity_sign_in_desc": "Zephium AIとデバイス", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "新規タブと同じ", "tabs_external_option_end": "末尾に新規タブ", "tabs_external_option_next": "現在のタブの隣", + "tabs_external_option_mini": "ミニウインドウ", "tabs_close_buttons": "閉じるボタン", "tabs_close_buttons_help": "タブにポインタを合わせたときだけ表示するか、すべてのタブに表示します。", "tabs_close_buttons_option_hover": "ポインタを合わせたとき", @@ -3571,6 +3575,9 @@ "native_settings_more": "設定…", "native_new_tab": "新規タブ", "native_new_private_window": "新規プライベートウインドウ", + "native_new_mini_window": "新規ミニウインドウ", + "native_open_mini_window_in_zephium": "ミニウインドウを Zephium で開く", + "native_keep_mini_window_on_top": "ミニウインドウを常に手前に表示", "native_close_private_window": "プライベートウインドウを閉じる", "native_toggle_private_window": "プライベートウインドウを切り替える", "native_regular_window": "通常のウインドウ", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "常に手前に表示", + "mini_open_in_main_hint": "このページをタブとして Zephium に移動", + "mini_choose_space": "スペースを選択", + "command_mini_open_in_main": "ミニウインドウを Zephium で開く", + "command_mini_keep_on_top": "ミニウインドウを常に手前に表示" } diff --git a/frame/messages/ko.json b/frame/messages/ko.json index b67019982..6b67ab445 100644 --- a/frame/messages/ko.json +++ b/frame/messages/ko.json @@ -234,6 +234,7 @@ "command_browser_settings": "설정", "command_tab_new": "새 탭", "command_window_new_private": "새 비공개 창", + "command_window_new_mini": "새 미니 윈도우", "command_window_close_private": "비공개 창 닫기", "command_window_toggle_private": "비공개 창 전환", "command_window_show_regular": "일반 창으로 전환", @@ -903,6 +904,7 @@ "panel_action_failed": "작업을 완료하지 못했어요. 다시 시도해 주세요.", "panel_search_mode": "검색", "panel_search_placeholder": "검색 또는 주소 입력", + "panel_mini_placeholder": "미니 윈도우에서 열기", "panel_clear_search": "검색 지우기", "panel_results": "검색 결과", "panel_no_results": "일치하는 결과가 없어요", @@ -3279,6 +3281,7 @@ "window_maximize": "최대화", "window_restore": "이전 크기로 복원", "window_close": "닫기", + "mini_open_in_main": "Zephium에서 열기", "profile_incognito": "시크릿 모드", "settings_identity_sign_in": "로그인", "settings_identity_sign_in_desc": "Zephium AI와 내 기기", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "새 탭과 같게", "tabs_external_option_end": "끝에 새 탭", "tabs_external_option_next": "현재 탭 옆에", + "tabs_external_option_mini": "미니 윈도우", "tabs_close_buttons": "닫기 버튼", "tabs_close_buttons_help": "탭 위에 포인터를 올릴 때만, 또는 모든 탭에 닫기 버튼을 보여줘요.", "tabs_close_buttons_option_hover": "마우스를 올리면", @@ -3571,6 +3575,9 @@ "native_settings_more": "설정…", "native_new_tab": "새 탭", "native_new_private_window": "새 비공개 윈도우", + "native_new_mini_window": "새 미니 윈도우", + "native_open_mini_window_in_zephium": "미니 창을 Zephium에서 열기", + "native_keep_mini_window_on_top": "미니 창을 항상 위에 표시", "native_close_private_window": "비공개 윈도우 닫기", "native_toggle_private_window": "비공개 윈도우 전환", "native_regular_window": "일반 윈도우", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "항상 위에 표시", + "mini_open_in_main_hint": "이 페이지를 Zephium의 탭으로 옮기기", + "mini_choose_space": "스페이스 선택", + "command_mini_open_in_main": "미니 창을 Zephium에서 열기", + "command_mini_keep_on_top": "미니 창을 항상 위에 표시" } diff --git a/frame/messages/pt-BR.json b/frame/messages/pt-BR.json index 3becdc434..ea1b6e66e 100644 --- a/frame/messages/pt-BR.json +++ b/frame/messages/pt-BR.json @@ -234,6 +234,7 @@ "command_browser_settings": "Ajustes", "command_tab_new": "Nova aba", "command_window_new_private": "Nova janela privativa", + "command_window_new_mini": "Nova janela pequena", "command_window_close_private": "Fechar janela privativa", "command_window_toggle_private": "Alternar janela privativa", "command_window_show_regular": "Mudar para a janela normal", @@ -903,6 +904,7 @@ "panel_action_failed": "Não foi possível concluir esta ação. Tente novamente.", "panel_search_mode": "Pesquisar", "panel_search_placeholder": "Pesquise ou digite um endereço", + "panel_mini_placeholder": "Abrir em uma janela pequena", "panel_clear_search": "Limpar pesquisa", "panel_results": "Resultados da pesquisa", "panel_no_results": "Nenhum resultado correspondente", @@ -3279,6 +3281,7 @@ "window_maximize": "Maximizar", "window_restore": "Restaurar", "window_close": "Fechar", + "mini_open_in_main": "Abrir no Zephium", "profile_incognito": "Anônimo", "settings_identity_sign_in": "Entrar", "settings_identity_sign_in_desc": "Zephium AI e seus dispositivos", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Igual às novas abas", "tabs_external_option_end": "Nova aba no final", "tabs_external_option_next": "Ao lado da aba atual", + "tabs_external_option_mini": "Janela pequena", "tabs_close_buttons": "Botões de fechar", "tabs_close_buttons_help": "Mostre o botão de fechar de uma aba quando o ponteiro passar por ela, ou em todas as abas.", "tabs_close_buttons_option_hover": "Ao passar o ponteiro", @@ -3571,6 +3575,9 @@ "native_settings_more": "Ajustes…", "native_new_tab": "Nova Aba", "native_new_private_window": "Nova Janela Privativa", + "native_new_mini_window": "Nova Janela Pequena", + "native_open_mini_window_in_zephium": "Abrir a minijanela no Zephium", + "native_keep_mini_window_on_top": "Manter a minijanela na frente", "native_close_private_window": "Fechar Janela Privativa", "native_toggle_private_window": "Alternar Janela Privativa", "native_regular_window": "Janela Normal", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Manter na frente", + "mini_open_in_main_hint": "Mover esta página para o Zephium como aba", + "mini_choose_space": "Escolher um espaço", + "command_mini_open_in_main": "Abrir a minijanela no Zephium", + "command_mini_keep_on_top": "Manter a minijanela na frente" } diff --git a/frame/messages/ru.json b/frame/messages/ru.json index 913e0e4c0..897e18b95 100644 --- a/frame/messages/ru.json +++ b/frame/messages/ru.json @@ -234,6 +234,7 @@ "command_browser_settings": "Настройки", "command_tab_new": "Новая вкладка", "command_window_new_private": "Новое приватное окно", + "command_window_new_mini": "Новое мини-окно", "command_window_close_private": "Закрыть приватное окно", "command_window_toggle_private": "Переключить приватное окно", "command_window_show_regular": "Перейти в обычное окно", @@ -903,6 +904,7 @@ "panel_action_failed": "Не удалось выполнить действие. Попробуйте еще раз.", "panel_search_mode": "Поиск", "panel_search_placeholder": "Поиск или ввод адреса", + "panel_mini_placeholder": "Открыть в мини-окне", "panel_clear_search": "Очистить поиск", "panel_results": "Результаты поиска", "panel_no_results": "Нет подходящих результатов", @@ -3279,6 +3281,7 @@ "window_maximize": "Развернуть", "window_restore": "Восстановить", "window_close": "Закрыть", + "mini_open_in_main": "Открыть в Zephium", "profile_incognito": "Инкогнито", "settings_identity_sign_in": "Войти", "settings_identity_sign_in_desc": "Zephium AI и ваши устройства", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Как новые вкладки", "tabs_external_option_end": "Новая вкладка в конце", "tabs_external_option_next": "Рядом с текущей вкладкой", + "tabs_external_option_mini": "Мини-окно", "tabs_close_buttons": "Кнопки закрытия", "tabs_close_buttons_help": "Показывать кнопку закрытия вкладки при наведении на нее или на каждой вкладке.", "tabs_close_buttons_option_hover": "При наведении", @@ -3571,6 +3575,9 @@ "native_settings_more": "Настройки…", "native_new_tab": "Новая вкладка", "native_new_private_window": "Новое приватное окно", + "native_new_mini_window": "Новое мини-окно", + "native_open_mini_window_in_zephium": "Открыть мини-окно в Zephium", + "native_keep_mini_window_on_top": "Мини-окно поверх других окон", "native_close_private_window": "Закрыть приватное окно", "native_toggle_private_window": "Переключить приватное окно", "native_regular_window": "Обычное окно", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Поверх других окон", + "mini_open_in_main_hint": "Перенести эту страницу в Zephium как вкладку", + "mini_choose_space": "Выбрать пространство", + "command_mini_open_in_main": "Открыть мини-окно в Zephium", + "command_mini_keep_on_top": "Мини-окно поверх других окон" } diff --git a/frame/messages/tr.json b/frame/messages/tr.json index 03788eef8..2db0a8ea1 100644 --- a/frame/messages/tr.json +++ b/frame/messages/tr.json @@ -234,6 +234,7 @@ "command_browser_settings": "Ayarlar", "command_tab_new": "Yeni sekme", "command_window_new_private": "Yeni gizli pencere", + "command_window_new_mini": "Yeni küçük pencere", "command_window_close_private": "Gizli pencereyi kapat", "command_window_toggle_private": "Gizli pencereyi aç/kapat", "command_window_show_regular": "Normal pencereye geç", @@ -903,6 +904,7 @@ "panel_action_failed": "Bu işlem tamamlanamadı. Lütfen yeniden deneyin.", "panel_search_mode": "Ara", "panel_search_placeholder": "Arayın veya bir adres girin", + "panel_mini_placeholder": "Küçük bir pencerede aç", "panel_clear_search": "Aramayı temizle", "panel_results": "Arama sonuçları", "panel_no_results": "Eşleşen sonuç yok", @@ -3279,6 +3281,7 @@ "window_maximize": "Büyüt", "window_restore": "Geri Yükle", "window_close": "Kapat", + "mini_open_in_main": "Zephium'da aç", "profile_incognito": "Gizli", "settings_identity_sign_in": "Oturum aç", "settings_identity_sign_in_desc": "Zephium AI ve aygıtlarınız", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Yeni sekmelerle aynı", "tabs_external_option_end": "Sonda yeni sekme", "tabs_external_option_next": "Geçerli sekmenin yanında", + "tabs_external_option_mini": "Küçük pencere", "tabs_close_buttons": "Kapatma düğmeleri", "tabs_close_buttons_help": "Bir sekmenin kapatma düğmesi, üzerine geldiğinizde mi yoksa her sekmede mi gösterilsin.", "tabs_close_buttons_option_hover": "Üzerine gelince", @@ -3571,6 +3575,9 @@ "native_settings_more": "Ayarlar…", "native_new_tab": "Yeni Sekme", "native_new_private_window": "Yeni Gizli Pencere", + "native_new_mini_window": "Yeni Küçük Pencere", + "native_open_mini_window_in_zephium": "Mini pencereyi Zephium'da aç", + "native_keep_mini_window_on_top": "Mini pencereyi üstte tut", "native_close_private_window": "Gizli Pencereyi Kapat", "native_toggle_private_window": "Gizli Pencereyi Aç/Kapat", "native_regular_window": "Normal Pencere", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Üstte tut", + "mini_open_in_main_hint": "Bu sayfayı sekme olarak Zephium'a taşı", + "mini_choose_space": "Alan seç", + "command_mini_open_in_main": "Mini pencereyi Zephium'da aç", + "command_mini_keep_on_top": "Mini pencereyi üstte tut" } diff --git a/frame/messages/uk.json b/frame/messages/uk.json index ceb48dc1b..e4c53e294 100644 --- a/frame/messages/uk.json +++ b/frame/messages/uk.json @@ -234,6 +234,7 @@ "command_browser_settings": "Налаштування", "command_tab_new": "Нова вкладка", "command_window_new_private": "Нове приватне вікно", + "command_window_new_mini": "Нове міні-вікно", "command_window_close_private": "Закрити приватне вікно", "command_window_toggle_private": "Перемкнути приватне вікно", "command_window_show_regular": "Перейти до звичайного вікна", @@ -903,6 +904,7 @@ "panel_action_failed": "Не вдалося виконати цю дію. Спробуйте ще раз.", "panel_search_mode": "Пошук", "panel_search_placeholder": "Пошук або введіть адресу", + "panel_mini_placeholder": "Відкрити в міні-вікні", "panel_clear_search": "Очистити пошук", "panel_results": "Результати пошуку", "panel_no_results": "Немає відповідних результатів", @@ -3279,6 +3281,7 @@ "window_maximize": "Розгорнути", "window_restore": "Відновити розмір", "window_close": "Закрити", + "mini_open_in_main": "Відкрити в Zephium", "profile_incognito": "Інкогніто", "settings_identity_sign_in": "Увійти", "settings_identity_sign_in_desc": "Zephium AI і ваші пристрої", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "Так само, як нові вкладки", "tabs_external_option_end": "Нова вкладка в кінці", "tabs_external_option_next": "Поруч із поточною вкладкою", + "tabs_external_option_mini": "Міні-вікно", "tabs_close_buttons": "Кнопки закриття", "tabs_close_buttons_help": "Показувати кнопку закриття вкладки, коли на неї наводите курсор, або на кожній вкладці.", "tabs_close_buttons_option_hover": "Під час наведення", @@ -3571,6 +3575,9 @@ "native_settings_more": "Налаштування…", "native_new_tab": "Нова вкладка", "native_new_private_window": "Нове приватне вікно", + "native_new_mini_window": "Нове міні-вікно", + "native_open_mini_window_in_zephium": "Відкрити міні-вікно в Zephium", + "native_keep_mini_window_on_top": "Міні-вікно поверх інших вікон", "native_close_private_window": "Закрити приватне вікно", "native_toggle_private_window": "Перемкнути приватне вікно", "native_regular_window": "Звичайне вікно", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "Поверх інших вікон", + "mini_open_in_main_hint": "Перенести цю сторінку в Zephium як вкладку", + "mini_choose_space": "Вибрати простір", + "command_mini_open_in_main": "Відкрити міні-вікно в Zephium", + "command_mini_keep_on_top": "Міні-вікно поверх інших вікон" } diff --git a/frame/messages/zh-CN.json b/frame/messages/zh-CN.json index 24c29340c..67832cb70 100644 --- a/frame/messages/zh-CN.json +++ b/frame/messages/zh-CN.json @@ -234,6 +234,7 @@ "command_browser_settings": "设置", "command_tab_new": "新建标签页", "command_window_new_private": "新建隐私窗口", + "command_window_new_mini": "新建小窗口", "command_window_close_private": "关闭隐私窗口", "command_window_toggle_private": "切换隐私窗口", "command_window_show_regular": "切换到普通窗口", @@ -903,6 +904,7 @@ "panel_action_failed": "无法完成此操作,请重试。", "panel_search_mode": "搜索", "panel_search_placeholder": "搜索或输入地址", + "panel_mini_placeholder": "在小窗口中打开", "panel_clear_search": "清除搜索", "panel_results": "搜索结果", "panel_no_results": "没有匹配的结果", @@ -3279,6 +3281,7 @@ "window_maximize": "最大化", "window_restore": "还原", "window_close": "关闭", + "mini_open_in_main": "在 Zephium 中打开", "profile_incognito": "无痕浏览", "settings_identity_sign_in": "登录", "settings_identity_sign_in_desc": "Zephium AI 和你的设备", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "与新建标签页相同", "tabs_external_option_end": "在末尾新建标签页", "tabs_external_option_next": "在当前标签页旁边", + "tabs_external_option_mini": "小窗口", "tabs_close_buttons": "关闭按钮", "tabs_close_buttons_help": "将指针移到标签页上时显示其关闭按钮,或让每个标签页都显示关闭按钮。", "tabs_close_buttons_option_hover": "悬停时", @@ -3571,6 +3575,9 @@ "native_settings_more": "设置…", "native_new_tab": "新建标签页", "native_new_private_window": "新建隐私浏览窗口", + "native_new_mini_window": "新建小窗口", + "native_open_mini_window_in_zephium": "在 Zephium 中打开迷你窗口", + "native_keep_mini_window_on_top": "让迷你窗口保持在最前", "native_close_private_window": "关闭隐私浏览窗口", "native_toggle_private_window": "切换隐私窗口", "native_regular_window": "普通窗口", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "保持在最前", + "mini_open_in_main_hint": "将此页面作为标签页移入 Zephium", + "mini_choose_space": "选择空间", + "command_mini_open_in_main": "在 Zephium 中打开迷你窗口", + "command_mini_keep_on_top": "让迷你窗口保持在最前" } diff --git a/frame/messages/zh-TW.json b/frame/messages/zh-TW.json index 688c107ba..81cccc3ea 100644 --- a/frame/messages/zh-TW.json +++ b/frame/messages/zh-TW.json @@ -234,6 +234,7 @@ "command_browser_settings": "設定", "command_tab_new": "新增分頁", "command_window_new_private": "新增私密視窗", + "command_window_new_mini": "新增小視窗", "command_window_close_private": "關閉私密視窗", "command_window_toggle_private": "切換私密視窗", "command_window_show_regular": "切換到一般視窗", @@ -903,6 +904,7 @@ "panel_action_failed": "無法完成這項操作,請再試一次。", "panel_search_mode": "搜尋", "panel_search_placeholder": "搜尋或輸入網址", + "panel_mini_placeholder": "在小視窗中開啟", "panel_clear_search": "清除搜尋", "panel_results": "搜尋結果", "panel_no_results": "沒有符合的結果", @@ -3279,6 +3281,7 @@ "window_maximize": "縮放", "window_restore": "還原", "window_close": "關閉", + "mini_open_in_main": "在 Zephium 中開啟", "profile_incognito": "無痕", "settings_identity_sign_in": "登入", "settings_identity_sign_in_desc": "Zephium AI 與你的裝置", @@ -3296,6 +3299,7 @@ "tabs_external_option_same": "與新增分頁相同", "tabs_external_option_end": "新分頁放在最後", "tabs_external_option_next": "放在目前分頁旁", + "tabs_external_option_mini": "小視窗", "tabs_close_buttons": "關閉按鈕", "tabs_close_buttons_help": "指向分頁時顯示其關閉按鈕,或在每個分頁上都顯示。", "tabs_close_buttons_option_hover": "滑鼠指向時", @@ -3571,6 +3575,9 @@ "native_settings_more": "設定…", "native_new_tab": "新增分頁", "native_new_private_window": "新增私密視窗", + "native_new_mini_window": "新增小視窗", + "native_open_mini_window_in_zephium": "在 Zephium 中開啟迷你視窗", + "native_keep_mini_window_on_top": "讓迷你視窗保持在最上層", "native_close_private_window": "關閉私密視窗", "native_toggle_private_window": "切換私密視窗", "native_regular_window": "一般視窗", @@ -3908,5 +3915,10 @@ "privacy_windows_diagnostics_failed": "Could not open Windows Settings. Open Windows Settings and search for Diagnostics & feedback.", "privacy_microsoft_statement": "Microsoft privacy statement", "privacy_microsoft_statement_help": "Read how Microsoft handles SmartScreen and WebView2 data.", - "privacy_microsoft_statement_open": "Read privacy statement" + "privacy_microsoft_statement_open": "Read privacy statement", + "mini_keep_on_top": "保持在最上層", + "mini_open_in_main_hint": "將此頁面以分頁移入 Zephium", + "mini_choose_space": "選擇空間", + "command_mini_open_in_main": "在 Zephium 中開啟迷你視窗", + "command_mini_keep_on_top": "讓迷你視窗保持在最上層" } diff --git a/frame/mini.html b/frame/mini.html new file mode 100644 index 000000000..e3739aba9 --- /dev/null +++ b/frame/mini.html @@ -0,0 +1,12 @@ + + + + + + Zephium + + +
+ + + diff --git a/frame/src/app/mini/MiniApp.svelte b/frame/src/app/mini/MiniApp.svelte new file mode 100644 index 000000000..05ad24159 --- /dev/null +++ b/frame/src/app/mini/MiniApp.svelte @@ -0,0 +1,137 @@ + + + + +
+ + + +
diff --git a/frame/src/app/panel/tests/PanelApp.component.test.ts b/frame/src/app/panel/tests/PanelApp.component.test.ts index 20116f680..f371f930a 100644 --- a/frame/src/app/panel/tests/PanelApp.component.test.ts +++ b/frame/src/app/panel/tests/PanelApp.component.test.ts @@ -71,6 +71,7 @@ test("loads the launcher before startup IPC and preserves a live setting during corner_radius: 20, seed: null, seed_tab: null, + mini: false, }; }); await expect.poll(() => native.loading.mock.calls.length).toBe(1); diff --git a/frame/src/entries/mini.ts b/frame/src/entries/mini.ts new file mode 100644 index 000000000..536ff5784 --- /dev/null +++ b/frame/src/entries/mini.ts @@ -0,0 +1,15 @@ +import { getCurrentWindow } from "@tauri-apps/api/window"; +import { mount, flushSync } from "svelte"; +import App from "$app/mini/MiniApp.svelte"; + +try { + const label = getCurrentWindow().label; + if (!/^mini-[1-9]\d*$/.test(label)) throw new Error("unexpected native surface"); + const target = document.getElementById("root"); + if (!(target instanceof HTMLElement)) throw new Error("trusted UI root is unavailable"); + mount(App, { target, props: { label } }); + // The native presentation barrier observes this DOM synchronously. + flushSync(); +} catch { + console.error("trusted mini window initialization failed"); +} diff --git a/frame/src/features/mini/components/MiniToolbar.svelte b/frame/src/features/mini/components/MiniToolbar.svelte new file mode 100644 index 000000000..82f7d9590 --- /dev/null +++ b/frame/src/features/mini/components/MiniToolbar.svelte @@ -0,0 +1,325 @@ + + + +
+ + {#snippet control(icon: IconSvgElement, label: string, intent: MiniIntent, disabled: boolean)} + + {/snippet} +
+ {@render control(ArrowLeft02Icon, m.ui_back(), "back", tab?.can_go_back !== true)} + {@render control(ArrowRight02Icon, m.ui_forward(), "forward", tab?.can_go_forward !== true)} + {@render control(Refresh01Icon, m.ui_reload(), "reload", !tab)} +
+ {#if tab} + + {/if} + + + +
+ + {#if tab && spaces > 1} + + {/if} +
+ {#if frame === "controls"} +
+ + +
+ {/if} + {#if tab?.loading} + + {/if} +
+ + diff --git a/frame/src/features/mini/index.ts b/frame/src/features/mini/index.ts new file mode 100644 index 000000000..5bbf095f3 --- /dev/null +++ b/frame/src/features/mini/index.ts @@ -0,0 +1,2 @@ +export { acceptMiniTab, acceptMiniView, miniShortcut, windowOfLabel } from "./lib/mini-model"; +export { default as MiniToolbar } from "./components/MiniToolbar.svelte"; diff --git a/frame/src/features/mini/lib/mini-model.ts b/frame/src/features/mini/lib/mini-model.ts new file mode 100644 index 000000000..7a26ecb36 --- /dev/null +++ b/frame/src/features/mini/lib/mini-model.ts @@ -0,0 +1,59 @@ +import type { MiniIntent, MiniView, TabView } from "$shared/ipc/bindings"; + +const revision = /^[0-9a-f]{32}$/; + +/** The window a toolbar's label names: canonical decimal only, as native parses it. */ +export function windowOfLabel(label: string): number | null { + const match = /^mini-([1-9]\d*)$/.exec(label); + if (!match) return null; + const window = Number(match[1]); + return Number.isSafeInteger(window) ? window : null; +} + +/** A view for this window replaces the page shown, unless it is an older revision of it. */ +export function acceptMiniView(window: number, current: TabView | null, next: MiniView): boolean { + if (next.window !== window) return false; + return next.tab === null || acceptMiniTab(current, next.tab); +} + +export function acceptMiniTab(current: TabView | null, next: TabView): boolean { + return ( + revision.test(next.projection_revision) && + (!current || current.id !== next.id || next.projection_revision >= current.projection_revision) + ); +} + +/** The host the toolbar shows. Native's presentation check reads it back by the same rule. */ +export function hostOf(url: string | null): string { + if (!url) return ""; + try { + return new URL(url).host; + } catch { + return ""; + } +} + +type Keys = Pick; + +/** The window's own keys while its toolbar holds focus, under the platform's + * command modifier: open in Zephium, address, close, reload. */ +export function miniShortcut(event: Keys, mac: boolean): MiniIntent | null { + const command = mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey; + if (!command || event.altKey || event.shiftKey) return null; + switch (event.key.toLowerCase()) { + case "o": + return "open_in_main"; + case "l": + return "edit_address"; + case "w": + return "close"; + case "r": + return "reload"; + case "[": + return "back"; + case "]": + return "forward"; + default: + return null; + } +} diff --git a/frame/src/features/mini/tests/MiniToolbar.component.test.ts b/frame/src/features/mini/tests/MiniToolbar.component.test.ts new file mode 100644 index 000000000..a571d0755 --- /dev/null +++ b/frame/src/features/mini/tests/MiniToolbar.component.test.ts @@ -0,0 +1,115 @@ +import { expect, test, vi } from "vitest"; +import { render } from "vitest-browser-svelte"; +import "$styles/mini.css"; +import type { TabView } from "$shared/ipc/bindings"; +import MiniToolbar from "../components/MiniToolbar.svelte"; + +const tab: TabView = { + id: "0190a5f2-0000-7000-8000-000000000001", + projection_revision: "0000000000000000000000000000002a", + title: "Example", + url: "https://example.com/path", + loading: false, + can_go_back: true, + can_go_forward: false, + icon: null, +}; + +const props = () => ({ + tab: null as TabView | null, + spaces: 1, + pinned: false, + frame: "lights" as "lights" | "controls", + onAction: vi.fn(), + onSpaceMenu: vi.fn(), +}); + +/** The same reads native's presentation check makes before the page shows. */ +function nativeCheck(root: ParentNode, expected: TabView): boolean { + const shell = root.querySelector("[data-zephium-mini-tab]"); + if (!shell || shell.dataset.zephiumMiniTab !== expected.id) return false; + if ( + shell.dataset.zephiumTabUrl !== (expected.url ?? "") || + shell.dataset.zephiumProjectionRevision !== expected.projection_revision + ) + return false; + const label = shell.querySelector("[data-zephium-tab-label]"); + if (!label || label.textContent !== expected.title) return false; + const address = shell.querySelector("[data-zephium-address]"); + return address?.textContent === new URL(expected.url!).host; +} + +test("the toolbar shows the page so native's presentation check passes", async () => { + const screen = await render(MiniToolbar, { ...props(), tab }); + expect(nativeCheck(screen.container, tab)).toBe(true); + // An untrusted title is text, never markup. + expect(screen.container.querySelector("b")).toBeNull(); +}); + +test("the buttons ask for their page actions", async () => { + const onAction = vi.fn(); + const screen = await render(MiniToolbar, { ...props(), tab, onAction }); + await expect.element(screen.getByRole("button", { name: "Forward" })).toBeDisabled(); + await screen.getByRole("button", { name: "Back" }).click(); + await screen.getByRole("button", { name: "Reload" }).click(); + await screen.getByRole("button", { name: "Open in Zephium" }).click(); + expect(onAction.mock.calls).toEqual([["back"], ["reload"], ["open_in_main"]]); +}); + +test("clicking the page's name asks to edit its address", async () => { + const onAction = vi.fn(); + const screen = await render(MiniToolbar, { ...props(), tab, onAction }); + await screen.getByText("example.com").click(); + expect(onAction).toHaveBeenCalledWith("edit_address"); +}); + +test("a page that can go to another space offers the choice", async () => { + const onSpaceMenu = vi.fn(); + const one = await render(MiniToolbar, { ...props(), tab }); + expect(one.container.querySelector('[aria-haspopup="menu"]')).toBeNull(); + one.unmount(); + const screen = await render(MiniToolbar, { ...props(), tab, spaces: 2, onSpaceMenu }); + await screen.getByRole("button", { name: "Choose a space" }).click(); + expect(onSpaceMenu).toHaveBeenCalledOnce(); +}); + +test("keep on top shows whether it is on and asks to toggle", async () => { + const onAction = vi.fn(); + const off = await render(MiniToolbar, { ...props(), tab, onAction }); + const pin = off.getByRole("button", { name: "Keep on top" }); + await expect.element(pin).toHaveAttribute("aria-pressed", "false"); + await pin.click(); + expect(onAction).toHaveBeenCalledWith("keep_on_top"); + off.unmount(); + const on = await render(MiniToolbar, { ...props(), tab, pinned: true }); + await expect + .element(on.getByRole("button", { name: "Keep on top" })) + .toHaveAttribute("aria-pressed", "true"); +}); + +test("only a frameless window draws its own minimize and close", async () => { + const lights = await render(MiniToolbar, { ...props(), tab }); + expect(lights.container.querySelector(".window-button")).toBeNull(); + lights.unmount(); + const onAction = vi.fn(); + const screen = await render(MiniToolbar, { ...props(), tab, frame: "controls", onAction }); + await screen.getByRole("button", { name: "Minimize" }).click(); + await screen.getByRole("button", { name: "Close" }).click(); + expect(onAction.mock.calls).toEqual([["minimize"], ["close"]]); +}); + +test("a loading page shows a progress line, and nothing once it loaded", async () => { + const loading = await render(MiniToolbar, { ...props(), tab: { ...tab, loading: true } }); + await expect.element(loading.getByRole("progressbar")).toBeInTheDocument(); + loading.unmount(); + const loaded = await render(MiniToolbar, { ...props(), tab }); + expect(loaded.container.querySelector('[role="progressbar"]')).toBeNull(); +}); + +test("without a page, only reload's neighbours and the window stay usable", async () => { + const screen = await render(MiniToolbar, { ...props(), frame: "controls" }); + await expect.element(screen.getByRole("button", { name: "Open in Zephium" })).toBeDisabled(); + await expect.element(screen.getByRole("button", { name: "Reload" })).toBeDisabled(); + await expect.element(screen.getByRole("button", { name: "Close" })).toBeEnabled(); + expect(screen.container.querySelector("[data-zephium-mini-tab]")).toBeNull(); +}); diff --git a/frame/src/features/mini/tests/mini-model.test.ts b/frame/src/features/mini/tests/mini-model.test.ts new file mode 100644 index 000000000..1d1de91a8 --- /dev/null +++ b/frame/src/features/mini/tests/mini-model.test.ts @@ -0,0 +1,88 @@ +import { describe, expect, it } from "vitest"; +import { + acceptMiniTab, + acceptMiniView, + hostOf, + miniShortcut, + windowOfLabel, +} from "../lib/mini-model"; +import type { MiniView, TabView } from "$shared/ipc/bindings"; + +const page = (id: string, revision: number): TabView => ({ + id, + projection_revision: revision.toString(16).padStart(32, "0"), + title: "Example", + url: "https://example.com/a", + loading: false, + can_go_back: false, + can_go_forward: false, + icon: null, +}); + +const view = (window: number, tab: TabView | null): MiniView => ({ + window, + tab, + spaces: [], + space: null, + pinned: false, +}); + +describe("mini window toolbar", () => { + it("names its window from canonical labels only", () => { + expect(windowOfLabel("mini-2")).toBe(2); + for (const label of ["mini-", "mini-0", "mini-02", "mini-2a", "main", "panel"]) + expect(windowOfLabel(label)).toBeNull(); + expect(windowOfLabel("mini-99999999999999999999")).toBeNull(); + }); + + it("takes views for its own window and never an older revision of its page", () => { + expect(acceptMiniView(2, null, view(3, page("a", 1)))).toBe(false); + expect(acceptMiniView(2, null, view(2, page("a", 1)))).toBe(true); + expect(acceptMiniView(2, page("a", 1), view(2, null))).toBe(true); + expect(acceptMiniTab(page("a", 2), page("a", 1))).toBe(false); + expect(acceptMiniTab(page("a", 2), page("a", 2))).toBe(true); + expect(acceptMiniTab(page("a", 2), page("b", 1))).toBe(true); + expect(acceptMiniTab(null, { ...page("a", 1), projection_revision: "bad" })).toBe(false); + }); + + it("shows the host native checks, and nothing for a URL it cannot parse", () => { + expect(hostOf("https://example.com:8443/path")).toBe("example.com:8443"); + expect(hostOf("not a url")).toBe(""); + expect(hostOf(null)).toBe(""); + }); +}); + +describe("miniShortcut", () => { + const key = ( + k: string, + mods: Partial>, + ) => ({ + key: k, + metaKey: false, + ctrlKey: false, + altKey: false, + shiftKey: false, + ...mods, + }); + + it("answers the platform's command modifier only", () => { + expect(miniShortcut(key("o", { metaKey: true }), true)).toBe("open_in_main"); + expect(miniShortcut(key("O", { ctrlKey: true }), false)).toBe("open_in_main"); + expect(miniShortcut(key("l", { metaKey: true }), true)).toBe("edit_address"); + expect(miniShortcut(key("w", { ctrlKey: true }), false)).toBe("close"); + expect(miniShortcut(key("r", { metaKey: true }), true)).toBe("reload"); + expect(miniShortcut(key("[", { metaKey: true }), true)).toBe("back"); + expect(miniShortcut(key("]", { ctrlKey: true }), false)).toBe("forward"); + }); + + it("ignores the other platform's modifier, extra modifiers and other keys", () => { + expect(miniShortcut(key("o", { ctrlKey: true }), true)).toBeNull(); + expect(miniShortcut(key("o", { metaKey: true }), false)).toBeNull(); + expect(miniShortcut(key("o", { metaKey: true, ctrlKey: true }), true)).toBeNull(); + expect(miniShortcut(key("o", { metaKey: true, shiftKey: true }), true)).toBeNull(); + expect(miniShortcut(key("o", { ctrlKey: true, altKey: true }), false)).toBeNull(); + expect(miniShortcut(key("o", {}), true)).toBeNull(); + expect(miniShortcut(key("t", { metaKey: true }), true)).toBeNull(); + expect(miniShortcut(key("", { ctrlKey: true }), false)).toBeNull(); + }); +}); diff --git a/frame/src/features/panel/tests/panel-model.test.ts b/frame/src/features/panel/tests/panel-model.test.ts index 0cab29663..1b7af1dc0 100644 --- a/frame/src/features/panel/tests/panel-model.test.ts +++ b/frame/src/features/panel/tests/panel-model.test.ts @@ -13,6 +13,7 @@ const snapshot = (revision: string): PanelState => ({ error: false, seed: null, seed_tab: null, + mini: false, corner_radius: 20, }); describe("panel presentation and search identity", () => { diff --git a/frame/src/features/search/components/LauncherPanel.svelte b/frame/src/features/search/components/LauncherPanel.svelte index f6961d02b..13f1d967a 100644 --- a/frame/src/features/search/components/LauncherPanel.svelte +++ b/frame/src/features/search/components/LauncherPanel.svelte @@ -55,6 +55,7 @@ onTool: (tool) => onTool(tool), onCapture: untrack(() => onCapture), captureKeys: keys.capture, + sitesOnly: () => !!context?.mini, }); // Geometry the native shapes are placed from. Kept as numbers rather than @@ -125,12 +126,13 @@ if (row) available.push({ id: "open", label: primary, keys: keys.open, run: () => surface.submit() }); if (surface.addressable) { - available.push({ - id: "background", - label: m.launcher_open_background(), - keys: keys.background, - run: () => surface.submit(true), - }); + if (!context?.mini) + available.push({ + id: "background", + label: m.launcher_open_background(), + keys: keys.background, + run: () => surface.submit(true), + }); available.push({ id: "copy", label: m.launcher_copy_link(), @@ -154,7 +156,9 @@ if (target.calculation) return m.launcher_copy_answer(); switch (target.result?.kind) { case "tab": - return m.launcher_switch_tab(); + return target.result.action.type === "OpenUrl" + ? m.launcher_open() + : m.launcher_switch_tab(); case "search": case "suggestion": case "search_history": @@ -312,7 +316,7 @@ // A focused button activates itself instead of running the field's row. if (event.key === "Enter" && event.target instanceof HTMLButtonElement) return; const numbered = mod && !event.shiftKey && !event.altKey ? Number(key) : NaN; - if (numbered >= 1 && numbered <= destinations.length) { + if (!context?.mini && numbered >= 1 && numbered <= destinations.length) { event.preventDefault(); onTool(destinations[numbered - 1]!.kind); return; @@ -400,10 +404,12 @@ autocapitalize="off" autocorrect="off" spellcheck={false} - placeholder={m.panel_search_placeholder()} + placeholder={context?.mini ? m.panel_mini_placeholder() : m.panel_search_placeholder()} aria-label={surface.activeShortcut ? m.search_shortcut_label({ name: surface.activeShortcut.name }) - : m.panel_search_placeholder()} + : context?.mini + ? m.panel_mini_placeholder() + : m.panel_search_placeholder()} role="combobox" aria-haspopup={menu ? "menu" : "listbox"} aria-controls={menu ? ACTIONS_ID : "launcher-results"} @@ -452,7 +458,8 @@ >{:else if surface.notice === "copied"}{m.launcher_copied()}{:else if surface.notice === "answer"}{m.launcher_answer_copied()}{:else if surface.running}{m.panel_opening()}{:else if home} + >{:else if surface.running}{m.panel_opening()}{:else if home && !context?.mini}
{#each destinations as destination (destination.kind)}