Skip to content

Commit 0dfe262

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

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

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("url_history.txt", 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("url_history.txt", out);
837+
}
813838
}
814839
EngineAction::None => {}
815840
}

src/state.rs

Lines changed: 14 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,
@@ -212,6 +213,17 @@ impl AppState {
212213
vis_enabled[9] = false; // Ferrofluid Particle Sim
213214
vis_enabled[10] = false; // Neon Corridor
214215
}
216+
217+
let mut url_history = Vec::new();
218+
if let Ok(data) = std::fs::read_to_string("url_history.txt") {
219+
for line in data.lines() {
220+
if let Some((url, title)) = line.split_once('|') {
221+
if !url_history.iter().any(|(u, _)| u == url) {
222+
url_history.push((url.to_string(), title.to_string()));
223+
}
224+
}
225+
}
226+
}
215227

216228
AppState {
217229
passthrough_enabled: true,
@@ -273,6 +285,7 @@ impl AppState {
273285
open_file_request: false,
274286
is_url_dialog_open: false,
275287
url_input_text: String::new(),
288+
url_history,
276289
egui_gamepad_events: Vec::new(),
277290
force_stereo_downmix: is_steam_deck,
278291
append_to_playlist: false,
@@ -358,6 +371,7 @@ impl AppState {
358371
open_file_request: false,
359372
is_url_dialog_open: self.is_url_dialog_open,
360373
url_input_text: self.url_input_text.clone(),
374+
url_history: self.url_history.clone(),
361375
egui_gamepad_events: Vec::new(),
362376
force_stereo_downmix: self.force_stereo_downmix,
363377
append_to_playlist: self.append_to_playlist,

0 commit comments

Comments
 (0)