diff --git a/crates/shell/src/engine/quickjs/window_api.rs b/crates/shell/src/engine/quickjs/window_api.rs index 7321f37adb..ba00d8d812 100644 --- a/crates/shell/src/engine/quickjs/window_api.rs +++ b/crates/shell/src/engine/quickjs/window_api.rs @@ -113,7 +113,7 @@ pub(super) fn install(ctx: &Ctx<'_>) -> JsResult<()> { "__window_activate", Func::from(|ctx: Ctx<'_>| -> JsResult<()> { write(&ctx, "window.activate_window()", |window, _| { - window.activate_window() + window.activate() }) }), )?; diff --git a/crates/shell/src/root.rs b/crates/shell/src/root.rs index 3340926254..0e931243dd 100644 --- a/crates/shell/src/root.rs +++ b/crates/shell/src/root.rs @@ -1372,7 +1372,7 @@ mod tests { let (root, cx) = shell_root(cx); // Timeouts only run while the window is active, so the test has to say // that it is. - cx.update(|window, _| window.activate_window()); + cx.update(|window, _| window.activate()); cx.run_until_parked(); root.update_in(cx, |root, window, cx| { diff --git a/crates/story/examples/dock.rs b/crates/story/examples/dock.rs index 0395772104..fefc96fe84 100644 --- a/crates/story/examples/dock.rs +++ b/crates/story/examples/dock.rs @@ -445,7 +445,7 @@ impl StoryWorkspace { window .update(cx, |_, window, cx| { - window.activate_window(); + window.activate(); window.set_window_title("GPUI App"); cx.on_release(|_, cx| { // exit app diff --git a/crates/story/examples/tiles.rs b/crates/story/examples/tiles.rs index f8c68681c1..5f8855033a 100644 --- a/crates/story/examples/tiles.rs +++ b/crates/story/examples/tiles.rs @@ -351,7 +351,7 @@ impl StoryTiles { window .update(cx, |_, window, _| { - window.activate_window(); + window.activate(); window.set_window_title("Story Tiles"); }) .expect("failed to update window"); diff --git a/crates/story/src/lib.rs b/crates/story/src/lib.rs index 08056addf0..ed072f530d 100644 --- a/crates/story/src/lib.rs +++ b/crates/story/src/lib.rs @@ -175,7 +175,7 @@ pub fn create_new_window_with_size( .expect("failed to open window"); window.update(cx, |_, window, _| { - window.activate_window(); + window.activate(); window.set_window_title(&title); })?; diff --git a/crates/ui/src/native_menu/macos.rs b/crates/ui/src/native_menu/macos.rs index 8723aea354..71bd994aa5 100644 --- a/crates/ui/src/native_menu/macos.rs +++ b/crates/ui/src/native_menu/macos.rs @@ -2,7 +2,7 @@ use std::{cell::Cell, sync::Arc}; -use gpui::{Action, App, AssetSource, Pixels, Point, SharedString, Window}; +use gpui::{Action, App, AssetRegistry, Pixels, Point, SharedString, Window}; use objc2::rc::Retained; use objc2::runtime::{AnyObject, NSObject}; use objc2::{AnyThread, DefinedClass, MainThreadMarker, define_class, msg_send, sel}; @@ -52,7 +52,7 @@ impl MenuTarget { /// borrowed while the menu is open. pub(super) fn show( items: Vec, - asset_source: Arc, + asset_source: Arc, position: Point, window: &mut Window, cx: &mut App, @@ -88,7 +88,7 @@ pub(super) fn show( fn run_menu( view_ptr: usize, items: &[NativeMenuItem], - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, position: Point, ) -> Option> { let mtm = MainThreadMarker::new()?; @@ -121,7 +121,7 @@ fn run_menu( /// to its index in `actions`, so the selected tag maps back to its action. fn build_menu<'a>( items: &'a [NativeMenuItem], - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, target: &MenuTarget, mtm: MainThreadMarker, actions: &mut Vec<&'a Box>, @@ -187,7 +187,7 @@ fn build_menu<'a>( fn ns_image_for_icon( path: &SharedString, - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, ) -> Option> { let image = resolve_icon_image(path, asset_source)?; if image.bytes.is_empty() { diff --git a/crates/ui/src/native_menu/mod.rs b/crates/ui/src/native_menu/mod.rs index 71910b7534..4a18a000a5 100644 --- a/crates/ui/src/native_menu/mod.rs +++ b/crates/ui/src/native_menu/mod.rs @@ -27,7 +27,7 @@ use crate::ActiveTheme as _; use crate::Icon; #[cfg(any(target_os = "macos", target_os = "windows"))] -use gpui::AssetSource; +use gpui::AssetRegistry; use gpui::{Action, App, Pixels, Point, SharedString, Window}; #[cfg(any(target_os = "macos", target_os = "windows"))] use gpui::{Image, ImageFormat}; @@ -202,13 +202,13 @@ impl NativeMenu { #[cfg(target_os = "macos")] { - macos::show(self.items, cx.asset_source().clone(), position, window, cx); + macos::show(self.items, cx.assets().clone(), position, window, cx); } #[cfg(target_os = "windows")] { windows::show( self.items, - cx.asset_source().clone(), + cx.assets().clone(), position, cx.theme().is_dark(), window, @@ -223,7 +223,7 @@ impl NativeMenu { #[cfg(any(target_os = "macos", target_os = "windows"))] pub(super) fn resolve_icon_image( path: &SharedString, - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, ) -> Option> { if path.is_empty() { return None; @@ -234,11 +234,7 @@ pub(super) fn resolve_icon_image( let bytes = if icon_path.is_absolute() { std::fs::read(icon_path).ok()? } else { - asset_source - .load(path.as_ref()) - .ok() - .flatten()? - .into_owned() + asset_source.load(path.as_ref())?.into_owned() }; let format = image_format(path.as_ref(), &bytes)?; Some(Arc::new(Image::from_bytes(format, bytes))) @@ -411,16 +407,9 @@ mod tests { const ASSET_SVG: &[u8] = br#""#; const FILE_SVG: &[u8] = br#""#; - struct TestAssetSource(Option<&'static [u8]>); - - impl AssetSource for TestAssetSource { - fn load(&self, _path: &str) -> gpui::Result>> { - Ok(self.0.map(Cow::Borrowed)) - } - - fn list(&self, _path: &str) -> gpui::Result> { - Ok(Vec::new()) - } + /// Assets holding only `path`, with the given contents. + fn assets_with(path: &SharedString, bytes: &'static [u8]) -> AssetRegistry { + [(path.clone(), Cow::Borrowed(bytes))].into_iter().collect() } /// A file written into the current directory for the duration of one test. @@ -452,8 +441,11 @@ mod tests { #[test] fn test_native_menu_icon_asset_resolves_to_bytes() { let icon = Icon::new(IconName::Github); - let image = resolve_icon_image(icon.path_ref(), &gpui_component_assets::Assets) - .expect("icon asset should resolve"); + let image = resolve_icon_image( + icon.path_ref(), + &AssetRegistry::from(gpui_component_assets::Assets), + ) + .expect("icon asset should resolve"); assert_eq!(image.format, ImageFormat::Svg); assert!(!image.bytes.is_empty()); @@ -464,11 +456,11 @@ mod tests { let path: SharedString = "native-menu-relative-shadow-test.svg".into(); let _file = TestIconFile::create(path.as_ref(), FILE_SVG); - let image = resolve_icon_image(&path, &TestAssetSource(Some(ASSET_SVG))) + let image = resolve_icon_image(&path, &assets_with(&path, ASSET_SVG)) .expect("relative icon should resolve from the asset source"); assert_eq!(image.bytes, ASSET_SVG); - assert!(resolve_icon_image(&path, &TestAssetSource(None)).is_none()); + assert!(resolve_icon_image(&path, &AssetRegistry::default()).is_none()); } #[test] @@ -479,7 +471,7 @@ mod tests { let _file = TestIconFile::create(&path, FILE_SVG); let path: SharedString = path.to_string_lossy().into_owned().into(); - let image = resolve_icon_image(&path, &TestAssetSource(Some(ASSET_SVG))) + let image = resolve_icon_image(&path, &assets_with(&path, ASSET_SVG)) .expect("absolute icon should resolve from the filesystem"); assert_eq!(image.bytes, FILE_SVG); } diff --git a/crates/ui/src/native_menu/windows.rs b/crates/ui/src/native_menu/windows.rs index d9d20d99c9..426bd3a9a3 100644 --- a/crates/ui/src/native_menu/windows.rs +++ b/crates/ui/src/native_menu/windows.rs @@ -5,7 +5,7 @@ use std::{ sync::{Arc, OnceLock}, }; -use gpui::{Action, App, AssetSource, ImageFormat, Pixels, Point, SharedString, Window}; +use gpui::{Action, App, AssetRegistry, ImageFormat, Pixels, Point, SharedString, Window}; use raw_window_handle::{HasWindowHandle, RawWindowHandle}; use windows::Win32::Foundation::{BOOL, GlobalFree, HANDLE, HWND, POINT}; use windows::Win32::Graphics::Gdi::{ @@ -39,7 +39,7 @@ const MENU_IMAGE_SIZE: u32 = 16; /// run from a foreground task to avoid re-entering GPUI while it is borrowed. pub(super) fn show( items: Vec, - asset_source: Arc, + asset_source: Arc, position: Point, dark_mode: bool, window: &mut Window, @@ -85,7 +85,7 @@ pub(super) fn show( fn run_menu( hwnd: isize, items: &[NativeMenuItem], - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, client_x: i32, client_y: i32, image_px: u32, @@ -187,7 +187,7 @@ unsafe fn apply_menu_theme(hwnd: HWND, dark_mode: bool) { /// Win32 menu creation; the returned `HMENU` must be destroyed by the caller. unsafe fn build_menu<'a>( items: &'a [NativeMenuItem], - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, actions: &mut Vec<&'a Box>, bitmaps: &mut Vec, image_px: u32, @@ -317,7 +317,7 @@ impl Drop for GdiplusSession { /// Calls GDI+ /GDI flat APIs; the returned handle is owned by the caller. unsafe fn load_hbitmap( path: &SharedString, - asset_source: &dyn AssetSource, + asset_source: &AssetRegistry, image_px: u32, ) -> Option { let image = resolve_icon_image(path, asset_source)?; diff --git a/crates/ui/src/notification.rs b/crates/ui/src/notification.rs index 27fcadd82b..85b3f7a3e6 100644 --- a/crates/ui/src/notification.rs +++ b/crates/ui/src/notification.rs @@ -669,7 +669,7 @@ impl SystemNotificationRegistry { // Errs when the window is already closed: the entry is removed and the // application is still brought to the foreground. let _ = entry.window.update(cx, |_, window, cx| { - window.activate_window(); + window.activate(); if let Some(list) = entry.list.upgrade() { // No-op when the toast already closed or was never created // (system-only delivery). @@ -1121,7 +1121,7 @@ mod tests { list: cx.new(|cx| NotificationList::new(window, cx)), other_focus: cx.focus_handle(), }); - cx.update(|window, _| window.activate_window()); + cx.update(|window, _| window.activate()); let list = root.read_with(cx, |root, _| root.list.clone()); // The left stack is pushed first, so it owns the lower group index. @@ -1167,7 +1167,7 @@ mod tests { list: cx.new(|cx| NotificationList::new(window, cx)), other_focus: cx.focus_handle(), }); - cx.update(|window, _| window.activate_window()); + cx.update(|window, _| window.activate()); let list = root.read_with(cx, |root, _| root.list.clone()); list.update_in(cx, |list, window, cx| { @@ -1215,7 +1215,7 @@ mod tests { list: cx.new(|cx| NotificationList::new(window, cx)), other_focus: cx.focus_handle(), }); - cx.update(|window, _| window.activate_window()); + cx.update(|window, _| window.activate()); let list = root.read_with(cx, |root, _| root.list.clone()); list.update_in(cx, |list, window, cx| { @@ -1277,7 +1277,7 @@ mod tests { let list_focus = list.read_with(cx, |list, _| list.focus_handle.clone()); cx.update(|window, cx| { - window.activate_window(); + window.activate(); list_focus.focus(window, cx); window.draw(cx).clear(cx); }); @@ -1578,7 +1578,7 @@ mod tests { list: cx.new(|cx| NotificationList::new(window, cx)), other_focus: cx.focus_handle(), }); - cx.update(|window, _| window.activate_window()); + cx.update(|window, _| window.activate()); let list = root.read_with(cx, |r, _| r.list.clone()); // Autohide expiry leaves the system notification in the center. diff --git a/crates/ui/src/text/format/html.rs b/crates/ui/src/text/format/html.rs index 2e4e29db32..72573bc6c5 100644 --- a/crates/ui/src/text/format/html.rs +++ b/crates/ui/src/text/format/html.rs @@ -754,8 +754,8 @@ mod tests { #[test] fn test_value_to_length() { assert_eq!(super::value_to_length("100px"), Some(px(100.).into())); - assert_eq!(super::value_to_length("100%"), Some(relative(1.))); - assert_eq!(super::value_to_length("56%"), Some(relative(0.56))); + assert_eq!(super::value_to_length("100%"), Some(relative(1.).into())); + assert_eq!(super::value_to_length("56%"), Some(relative(0.56).into())); assert_eq!(super::value_to_length("240"), Some(px(240.).into())); } @@ -794,7 +794,7 @@ mod tests { children: vec![InlineNode::image(ImageNode { url: "https://example.com/image.png".to_string().into(), alt: Some("Example".to_string().into()), - width: Some(relative(0.8)), + width: Some(relative(0.8).into()), height: None, title: Some("Example Image".to_string().into()), ..Default::default() diff --git a/examples/fps_monitor/src/main.rs b/examples/fps_monitor/src/main.rs index e5d6d2ba93..6ba5f21f3a 100644 --- a/examples/fps_monitor/src/main.rs +++ b/examples/fps_monitor/src/main.rs @@ -416,7 +416,7 @@ fn main() { cx.spawn(async move |cx| { cx.open_window(WindowOptions::default(), |window, cx| { - window.activate_window(); + window.activate(); window.set_window_title("FPS Monitor"); cx.new(|cx| Example::new(window, cx)) }) diff --git a/examples/system_monitor/src/main.rs b/examples/system_monitor/src/main.rs index 9768fa38c1..cfeac88719 100644 --- a/examples/system_monitor/src/main.rs +++ b/examples/system_monitor/src/main.rs @@ -570,7 +570,7 @@ fn main() { cx.spawn(async move |cx| { cx.open_window(window_options, |window, cx| { - window.activate_window(); + window.activate(); window.set_window_title("System Monitor"); Theme::change(ThemeMode::Dark, Some(window), cx);