Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ serde_yaml = "0.9.34+deprecated"
image = { version = "0.25.2", default-features = false, features = ["png"] }
bitflags = "2.6.0"
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
rust-embed = "6.4.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Action Required: Update rust-embed to the Latest Version

The current dependency version rust-embed = "6.4.0" is outdated. The latest version available is 8.5.0, which includes important bug fixes and enhancements. Please consider updating to the latest version to ensure optimal performance and security.

  • Review the rust-embed changelog for any breaking changes.
  • Test the application to verify compatibility with the new version.
🔗 Analysis chain

Approved: Addition of rust-embed dependency.

The addition of the rust-embed dependency aligns well with the PR objectives of fixing broken images in the binary. This should allow for embedding icon assets directly into the application, potentially resolving the issue with loading icons and images for the sidebar.

Consider the following suggestions:

  1. Verify if version 6.4.0 is the latest stable version of rust-embed. If not, consider updating to the latest stable version, unless there's a specific reason to use this version.
  2. For better organization, you might want to group this dependency with other similar ones in the Cargo.toml file, rather than adding it at the end.

Let's check if there's a newer version of rust-embed available:

This will help ensure we're using the most up-to-date version of the library.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the latest version of rust-embed

# Test: Query crates.io API for the latest version of rust-embed
curl -s https://crates.io/api/v1/crates/rust-embed | jq -r '.crate.max_version'

Length of output: 85

35 changes: 24 additions & 11 deletions src/ui/components/left_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,37 @@ use crate::ui::RootScreenType;
use eframe::epaint::{Color32, Margin};
use egui::{Context, Frame, ImageButton, SidePanel, TextureHandle};
use std::sync::Arc;
use rust_embed::RustEmbed;

// Function to load an icon as a texture
#[derive(RustEmbed)]
#[folder = "icons/"] // Adjust the folder path if necessary
struct Assets;

// Function to load an icon as a texture using embedded assets
fn load_icon(ctx: &Context, path: &str) -> Option<TextureHandle> {
if let Ok(image) = image::open(path) {
let size = [image.width() as usize, image.height() as usize];
let rgba_image = image.into_rgba8();
let pixels = rgba_image.into_raw();
// Attempt to retrieve the embedded file
if let Some(content) = Assets::get(path) {
// Load the image from the embedded bytes
if let Ok(image) = image::load_from_memory(&content.data) {
let size = [image.width() as usize, image.height() as usize];
let rgba_image = image.into_rgba8();
let pixels = rgba_image.into_raw();

Some(ctx.load_texture(
path,
egui::ColorImage::from_rgba_unmultiplied(size, &pixels),
Default::default(),
))
Some(ctx.load_texture(
path,
egui::ColorImage::from_rgba_unmultiplied(size, &pixels),
Default::default(),
))
} else {
eprintln!("Failed to load image from embedded data at path: {}", path);
None
Comment on lines +29 to +30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using a logging crate instead of eprintln!

Using eprintln! for error messages in a GUI application may not be ideal. Consider using a logging crate like log or env_logger for more flexible and configurable logging, which can be directed to files, consoles, or other outputs as needed.

}
Comment on lines +16 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify nested if let statements for better readability

The nested if let statements in the load_icon function can be simplified to improve readability using combinators like and_then and map.

Here's an example of how you might refactor it:

fn load_icon(ctx: &Context, path: &str) -> Option<TextureHandle> {
    Assets::get(path).and_then(|content| {
        image::load_from_memory(&content.data).ok().map(|image| {
            let size = [image.width() as usize, image.height() as usize];
            let rgba_image = image.into_rgba8();
            let pixels = rgba_image.into_raw();
            ctx.load_texture(
                path,
                egui::ColorImage::from_rgba_unmultiplied(size, &pixels),
                Default::default(),
            )
        })
    })
}

} else {
eprintln!("Failed to load icon at path: {}", path);
eprintln!("Image not found in embedded assets at path: {}", path);
None
}
}

pub fn add_left_panel(
ctx: &Context,
app_context: &Arc<AppContext>,
Expand Down