fix gui error

This commit is contained in:
Tan, Kian-ting 2025-08-16 23:25:41 +08:00
parent 86ffdd03d1
commit dc3a65099d

View file

@ -49,15 +49,26 @@ fn main() -> glib::ExitCode {
//let mut links = vec!(); //let mut links = vec!();
fn download_and_convert(mut links : &Vec<&'static str>, fn download_and_convert(mut links : &Vec<&str>,
output_path : &str, output_path : GString,
format : OutputFormat, format : OutputFormat,
tmp_window_clone : &ApplicationWindow, tmp_window_clone : &ApplicationWindow,
status_info_label: &gtk4::Label){ status_info_label: &gtk4::Label){
let tmp_window_clone = tmp_window_clone.clone(); let tmp_window_clone = tmp_window_clone.clone();
let tmp_window_clone2: ApplicationWindow = tmp_window_clone.clone(); let tmp_window_clone2: ApplicationWindow = tmp_window_clone.clone();
let output_path_clone = output_path.clone();
let mut output_path_clone = Box::new(output_path.clone());
fn real_download(output_path: &str,
format: OutputFormat,
tmp_window_clone: &ApplicationWindow,
status_info_label: &gtk4::Label,
lnk: String,
is_processed: bool) {
println!("Lnk: {}", lnk);
fn real_download(output_path: &str, format: OutputFormat, tmp_window_clone: &ApplicationWindow, status_info_label: &gtk4::Label, lnk: String, is_processed: bool) {
let output_format = match format { let output_format = match format {
OutputFormat::FLAC => "flac", OutputFormat::FLAC => "flac",
OutputFormat::MP3 => "mp3", OutputFormat::MP3 => "mp3",
@ -74,6 +85,8 @@ fn main() -> glib::ExitCode {
.arg(output_format) .arg(output_format)
.output(); .output();
println!("{:?} {}", res, lnk);
match res { match res {
Ok(_) => status_info_label.set_text(format!("\"{}\" downloaded!", &lnk).as_str()), Ok(_) => status_info_label.set_text(format!("\"{}\" downloaded!", &lnk).as_str()),
Err(masg) => { Err(masg) => {
@ -115,6 +128,11 @@ fn main() -> glib::ExitCode {
} }
let mut links = links.clone(); let mut links = links.clone();
println!("{:?}", links);
for lnk in links.iter_mut(){ for lnk in links.iter_mut(){
let re = Regex::new(r"list=").unwrap(); let re = Regex::new(r"list=").unwrap();
@ -123,9 +141,10 @@ fn main() -> glib::ExitCode {
let mut is_processed = true; let mut is_processed = true;
let format_clone = format.clone(); let format_clone = format.clone();
let lnk_clone = lnk.clone(); let lnk_clone = Box::leak(Box::new(lnk.clone()));
match capturing{ match capturing{
None =>{is_processed = true; real_download(output_path.clone(), format_clone, &tmp_window_clone, status_info_label, lnk.to_string(), is_processed);}, None =>{is_processed = true; real_download(&output_path.clone(), format_clone, &tmp_window_clone, status_info_label, lnk.to_string(), is_processed);},
Some(v) => { Some(v) => {
is_processed = false; is_processed = false;
let dialog = gtk::AlertDialog::builder() let dialog = gtk::AlertDialog::builder()
@ -140,11 +159,18 @@ fn main() -> glib::ExitCode {
let tmp_window_clone3 = tmp_window_clone2.clone();
let status_info_label = status_info_label.clone();
let lnk_clone_s = lnk_clone.to_string().clone();
let output_path_clone2 = output_path_clone.clone();
dialog.choose(Some(&tmp_window_clone), gio::Cancellable::NONE, move |result| { dialog.choose(Some(&tmp_window_clone), gio::Cancellable::NONE, move |result| {
if result.is_err() || result.unwrap() != 1 { if result.is_err() || result.unwrap() != 1 {
let is_processed = true;
println!("continue"); println!("continue");
let output_path = Box::new(output_path); //let output_path = Box::new(output_path);
real_download(*output_path, format, &tmp_window_clone2, status_info_label, lnk_clone.to_string(), is_processed); //let output_path_clone4 = value;
real_download(&output_path_clone2, format, &tmp_window_clone3, &status_info_label, lnk_clone_s, is_processed);
return;
}else{ }else{
println!("cancel"); println!("cancel");
is_processed = false; is_processed = false;
@ -300,25 +326,34 @@ fn main() -> glib::ExitCode {
let text_buffer2 = text_buffer.clone(); let text_buffer2 = text_buffer.clone();
let tmp_window_clone: ApplicationWindow = window.clone(); let tmp_window_clone: ApplicationWindow = window.clone();
let start_iter = text_buffer2.start_iter(); //let start_iter = text_buffer2.start_iter();
let end_iter = text_buffer2.end_iter(); //let end_iter = text_buffer2.end_iter();
//let mut links = text_buffer2.text(&start_iter, &end_iter, true); //let mut links = text_buffer2.text(&start_iter, &end_iter, true);
let status_info_label_cloned = status_info_label.clone(); let status_info_label_cloned = status_info_label.clone();
convert_button.connect_clicked(move|_|{ convert_button.connect_clicked(move|_|{
let output_path = path_entry_cloned_for_converting.buffer().text();
let output_path_cloned = output_path.clone();
let start_iter = text_buffer2.start_iter();
let end_iter = text_buffer2.end_iter();
let mut links = text_buffer2.text(&start_iter, &end_iter, true);
let mut link_clone = links.clone();
let new_line_pattern = Regex::new(r"(\r?\n)+").expect("invalid regex"); let new_line_pattern = Regex::new(r"(\r?\n)+").expect("invalid regex");
let mut links = text_buffer2.text(&start_iter, &end_iter, true); let mut link_vector: Vec<&str> = vec!();
let link_as_str = links.as_str();
let link_vector = new_line_pattern.split(link_as_str).collect();
if link_vector == [""]{ let link_as_str = link_clone; //.as_str();
link_vector = new_line_pattern.split(&link_as_str).collect();
if *link_vector == [""]{
show_empty_output_error(Some(&tmp_window_clone)); show_empty_output_error(Some(&tmp_window_clone));
} }
let output_path = path_entry_cloned_for_converting.buffer().text();
let format: OutputFormat; let format: OutputFormat;
@ -332,7 +367,8 @@ fn main() -> glib::ExitCode {
format = OutputFormat::FLAC; format = OutputFormat::FLAC;
} }
download_and_convert(link_vector, output_path.as_str(), let output_path_str = output_path_cloned;
download_and_convert(&link_vector, output_path_str,
format, format,
&tmp_window_clone, &tmp_window_clone,
&status_info_label_cloned); &status_info_label_cloned);