re_viewer_context/
app_options.rs1use re_log_types::TimestampFormat;
2use re_video::{DecodeHardwareAcceleration, DecodeSettings};
3
4const MAPBOX_ACCESS_TOKEN_ENV_VAR: &str = "RERUN_MAPBOX_ACCESS_TOKEN";
5
6#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
8#[serde(default)]
9pub struct AppOptions {
10 pub warn_e2e_latency: f32,
12
13 pub show_metrics: bool,
15
16 #[serde(alias = "include_welcome_screen_button_in_recordings_panel")]
18 pub include_rerun_examples_button_in_recordings_panel: bool,
19
20 pub show_picking_debug_overlay: bool,
22
23 pub inspect_blueprint_timeline: bool,
25
26 pub blueprint_gc: bool,
28
29 #[serde(rename = "timestamp_format")]
31 pub timestamp_format: TimestampFormat,
32
33 pub video_decoder_hw_acceleration: DecodeHardwareAcceleration,
35
36 #[expect(clippy::doc_markdown)]
44 pub video_decoder_override_ffmpeg_path: bool,
45
46 #[expect(clippy::doc_markdown)]
50 pub video_decoder_ffmpeg_path: String,
51
52 pub mapbox_access_token: String,
56
57 #[cfg(not(target_arch = "wasm32"))]
65 pub cache_directory: Option<std::path::PathBuf>,
66}
67
68impl Default for AppOptions {
69 fn default() -> Self {
70 Self {
71 warn_e2e_latency: 1.0,
72
73 show_metrics: cfg!(debug_assertions),
74
75 include_rerun_examples_button_in_recordings_panel: true,
76
77 show_picking_debug_overlay: false,
78
79 inspect_blueprint_timeline: false,
80
81 blueprint_gc: true,
82
83 timestamp_format: TimestampFormat::default(),
84
85 video_decoder_hw_acceleration: DecodeHardwareAcceleration::default(),
86 video_decoder_override_ffmpeg_path: false,
87 video_decoder_ffmpeg_path: String::new(),
88
89 mapbox_access_token: String::new(),
90
91 #[cfg(not(target_arch = "wasm32"))]
92 cache_directory: Self::default_cache_directory(),
93 }
94 }
95}
96
97impl AppOptions {
98 pub fn mapbox_access_token(&self) -> Option<String> {
99 if self.mapbox_access_token.is_empty() {
100 std::env::var(MAPBOX_ACCESS_TOKEN_ENV_VAR).ok()
101 } else {
102 Some(self.mapbox_access_token.clone())
103 }
104 }
105
106 #[cfg(not(target_arch = "wasm32"))]
107 pub fn cache_subdirectory(
108 &self,
109 sub_dir: impl AsRef<std::path::Path>,
110 ) -> Option<std::path::PathBuf> {
111 self.cache_directory
112 .as_ref()
113 .map(|cache_dir| cache_dir.join(sub_dir))
114 }
115
116 pub fn default_cache_directory() -> Option<std::path::PathBuf> {
118 directories::ProjectDirs::from("io", "rerun", "Rerun")
119 .map(|dirs| dirs.cache_dir().to_owned())
120 }
121
122 pub fn video_decoder_settings(&self) -> DecodeSettings {
124 DecodeSettings {
125 hw_acceleration: self.video_decoder_hw_acceleration,
126
127 #[cfg(not(target_arch = "wasm32"))]
128 ffmpeg_path: self
129 .video_decoder_override_ffmpeg_path
130 .then(|| std::path::PathBuf::from(&self.video_decoder_ffmpeg_path)),
131 }
132 }
133}