pacsea/ui/helpers/preflight.rs
1//! Preflight resolution status utilities.
2//!
3//! This module provides functions for checking preflight resolution status of packages.
4
5use crate::state::AppState;
6
7/// What: Check if a package is currently being processed by any preflight resolver.
8///
9/// Inputs:
10/// - `app`: Application state containing preflight resolution queues and flags.
11/// - `package_name`: Name of the package to check.
12///
13/// Output:
14/// - `true` if the package is in any preflight resolution queue and the corresponding resolver is active.
15///
16/// Details:
17/// - Checks if the package name appears in any of the preflight queues (summary, deps, files, services, sandbox)
18/// and if the corresponding resolving flag is set to true.
19/// - Also checks install list resolution (when preflight modal is not open) by checking if the package
20/// is in `app.install_list` and any resolver is active.
21#[must_use]
22pub fn is_package_loading_preflight(app: &AppState, package_name: &str) -> bool {
23 // Check summary resolution (preflight-specific)
24 if app.preflight_summary_resolving
25 && let Some((ref items, _)) = app.preflight_summary_items
26 && items.iter().any(|p| p.name == package_name)
27 {
28 return true;
29 }
30
31 // Check dependency resolution
32 // First check preflight-specific queue (when modal is open)
33 if app.preflight_deps_resolving
34 && let Some((ref items, _action)) = app.preflight_deps_items
35 && items.iter().any(|p| p.name == package_name)
36 {
37 return true;
38 }
39 // Then check install list resolution (when modal is not open)
40 // Only show indicator if deps are actually resolving AND package is in install list
41 if app.deps_resolving
42 && !app.preflight_deps_resolving
43 && app.install_list.iter().any(|p| p.name == package_name)
44 {
45 return true;
46 }
47
48 // Check file resolution
49 // First check preflight-specific queue (when modal is open)
50 if app.preflight_files_resolving
51 && let Some(ref items) = app.preflight_files_items
52 && items.iter().any(|p| p.name == package_name)
53 {
54 return true;
55 }
56 // Then check install list resolution (when modal is not open)
57 // Only show indicator if files are actually resolving AND preflight is not resolving
58 if app.files_resolving
59 && !app.preflight_files_resolving
60 && app.install_list.iter().any(|p| p.name == package_name)
61 {
62 return true;
63 }
64
65 // Check service resolution
66 // First check preflight-specific queue (when modal is open)
67 if app.preflight_services_resolving
68 && let Some(ref items) = app.preflight_services_items
69 && items.iter().any(|p| p.name == package_name)
70 {
71 return true;
72 }
73 // Then check install list resolution (when modal is not open)
74 // Only show indicator if services are actually resolving AND preflight is not resolving
75 if app.services_resolving
76 && !app.preflight_services_resolving
77 && app.install_list.iter().any(|p| p.name == package_name)
78 {
79 return true;
80 }
81
82 // Check sandbox resolution
83 // First check preflight-specific queue (when modal is open)
84 if app.preflight_sandbox_resolving
85 && let Some(ref items) = app.preflight_sandbox_items
86 && items.iter().any(|p| p.name == package_name)
87 {
88 return true;
89 }
90 // Then check install list resolution (when modal is not open)
91 // Note: sandbox only applies to AUR packages
92 // Only show indicator if sandbox is actually resolving AND preflight is not resolving
93 if app.sandbox_resolving
94 && !app.preflight_sandbox_resolving
95 && app
96 .install_list
97 .iter()
98 .any(|p| p.name == package_name && matches!(p.source, crate::state::Source::Aur))
99 {
100 return true;
101 }
102
103 false
104}