Fix image errors

Conrad Irwin created

* Firstly only log one error per image load, not per frame
* Secondly use an Icon not an image for rendering Icons

Change summary

crates/gpui2/src/elements/img.rs           |  4 ++--
crates/gpui2/src/image_cache.rs            | 10 +++++++++-
crates/terminal_view2/src/terminal_view.rs | 13 ++++++-------
3 files changed, 17 insertions(+), 10 deletions(-)

Detailed changes

crates/gpui2/src/elements/img.rs 🔗

@@ -81,7 +81,7 @@ impl<V> Element<V> for Img<V> {
                     if let Some(data) = image_future
                         .clone()
                         .now_or_never()
-                        .and_then(ResultExt::log_err)
+                        .and_then(|result| result.ok())
                     {
                         let corner_radii = corner_radii.to_pixels(bounds.size, cx.rem_size());
                         cx.with_z_index(1, |cx| {
@@ -90,7 +90,7 @@ impl<V> Element<V> for Img<V> {
                         });
                     } else {
                         cx.spawn(|_, mut cx| async move {
-                            if image_future.await.log_err().is_some() {
+                            if image_future.await.ok().is_some() {
                                 cx.on_next_frame(|cx| cx.notify());
                             }
                         })

crates/gpui2/src/image_cache.rs 🔗

@@ -2,7 +2,7 @@ use crate::{ImageData, ImageId, SharedString};
 use collections::HashMap;
 use futures::{
     future::{BoxFuture, Shared},
-    AsyncReadExt, FutureExt,
+    AsyncReadExt, FutureExt, TryFutureExt,
 };
 use image::ImageError;
 use parking_lot::Mutex;
@@ -88,6 +88,14 @@ impl ImageCache {
                         Ok(Arc::new(ImageData::new(image)))
                     }
                 }
+                .map_err({
+                    let uri = uri.clone();
+
+                    move |error| {
+                        log::log!(log::Level::Error, "{:?} {:?}", &uri, &error);
+                        error
+                    }
+                })
                 .boxed()
                 .shared();
 

crates/terminal_view2/src/terminal_view.rs 🔗

@@ -9,11 +9,10 @@ pub mod terminal_panel;
 // use crate::terminal_element::TerminalElement;
 use editor::{scroll::autoscroll::Autoscroll, Editor};
 use gpui::{
-    actions, div, img, red, Action, AnyElement, AppContext, Component, DispatchPhase, Div,
-    EventEmitter, FocusEvent, FocusHandle, Focusable, FocusableComponent, FocusableView,
-    InputHandler, InteractiveComponent, KeyDownEvent, Keystroke, Model, MouseButton,
-    ParentComponent, Pixels, Render, SharedString, Styled, Task, View, ViewContext, VisualContext,
-    WeakView,
+    actions, div, Action, AnyElement, AppContext, Component, DispatchPhase, Div, EventEmitter,
+    FocusEvent, FocusHandle, Focusable, FocusableComponent, FocusableView, InputHandler,
+    InteractiveComponent, KeyDownEvent, Keystroke, Model, MouseButton, ParentComponent, Pixels,
+    Render, SharedString, Styled, Task, View, ViewContext, VisualContext, WeakView,
 };
 use language::Bias;
 use persistence::TERMINAL_DB;
@@ -32,7 +31,7 @@ use workspace::{
     notifications::NotifyResultExt,
     register_deserializable_item,
     searchable::{SearchEvent, SearchOptions, SearchableItem},
-    ui::{ContextMenu, Label, ListEntry},
+    ui::{ContextMenu, Icon, IconElement, Label, ListEntry},
     CloseActiveItem, NewCenterTerminal, Pane, ToolbarItemLocation, Workspace, WorkspaceId,
 };
 
@@ -755,7 +754,7 @@ impl Item for TerminalView {
         let title = self.terminal().read(cx).title();
 
         div()
-            .child(img().uri("icons/terminal.svg").bg(red()))
+            .child(IconElement::new(Icon::Terminal))
             .child(title)
             .render()
     }