Skip to content

Commit

Permalink
bak
Browse files Browse the repository at this point in the history
  • Loading branch information
TC999 committed Dec 11, 2024
1 parent 8e45a57 commit 0789199
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 35 deletions.
97 changes: 63 additions & 34 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::collections::HashMap;
pub struct SubscriptionManager {
pub is_open: bool,
pub subscriptions: HashMap<String, String>, // 显示已订阅规则,键为名称,值为描述或文件路径
pub download_progress: Option<f32>, // 下载进度
pub download_status: Option<String>, // 下载状态信息
pub download_progress: Option<f32>, // 下载进度
pub download_status: Option<String>, // 下载状态信息
pub download_url: String, // 当前输入的下载链接
}

impl Default for SubscriptionManager {
Expand All @@ -15,6 +16,7 @@ impl Default for SubscriptionManager {
subscriptions: HashMap::new(),
download_progress: None,
download_status: None,
download_url: String::new(),
}
}
}
Expand All @@ -25,56 +27,83 @@ impl SubscriptionManager {
egui::Window::new("订阅规则")
.open(&mut self.is_open)
.show(ctx, |ui| {
ui.horizontal(|ui| {
if ui.button("下载规则").clicked() {
self.start_download_dialog(ui);
}
if ui.button("从文件导入").clicked() {
self.import_from_file();
}
});
self.show_controls(ui);
self.show_subscriptions(ui);
self.show_download_status(ui);
});
}
}

ui.separator();
ui.label("已订阅规则:");
for (name, description) in &self.subscriptions {
ui.horizontal(|ui| {
ui.label(format!("{} - {}", name, description));
if ui.button("删除").clicked() {
self.subscriptions.remove(name);
}
});
}
fn show_controls(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
if ui.button("下载规则").clicked() {
self.start_download_dialog(ui);
}
if ui.button("从文件导入").clicked() {
self.import_from_file();
}
});
ui.separator();
}

if let Some(progress) = self.download_progress {
ui.add(egui::ProgressBar::new(progress).show_percentage());
}
if let Some(status) = &self.download_status {
ui.label(status);
fn show_subscriptions(&mut self, ui: &mut egui::Ui) {
ui.label("已订阅规则:");
let subscriptions_to_remove: Vec<String> = self
.subscriptions
.iter()
.filter_map(|(name, description)| {
let mut remove = false;
ui.horizontal(|ui| {
ui.label(format!("{} - {}", name, description));
if ui.button("删除").clicked() {
remove = true;
}
});
if remove {
Some(name.clone())
} else {
None
}
})
.collect();

for name in subscriptions_to_remove {
self.subscriptions.remove(&name);
}
}

fn show_download_status(&mut self, ui: &mut egui::Ui) {
if let Some(progress) = self.download_progress {
ui.add(egui::ProgressBar::new(progress).show_percentage());
}
if let Some(status) = &self.download_status {
ui.label(status);
}
}

fn start_download_dialog(&mut self, ui: &mut egui::Ui) {
ui.label("请输入规则下载链接:");
let mut url = String::new();
ui.text_edit_singleline(&mut url);
ui.text_edit_singleline(&mut self.download_url);

if ui.button("确定").clicked() {
self.download_progress = Some(0.0);
self.download_status = Some("开始下载...".to_string());
// 模拟下载流程
// TODO: 实现异步下载逻辑,更新进度并完成时移除弹窗
self.download_progress = Some(1.0); // 下载完成
self.download_status = Some("下载完成".to_string());
self.subscriptions
.insert("新规则".to_string(), "从网络下载".to_string());

// 模拟异步下载逻辑
self.simulate_download();
}
}

fn simulate_download(&mut self) {
// 这里是模拟的下载过程,你可以改为异步任务
self.download_progress = Some(1.0); // 下载完成
self.download_status = Some("下载完成".to_string());
self.subscriptions
.insert("新规则".to_string(), "从网络下载".to_string());
}

fn import_from_file(&mut self) {
// TODO: 打开文件选择窗口,解析 YAML 并更新订阅规则
// 示例添加一个规则
self.subscriptions
.insert("本地规则".to_string(), "从文件导入".to_string());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::logger; // 导入 logger 模块
use crate::move_module; // 导入移动模块
use crate::open;
use crate::scanner;
use crate::subscription;
use crate::utils;
use crate::yaml_loader::FolderDescriptions;
use eframe::egui::{self, Grid, ScrollArea};
use std::collections::HashSet;
use std::sync::mpsc::{Receiver, Sender};
use subscription::SubscriptionManager;

pub struct AppDataCleaner {
is_scanning: bool,
Expand Down

0 comments on commit 0789199

Please sign in to comment.