fix(Ui): Fix err with deleting files

This commit is contained in:
Black_Raven committed 2026-03-29 14:18:34 +03:00
1 parent e318699a36
commit 43a5995036
1 file changed
+122 -37
+122 -37
View File
@@ -1,12 +1,14 @@
//! Графический интерфейс для операций rclone.
use crate::operations::{
self, CopyOptions, DeleteOptions, FileInfo, FindOptions, MoveOptions, Remote,
};
use crate::rclone_install::RcloneApp;
use eframe::egui;
use egui::{CentralPanel, ScrollArea, Window, Align2, Color32, Spinner};
use egui::{Align2, CentralPanel, Color32, ScrollArea, Spinner, Window};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use tokio::runtime::Runtime;
use crate::rclone_install::RcloneApp;
use crate::operations::{self, FileInfo, Remote, CopyOptions, MoveOptions, DeleteOptions, FindOptions};
/// Состояние приложения.
#[derive(Clone)]
@@ -153,8 +155,12 @@ impl RcloneUI {
Ok(types) => self.available_remote_types = types,
Err(_) => {
self.available_remote_types = vec![
"drive".to_string(), "s3".to_string(), "dropbox".to_string(),
"local".to_string(), "onedrive".to_string(), "webdav".to_string(),
"drive".to_string(),
"s3".to_string(),
"dropbox".to_string(),
"local".to_string(),
"onedrive".to_string(),
"webdav".to_string(),
];
}
}
@@ -268,7 +274,12 @@ impl RcloneUI {
rt.block_on(async {
operations::sync::move_files(&rclone, &source, &dest, &options)
})
.map(|stats| format!("Перемещено {} файлов, {} байт", stats.files, stats.transferred))
.map(|stats| {
format!(
"Перемещено {} файлов, {} байт",
stats.files, stats.transferred
)
})
.map_err(|e| format!("Ошибка перемещения: {}", e))
});
}
@@ -287,9 +298,7 @@ impl RcloneUI {
let dest = dest.to_string();
self.start_background_operation(move || {
let rt = Runtime::new().unwrap();
rt.block_on(async {
operations::sync::copy(&rclone, &source, &dest, &options)
})
rt.block_on(async { operations::sync::copy(&rclone, &source, &dest, &options) })
.map(|stats| format!("Скопировано {} файлов", stats.files))
.map_err(|e| format!("Ошибка копирования: {}", e))
});
@@ -328,27 +337,46 @@ impl RcloneUI {
}
fn validate_remote_name(name: &str) -> bool {
if name.is_empty() || name.starts_with(' ') || name.starts_with('-') || name.ends_with(' ') {
if name.is_empty() || name.starts_with(' ') || name.starts_with('-') || name.ends_with(' ')
{
return false;
}
name.chars().all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '-' || ch == '.' || ch == '+' || ch == '@' || ch == ' ')
name.chars().all(|ch| {
ch.is_ascii_alphanumeric()
|| ch == '_'
|| ch == '-'
|| ch == '.'
|| ch == '+'
|| ch == '@'
|| ch == ' '
})
}
fn format_size(bytes: u64) -> String {
const KB: u64 = 1024;
const MB: u64 = KB * 1024;
const GB: u64 = MB * 1024;
if bytes >= GB { format!("{:.2} ГБ", bytes as f64 / GB as f64) }
else if bytes >= MB { format!("{:.2} МБ", bytes as f64 / MB as f64) }
else if bytes >= KB { format!("{:.2} КБ", bytes as f64 / KB as f64) }
else { format!("{} Б", bytes) }
if bytes >= GB {
format!("{:.2} ГБ", bytes as f64 / GB as f64)
} else if bytes >= MB {
format!("{:.2} МБ", bytes as f64 / MB as f64)
} else if bytes >= KB {
format!("{:.2} КБ", bytes as f64 / KB as f64)
} else {
format!("{} Б", bytes)
}
}
fn format_speed(speed: f64) -> String {
if speed < 1024.0 { format!("{:.0} Б/с", speed) }
else if speed < 1024.0 * 1024.0 { format!("{:.1} КБ/с", speed / 1024.0) }
else if speed < 1024.0 * 1024.0 * 1024.0 { format!("{:.1} МБ/с", speed / (1024.0 * 1024.0)) }
else { format!("{:.2} ГБ/с", speed / (1024.0 * 1024.0 * 1024.0)) }
if speed < 1024.0 {
format!("{:.0} Б/с", speed)
} else if speed < 1024.0 * 1024.0 {
format!("{:.1} КБ/с", speed / 1024.0)
} else if speed < 1024.0 * 1024.0 * 1024.0 {
format!("{:.1} МБ/с", speed / (1024.0 * 1024.0))
} else {
format!("{:.2} ГБ/с", speed / (1024.0 * 1024.0 * 1024.0))
}
}
}
@@ -364,7 +392,9 @@ impl eframe::App for RcloneUI {
egui::TopBottomPanel::top("menu_bar").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("Файл", |ui| {
if ui.button("Выход").clicked() { std::process::exit(0); }
if ui.button("Выход").clicked() {
std::process::exit(0);
}
});
ui.menu_button("Хранилища", |ui| {
if ui.button("Добавить новое хранилище").clicked() {
@@ -376,13 +406,24 @@ impl eframe::App for RcloneUI {
});
ui.menu_button("Настройки", |ui| {
ui.checkbox(&mut self.settings.show_hidden, "Показывать скрытые файлы");
ui.checkbox(&mut self.settings.confirm_before_transfer, "Подтверждать перед передачей");
ui.add(egui::Slider::new(&mut self.settings.max_concurrent_transfers, 1..=10).text("Макс. одновременных передач"));
ui.checkbox(
&mut self.settings.confirm_before_transfer,
"Подтверждать перед передачей",
);
ui.add(
egui::Slider::new(&mut self.settings.max_concurrent_transfers, 1..=10)
.text("Макс. одновременных передач"),
);
ui.horizontal(|ui| {
ui.label("Ограничение скорости:");
let mut limit_str = self.settings.bandwidth_limit.clone().unwrap_or_default();
let mut limit_str =
self.settings.bandwidth_limit.clone().unwrap_or_default();
if ui.text_edit_singleline(&mut limit_str).changed() {
self.settings.bandwidth_limit = if limit_str.is_empty() { None } else { Some(limit_str) };
self.settings.bandwidth_limit = if limit_str.is_empty() {
None
} else {
Some(limit_str)
};
}
});
});
@@ -395,10 +436,18 @@ impl eframe::App for RcloneUI {
});
} else {
match &self.state {
AppState::Ready => { ui.colored_label(Color32::GREEN, "● Готов"); }
AppState::Initializing => { ui.colored_label(Color32::YELLOW, "● Инициализация..."); }
AppState::Error(_) => { ui.colored_label(Color32::RED, "● Ошибка"); }
_ => { ui.colored_label(Color32::BLUE, "● Занят"); }
AppState::Ready => {
ui.colored_label(Color32::GREEN, "● Готов");
}
AppState::Initializing => {
ui.colored_label(Color32::YELLOW, "● Инициализация...");
}
AppState::Error(_) => {
ui.colored_label(Color32::RED, "● Ошибка");
}
_ => {
ui.colored_label(Color32::BLUE, "● Занят");
}
}
};
if let Some(rclone) = &self.rclone {
@@ -427,7 +476,8 @@ impl eframe::App for RcloneUI {
if ui.button(format!("📡 {}", remote.name)).clicked() {
self.pending_load_path = Some(format!("{}:", remote.name));
}
if ui.button("🗑️").on_hover_text("Удалить хранилище").clicked() {
if ui.button("🗑️").on_hover_text("Удалить хранилище").clicked()
{
self.remote_to_delete = Some(remote.name.clone());
self.show_delete_remote_dialog = true;
}
@@ -445,7 +495,11 @@ impl eframe::App for RcloneUI {
let mut new_search = search_pattern.clone();
ui.horizontal(|ui| {
ui.label("📍 Путь:");
ui.label(if current_path.is_empty() { "Выберите хранилище" } else { &current_path });
ui.label(if current_path.is_empty() {
"Выберите хранилище"
} else {
&current_path
});
ui.separator();
ui.label("🔍 Поиск:");
if ui.text_edit_singleline(&mut new_search).changed() {
@@ -469,7 +523,7 @@ impl eframe::App for RcloneUI {
ui.add_space(10.0);
ui.colored_label(
egui::Color32::LIGHT_BLUE,
"⟳ Выполняется операция... Пожалуйста, подождите."
"⟳ Выполняется операция... Пожалуйста, подождите.",
);
});
ctx.request_repaint_after(Duration::from_millis(16));
@@ -507,7 +561,9 @@ impl eframe::App for RcloneUI {
let current_files = self.current_files.clone();
let current_path = self.current_path.clone();
ScrollArea::vertical().show(ui, |ui| {
if current_path.contains('/') && ui.button("📁 .. (Родительская папка)").clicked() {
if current_path.contains('/')
&& ui.button("📁 .. (Родительская папка)").clicked()
{
let parent = current_path.rsplit_once('/').map(|(p, _)| p).unwrap_or("");
self.pending_load_path = Some(parent.to_string());
}
@@ -569,7 +625,20 @@ impl eframe::App for RcloneUI {
if ui.button("🗑️ Удалить").clicked() {
if let Some(rclone) = self.rclone.clone() {
let path = self.selected_paths[0].clone();
let options = DeleteOptions { recursive: true, verbose: true, dry_run: false };
// Определяем, является ли выбранный путь директорией
let is_dir = self.current_files.iter().any(|f| {
let full_path = if self.current_path.ends_with(':') {
format!("{}{}", self.current_path, f.name)
} else {
format!("{}/{}", self.current_path, f.name)
};
full_path == path && f.is_dir
});
let options = DeleteOptions {
recursive: is_dir,
verbose: true,
dry_run: false,
};
self.start_background_operation(move || {
operations::sync::delete(&rclone, &path, &options)
.map(|_| format!("Удалено: {}", path))
@@ -594,7 +663,11 @@ impl eframe::App for RcloneUI {
if self.show_transfer_dialog {
let source = self.transfer_source.clone();
let dest = self.transfer_dest.clone();
Window::new("Передача файлов").collapsible(false).resizable(false).anchor(Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
Window::new("Передача файлов")
.collapsible(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, [0.0, 0.0])
.show(ctx, |ui| {
ui.label(format!("Источник: {}", source));
ui.label("Назначение:");
let mut dest_edit = dest.clone();
@@ -664,7 +737,11 @@ impl eframe::App for RcloneUI {
// Диалог предупреждения о браузере
if self.show_browser_warning {
Window::new("Внимание").collapsible(false).resizable(false).anchor(Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
Window::new("Внимание")
.collapsible(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, [0.0, 0.0])
.show(ctx, |ui| {
ui.colored_label(Color32::YELLOW, "🌐 Будет открыт браузер для авторизации");
ui.label("После завершения авторизации в браузере вернитесь в приложение.");
ui.label("Операция выполняется в фоне, интерфейс не зависнет.");
@@ -685,7 +762,11 @@ impl eframe::App for RcloneUI {
// Диалог подтверждения удаления хранилища
if self.show_delete_remote_dialog {
let remote_name = self.remote_to_delete.clone();
Window::new("Удаление хранилища").collapsible(false).resizable(false).anchor(Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
Window::new("Удаление хранилища")
.collapsible(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, [0.0, 0.0])
.show(ctx, |ui| {
if let Some(ref name) = remote_name {
ui.label(format!("Удалить хранилище '{}'?", name));
ui.label("Это действие не удаляет данные, только конфигурацию.");
@@ -710,7 +791,11 @@ impl eframe::App for RcloneUI {
// Диалог ошибок
if let Some(error) = &self.error_message {
let error_clone = error.clone();
Window::new("Ошибка").collapsible(false).resizable(false).anchor(Align2::CENTER_CENTER, [0.0, 0.0]).show(ctx, |ui| {
Window::new("Ошибка")
.collapsible(false)
.resizable(false)
.anchor(Align2::CENTER_CENTER, [0.0, 0.0])
.show(ctx, |ui| {
ui.colored_label(Color32::RED, "⚠️ Произошла ошибка:");
ui.label(&error_clone);
if ui.button("OK").clicked() {