Skip to content

Commit 1595a06

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

5 files changed

Lines changed: 82 additions & 8 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: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,27 +1812,48 @@ impl<'a> VulkanEngine<'a> {
18121812
egui::Window::new("Open Network Stream")
18131813
.collapsible(false)
18141814
.resizable(false)
1815+
.default_width(600.0)
18151816
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
18161817
.show(ctx, |ui| {
18171818
ui.label("Enter Stream URL (e.g. .pls, .m3u, or direct stream link):");
1819+
ui.add_space(4.0);
18181820
let mut url_text = state.url_input_text.clone();
1819-
let text_resp = ui.add_sized([400.0, 30.0], egui::TextEdit::singleline(&mut url_text));
1821+
let text_resp = ui.add(
1822+
egui::TextEdit::singleline(&mut url_text)
1823+
.desired_width(f32::INFINITY)
1824+
.min_size(egui::vec2(0.0, 30.0))
1825+
);
18201826
if text_resp.changed() {
18211827
engine_action = EngineAction::SetUrlInput(url_text.clone());
18221828
}
18231829
ui.add_space(10.0);
18241830
ui.horizontal(|ui| {
1825-
ui.allocate_ui_with_layout(ui.available_size(), egui::Layout::centered_and_justified(egui::Direction::LeftToRight), |ui| {
1826-
if ui.button("Cancel").clicked() {
1827-
engine_action = EngineAction::CloseUrlDialog;
1828-
}
1829-
if ui.button("Open").clicked() || (text_resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
1831+
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
1832+
if ui.add_sized([80.0, 30.0], egui::Button::new("Open")).clicked() || (text_resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
18301833
if !url_text.is_empty() {
18311834
engine_action = EngineAction::LoadUrl(url_text);
18321835
}
18331836
}
1837+
if ui.add_sized([80.0, 30.0], egui::Button::new("Cancel")).clicked() {
1838+
engine_action = EngineAction::CloseUrlDialog;
1839+
}
18341840
});
18351841
});
1842+
1843+
if !state.url_history.is_empty() {
1844+
ui.separator();
1845+
ui.label(egui::RichText::new("Recent Streams:").strong());
1846+
egui::ScrollArea::vertical().max_height(150.0).show(ui, |ui| {
1847+
for (url, title) in &state.url_history {
1848+
if ui.add_sized(
1849+
[ui.available_width(), 30.0],
1850+
egui::Button::new(format!("{} ({})", title, url))
1851+
).clicked() {
1852+
engine_action = EngineAction::LoadUrl(url.clone());
1853+
}
1854+
}
1855+
});
1856+
}
18361857
});
18371858
}
18381859

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)