Skip to content

Commit

Permalink
Set Rerun viewer native app icon using eframe (#1976)
Browse files Browse the repository at this point in the history
* Set Rerun viewer native app icon using eframe

This was recently added to eframe

* Fix linux build
  • Loading branch information
emilk authored Apr 26, 2023
1 parent d6be388 commit 57964f6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 217 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ahash = "0.8"
anyhow = "1.0"
arrow2 = "0.16"
arrow2_convert = "0.4.2"
cfg-if = "1.0"
clap = "4.0"
comfy-table = { version = "6.1", default-features = false }
ctrlc = { version = "3.0", features = ["termination"] }
Expand Down
11 changes: 0 additions & 11 deletions crates/re_ui/src/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ impl Icon {
}
}

#[cfg(target_os = "macos")]
pub const APP_ICON: Icon = Icon::new(
"app_icon_mac",
include_bytes!("../data/icons/app_icon_mac.png"),
);
#[cfg(target_os = "windows")]
pub const APP_ICON: Icon = Icon::new(
"app_icon_windows",
include_bytes!("../data/icons/app_icon_windows.png"),
);

pub const RERUN_MENU: Icon =
Icon::new("rerun_menu", include_bytes!("../data/icons/rerun_menu.png"));

Expand Down
1 change: 1 addition & 0 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ re_analytics = { workspace = true, optional = true }
ahash.workspace = true
anyhow.workspace = true
bytemuck = { version = "1.11", features = ["extern_crate_alloc"] }
cfg-if.workspace = true
eframe = { workspace = true, default-features = false, features = [
"default_fonts",
"persistence",
Expand Down
11 changes: 0 additions & 11 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use re_smart_channel::Receiver;
use re_ui::{toasts, Command};

use crate::{
app_icon::setup_app_icon,
misc::{AppOptions, Caches, RecordingConfig, ViewerContext},
ui::{data_ui::ComponentUiRegistry, Blueprint},
viewer_analytics::ViewerAnalytics,
Expand All @@ -25,8 +24,6 @@ use crate::{
#[cfg(not(target_arch = "wasm32"))]
use re_log_types::TimeRangeF;

use super::app_icon::AppIconStatus;

const WATERMARK: bool = false; // Nice for recording media material

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -97,8 +94,6 @@ pub struct App {
cmd_palette: re_ui::CommandPalette,

analytics: ViewerAnalytics,

icon_status: AppIconStatus,
}

impl App {
Expand Down Expand Up @@ -155,8 +150,6 @@ impl App {
cmd_palette: Default::default(),

analytics,

icon_status: AppIconStatus::NotSetTryAgain,
}
}

Expand Down Expand Up @@ -439,10 +432,6 @@ impl eframe::App for App {
self.ram_limit_warner.update();
}

if self.icon_status == AppIconStatus::NotSetTryAgain {
self.icon_status = setup_app_icon();
}

if self.shutdown.load(std::sync::atomic::Ordering::Relaxed) {
#[cfg(not(target_arch = "wasm32"))]
frame.close();
Expand Down
190 changes: 0 additions & 190 deletions crates/re_viewer/src/app_icon.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ mod native;
#[cfg(not(target_arch = "wasm32"))]
pub use native::{run_native_app, run_native_viewer_with_messages};

mod app_icon;

#[cfg(not(target_arch = "wasm32"))]
pub use misc::profiler::Profiler;

Expand Down
31 changes: 31 additions & 0 deletions crates/re_viewer/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub fn run_native_app(app_creator: AppCreator) -> eframe::Result<()> {
initial_window_size: Some([1600.0, 1200.0].into()),
min_window_size: Some([320.0, 450.0].into()), // Should be high enough to fit the rerun menu

icon_data: icon_data(),

#[cfg(target_os = "macos")]
fullsize_content: re_ui::FULLSIZE_CONTENT,

Expand Down Expand Up @@ -40,6 +42,35 @@ pub fn run_native_app(app_creator: AppCreator) -> eframe::Result<()> {
)
}

#[allow(clippy::unnecessary_wraps)]
fn icon_data() -> Option<eframe::IconData> {
cfg_if::cfg_if! {
if #[cfg(macos)] {
let app_icon_png_bytes = include_bytes!("../../re_ui/data/icons/app_icon_mac.png");
} else if #[cfg(windows)] {
let app_icon_png_bytes = include_bytes!("../../re_ui/data/icons/app_icon_windows.png");
} else {
// Use the same icon for X11 as for Windows, at least for now.
let app_icon_png_bytes = include_bytes!("../../re_ui/data/icons/app_icon_windows.png");
}
};

// We include the .png with `include_bytes`. If that fails, things are extremely broken.
match eframe::IconData::try_from_png_bytes(app_icon_png_bytes) {
Ok(icon_data) => Some(icon_data),
Err(err) => {
#[cfg(debug_assertions)]
panic!("Failed to load app icon: {err}");

#[cfg(not(debug_assertions))]
{
re_log::warn!("Failed to load app icon: {err}");
None
}
}
}
}

pub fn run_native_viewer_with_messages(
build_info: re_build_info::BuildInfo,
app_env: crate::AppEnvironment,
Expand Down

0 comments on commit 57964f6

Please sign in to comment.