Skip to content

Commit e9a18a5

Browse files
committed
Fix URL button layout and add URL history
1 parent 8e3c37a commit e9a18a5

5 files changed

Lines changed: 70 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ naga = { version = "29.0.3", features = ["wgsl-in"] }
5151
glam = "0.32.1"
5252
env_logger = "0.11.10"
5353
ureq = "3.3.0"
54+
directories = "6.0.0"
5455

5556
[build-dependencies]
5657
winres = "0.1.12"

src/engine.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,21 @@ impl<'a> VulkanEngine<'a> {
18331833
}
18341834
});
18351835
});
1836+
1837+
if !state.url_history.is_empty() {
1838+
ui.separator();
1839+
ui.label(egui::RichText::new("Recent Streams:").strong());
1840+
egui::ScrollArea::vertical().max_height(150.0).show(ui, |ui| {
1841+
for (url, title) in &state.url_history {
1842+
if ui.add_sized(
1843+
[ui.available_width(), 30.0],
1844+
egui::Button::new(format!("{} ({})", title, url))
1845+
).clicked() {
1846+
engine_action = EngineAction::LoadUrl(url.clone());
1847+
}
1848+
}
1849+
});
1850+
}
18361851
});
18371852
}
18381853

src/main.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ fn main() -> Result<(), Box<dyn Error>> {
104104
state.playlist = args.file.clone();
105105
state.playlist_index = 0;
106106

107+
let mut history_changed = false;
108+
for path in &args.file {
109+
if path.starts_with("http") {
110+
if !state.url_history.iter().any(|(u, _)| u == path) {
111+
state.url_history.push((path.clone(), "Network Stream".to_string()));
112+
history_changed = true;
113+
}
114+
}
115+
}
116+
if history_changed {
117+
let mut out = String::new();
118+
for (u, t) in &state.url_history {
119+
out.push_str(&format!("{}|{}\n", u, t));
120+
}
121+
let _ = std::fs::write(crate::state::get_history_file_path(), out);
122+
}
123+
107124
if let Some(vis) = &args.vis {
108125
let vis_lower = vis.to_lowercase();
109126
if let Some(idx) = crate::state::VISUALIZERS.iter().position(|v| v.filename.to_lowercase().contains(&vis_lower) || v.name.to_lowercase().contains(&vis_lower)) {
@@ -808,8 +825,16 @@ async fn run_gui(app_state: Arc<Mutex<AppState>>, mut active_stream: Option<audi
808825
state.url_input_text.clear();
809826
state.playlist = vec![url.clone()];
810827
state.playlist_index = 0;
811-
state.load_request = Some(url);
828+
state.load_request = Some(url.clone());
812829
state.file_loaded = true;
830+
if !state.url_history.iter().any(|(u, _)| u == &url) {
831+
state.url_history.push((url.clone(), "Network Stream".to_string()));
832+
let mut out = String::new();
833+
for (u, t) in &state.url_history {
834+
out.push_str(&format!("{}|{}\n", u, t));
835+
}
836+
let _ = std::fs::write(crate::state::get_history_file_path(), out);
837+
}
813838
}
814839
EngineAction::None => {}
815840
}

src/state.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pub struct AppState {
170170
pub open_file_request: bool,
171171
pub is_url_dialog_open: bool,
172172
pub url_input_text: String,
173+
pub url_history: Vec<(String, String)>,
173174
pub egui_gamepad_events: Vec<egui::Event>,
174175
pub force_stereo_downmix: bool,
175176
pub append_to_playlist: bool,
@@ -185,6 +186,18 @@ pub struct AppState {
185186
pub cumulative_scrub: f64,
186187
}
187188

189+
pub fn get_history_file_path() -> std::path::PathBuf {
190+
if let Some(proj_dirs) = directories::ProjectDirs::from("com", "RustTracker", "RustTracker") {
191+
let dir = proj_dirs.data_dir();
192+
if !dir.exists() {
193+
let _ = std::fs::create_dir_all(dir);
194+
}
195+
dir.join("url_history.txt")
196+
} else {
197+
std::path::PathBuf::from("url_history.txt")
198+
}
199+
}
200+
188201
impl AppState {
189202
pub fn new(title: String) -> Self {
190203
let mut history = VecDeque::new();
@@ -212,6 +225,17 @@ impl AppState {
212225
vis_enabled[9] = false; // Ferrofluid Particle Sim
213226
vis_enabled[10] = false; // Neon Corridor
214227
}
228+
229+
let mut url_history = Vec::new();
230+
if let Ok(data) = std::fs::read_to_string(get_history_file_path()) {
231+
for line in data.lines() {
232+
if let Some((url, title)) = line.split_once('|') {
233+
if !url_history.iter().any(|(u, _)| u == url) {
234+
url_history.push((url.to_string(), title.to_string()));
235+
}
236+
}
237+
}
238+
}
215239

216240
AppState {
217241
passthrough_enabled: true,
@@ -273,6 +297,7 @@ impl AppState {
273297
open_file_request: false,
274298
is_url_dialog_open: false,
275299
url_input_text: String::new(),
300+
url_history,
276301
egui_gamepad_events: Vec::new(),
277302
force_stereo_downmix: is_steam_deck,
278303
append_to_playlist: false,
@@ -358,6 +383,7 @@ impl AppState {
358383
open_file_request: false,
359384
is_url_dialog_open: self.is_url_dialog_open,
360385
url_input_text: self.url_input_text.clone(),
386+
url_history: self.url_history.clone(),
361387
egui_gamepad_events: Vec::new(),
362388
force_stereo_downmix: self.force_stereo_downmix,
363389
append_to_playlist: self.append_to_playlist,

0 commit comments

Comments
 (0)