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 288e9d9 commit 03eda95
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct SubscriptionManager {
pub download_progress: Option<f32>, // 下载进度
pub download_status: Option<String>, // 下载状态信息
pub download_url: String, // 当前输入的下载链接
pub start_download: bool, // 标志是否触发下载
pub start_download_request: bool, // 标志是否触发下载
}

impl Default for SubscriptionManager {
Expand All @@ -18,7 +18,7 @@ impl Default for SubscriptionManager {
download_progress: None,
download_status: None,
download_url: String::new(),
start_download: false,
start_download_request: false,
}
}
}
Expand All @@ -29,31 +29,28 @@ impl SubscriptionManager {
egui::Window::new("订阅规则")
.open(&mut self.is_open)
.show(ctx, |ui| {
self.show_controls(ui);
self.show_subscriptions(ui);
self.show_download_status(ui);
self.render_controls(ui);
self.render_subscriptions(ui);
self.render_download_status(ui);
});

// 在 UI 渲染完成后处理状态更新
if self.start_download {
self.start_download();
self.start_download = false;
if self.start_download_request {
self.handle_start_download();
self.start_download_request = false;
}
}
}

fn show_controls(&mut self, ui: &mut egui::Ui) {
fn render_controls(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.add(
egui::TextEdit::singleline(&mut self.download_url).hint_text("请输入规则下载链接"),
);

if ui.button("下载规则").clicked() {
self.start_download = true;
}

if ui.input(|i| i.key_pressed(egui::Key::Enter)) {
self.start_download = true;
if ui.button("下载规则").clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter))
{
self.start_download_request = true;
}

if ui.button("从文件导入").clicked() {
Expand All @@ -63,7 +60,7 @@ impl SubscriptionManager {
ui.separator();
}

fn show_subscriptions(&mut self, ui: &mut egui::Ui) {
fn render_subscriptions(&mut self, ui: &mut egui::Ui) {
ui.label("已订阅规则:");
let subscriptions_to_remove: Vec<String> = self
.subscriptions
Expand All @@ -89,7 +86,7 @@ impl SubscriptionManager {
}
}

fn show_download_status(&mut self, ui: &mut egui::Ui) {
fn render_download_status(&mut self, ui: &mut egui::Ui) {
if let Some(progress) = self.download_progress {
ui.add(egui::ProgressBar::new(progress).show_percentage());
}
Expand All @@ -98,7 +95,7 @@ impl SubscriptionManager {
}
}

fn start_download(&mut self) {
fn handle_start_download(&mut self) {
if self.download_url.is_empty() {
self.download_status = Some("请输入有效的下载链接".to_string());
return;
Expand Down

0 comments on commit 03eda95

Please sign in to comment.