pacsea 0.8.2

A fast, friendly TUI for browsing and installing Arch and AUR packages with built-in news and security scanning
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
use crate::state::AppState;

/// What: Load cached dependencies filtered by item names.
///
/// Inputs:
/// - `app`: Application state reference
/// - `item_names`: Set of package names to filter dependencies by
///
/// Output:
/// - Vector of filtered dependency info, or empty if cache unavailable
///
/// Details:
/// - Filters cached dependencies to only those required by current items
/// - Returns empty vector if cache is resolving or empty
fn load_cached_dependencies(
    app: &AppState,
    item_names: &std::collections::HashSet<String>,
) -> Vec<crate::state::modal::DependencyInfo> {
    if app.deps_resolving || app.install_list_deps.is_empty() {
        tracing::debug!("[Install] No cached dependencies available");
        return Vec::new();
    }

    let filtered: Vec<crate::state::modal::DependencyInfo> = app
        .install_list_deps
        .iter()
        .filter(|dep| {
            dep.required_by
                .iter()
                .any(|req_by| item_names.contains(req_by))
        })
        .cloned()
        .collect();

    if filtered.is_empty() {
        tracing::debug!("[Install] Cached dependencies exist but none match current items");
        Vec::new()
    } else {
        tracing::debug!(
            "[Install] Using {} cached dependencies (filtered from {} total)",
            filtered.len(),
            app.install_list_deps.len()
        );
        filtered
    }
}

/// What: Load cached file information.
///
/// Inputs:
/// - `app`: Application state reference
/// - `items`: Package items for logging
///
/// Output:
/// - Vector of cached file info, or empty if cache unavailable
///
/// Details:
/// - Returns cached files if available and not currently resolving
fn load_cached_files(
    app: &AppState,
    items: &[crate::state::types::PackageItem],
) -> Vec<crate::state::modal::PackageFileInfo> {
    tracing::debug!(
        "[Install] Checking file cache: resolving={}, install_list_files={}, items={:?}",
        app.files_resolving,
        app.install_list_files.len(),
        items.iter().map(|i| &i.name).collect::<Vec<_>>()
    );

    if app.files_resolving || app.install_list_files.is_empty() {
        tracing::debug!(
            "[Install] No cached files available (resolving={}, empty={})",
            app.files_resolving,
            app.install_list_files.is_empty()
        );
        return Vec::new();
    }

    tracing::debug!(
        "[Install] Using {} cached file entries: {:?}",
        app.install_list_files.len(),
        app.install_list_files
            .iter()
            .map(|f| &f.name)
            .collect::<Vec<_>>()
    );
    for file_info in &app.install_list_files {
        tracing::debug!(
            "[Install] Cached file entry: Package '{}' - total={}, new={}, changed={}, removed={}, config={}",
            file_info.name,
            file_info.total_count,
            file_info.new_count,
            file_info.changed_count,
            file_info.removed_count,
            file_info.config_count
        );
    }
    app.install_list_files.clone()
}

/// What: Load cached services and check if services are loaded.
///
/// Inputs:
/// - `app`: Application state reference
///
/// Output:
/// - Tuple of (cached services, whether services are loaded)
///
/// Details:
/// - Checks both in-memory cache and cache file to determine loaded state
fn load_cached_services(app: &AppState) -> (Vec<crate::state::modal::ServiceImpact>, bool) {
    let cached_services = if !app.services_resolving && !app.install_list_services.is_empty() {
        tracing::debug!(
            "[Install] Using {} cached services",
            app.install_list_services.len()
        );
        app.install_list_services.clone()
    } else {
        tracing::debug!("[Install] No cached services available");
        Vec::new()
    };

    let services_cache_loaded = if app.install_list.is_empty() {
        false
    } else {
        let signature = crate::app::services_cache::compute_signature(&app.install_list);
        let loaded =
            crate::app::services_cache::load_cache(&app.services_cache_path, &signature).is_some();
        tracing::debug!(
            "[Install] Services cache check: {} (signature match: {})",
            if loaded { "found" } else { "not found" },
            signature.len()
        );
        loaded
    };

    let services_loaded = services_cache_loaded || !cached_services.is_empty();
    (cached_services, services_loaded)
}

/// What: Restore user restart decisions from pending service plan.
///
/// Inputs:
/// - `app`: Application state reference
/// - `services`: Mutable vector of service impacts to update
///
/// Output:
/// - No return value; modifies services in place
///
/// Details:
/// - Applies saved restart decisions from `pending_service_plan` to services
fn restore_service_decisions(app: &AppState, services: &mut [crate::state::modal::ServiceImpact]) {
    if app.pending_service_plan.is_empty() || services.is_empty() {
        return;
    }

    let decision_map: std::collections::HashMap<
        String,
        crate::state::modal::ServiceRestartDecision,
    > = app
        .pending_service_plan
        .iter()
        .map(|s| (s.unit_name.clone(), s.restart_decision))
        .collect();

    for service in services.iter_mut() {
        if let Some(&saved_decision) = decision_map.get(&service.unit_name) {
            service.restart_decision = saved_decision;
        }
    }
}

/// What: Load cached sandbox info and check if sandbox is loaded.
///
/// Inputs:
/// - `app`: Application state reference
/// - `items`: Package items for cache signature computation
///
/// Output:
/// - Tuple of (cached sandbox info, whether sandbox is loaded)
///
/// Details:
/// - Checks both in-memory cache and cache file to determine loaded state
fn load_cached_sandbox(
    app: &AppState,
    items: &[crate::state::types::PackageItem],
) -> (Vec<crate::logic::sandbox::SandboxInfo>, bool) {
    tracing::debug!(
        "[Install] Checking sandbox cache: resolving={}, install_list_sandbox={}, items={:?}",
        app.sandbox_resolving,
        app.install_list_sandbox.len(),
        items.iter().map(|i| &i.name).collect::<Vec<_>>()
    );

    let cached_sandbox = if !app.sandbox_resolving && !app.install_list_sandbox.is_empty() {
        tracing::debug!(
            "[Install] Using {} cached sandbox entries: {:?}",
            app.install_list_sandbox.len(),
            app.install_list_sandbox
                .iter()
                .map(|s| &s.package_name)
                .collect::<Vec<_>>()
        );
        app.install_list_sandbox.clone()
    } else {
        tracing::debug!(
            "[Install] No cached sandbox available (resolving={}, empty={})",
            app.sandbox_resolving,
            app.install_list_sandbox.is_empty()
        );
        Vec::new()
    };

    let sandbox_cache_loaded = if items.is_empty() {
        false
    } else {
        let signature = crate::app::sandbox_cache::compute_signature(items);
        let cache_result =
            crate::app::sandbox_cache::load_cache(&app.sandbox_cache_path, &signature);
        tracing::debug!(
            "[Install] Sandbox cache file check: signature={:?}, found={}, cached_entries={}",
            signature,
            cache_result.is_some(),
            cache_result.as_ref().map_or(0, Vec::len)
        );
        if let Some(ref cached) = cache_result {
            tracing::debug!(
                "[Install] Cached sandbox packages: {:?}",
                cached.iter().map(|s| &s.package_name).collect::<Vec<_>>()
            );
        }
        cache_result.is_some()
    };

    let sandbox_loaded = sandbox_cache_loaded || !cached_sandbox.is_empty();
    tracing::debug!(
        "[Install] Final sandbox state: cached_sandbox={}, sandbox_cache_loaded={}, sandbox_loaded={}",
        cached_sandbox.len(),
        sandbox_cache_loaded,
        sandbox_loaded
    );
    (cached_sandbox, sandbox_loaded)
}

/// What: Create minimal summary data for immediate display.
///
/// Inputs:
/// - `app`: Application state reference
/// - `items`: Package items to create summary for
///
/// Output:
/// - Tuple of (summary data, header chips)
///
/// Details:
/// - Creates minimal summary without blocking pacman calls
/// - Full summary computed asynchronously after modal opens
fn create_minimal_summary(
    app: &AppState,
    items: &[crate::state::types::PackageItem],
) -> (
    crate::state::modal::PreflightSummaryData,
    crate::state::modal::PreflightHeaderChips,
) {
    let aur_count = items
        .iter()
        .filter(|p| matches!(p.source, crate::state::Source::Aur))
        .count();

    tracing::debug!(
        "[Install] Creating minimal summary for {} packages ({} AUR)",
        items.len(),
        aur_count
    );

    let has_aur = aur_count > 0;
    let risk_score = if has_aur { 2 } else { 0 };
    let risk_level = if has_aur {
        crate::state::modal::RiskLevel::Medium
    } else {
        crate::state::modal::RiskLevel::Low
    };
    let aur_warning = if has_aur {
        vec![crate::i18n::t(
            app,
            "app.modals.preflight.summary.aur_packages_included",
        )]
    } else {
        vec![]
    };
    let aur_note = if has_aur {
        vec![crate::i18n::t(
            app,
            "app.modals.preflight.summary.aur_packages_present",
        )]
    } else {
        vec![]
    };

    let minimal_summary = crate::state::modal::PreflightSummaryData {
        packages: items
            .iter()
            .map(|item| crate::state::modal::PreflightPackageSummary {
                name: item.name.clone(),
                source: item.source.clone(),
                installed_version: None,
                target_version: item.version.clone(),
                is_downgrade: false,
                is_major_bump: false,
                download_bytes: None,
                install_delta_bytes: None,
                notes: vec![],
            })
            .collect(),
        package_count: items.len(),
        aur_count,
        download_bytes: 0,
        install_delta_bytes: 0,
        risk_score,
        risk_level,
        risk_reasons: aur_warning.clone(),
        major_bump_packages: vec![],
        core_system_updates: vec![],
        pacnew_candidates: 0,
        pacsave_candidates: 0,
        config_warning_packages: vec![],
        service_restart_units: vec![],
        summary_warnings: aur_warning,
        summary_notes: aur_note,
    };

    let minimal_header = crate::state::modal::PreflightHeaderChips {
        package_count: items.len(),
        download_bytes: 0,
        install_delta_bytes: 0,
        aur_count,
        risk_score,
        risk_level,
    };

    (minimal_summary, minimal_header)
}

/// What: Trigger background resolution for missing data.
///
/// Inputs:
/// - `app`: Mutable application state
/// - `items`: Package items to resolve
/// - `dependency_info`: Current dependency info (empty triggers resolution)
/// - `cached_files`: Current file info (empty triggers resolution)
/// - `services_loaded`: Whether services are already loaded
/// - `cached_sandbox`: Current sandbox info (empty triggers resolution)
///
/// Output:
/// - No return value; sets resolution flags in app state
///
/// Details:
/// - Triggers background resolution for dependencies, files, services, and sandbox
/// - Only triggers if cache is empty or not loaded
fn trigger_background_resolution(
    app: &mut AppState,
    items: &[crate::state::types::PackageItem],
    dependency_info: &[crate::state::modal::DependencyInfo],
    cached_files: &[crate::state::modal::PackageFileInfo],
    services_loaded: bool,
    cached_sandbox: &[crate::logic::sandbox::SandboxInfo],
) {
    if dependency_info.is_empty() {
        if app.deps_resolving {
            tracing::debug!(
                "[Preflight] NOT setting preflight_deps_resolving (global deps_resolving already in progress, will reuse result)"
            );
        } else {
            tracing::debug!(
                "[Preflight] Setting preflight_deps_resolving=true for {} items (cache empty)",
                items.len()
            );
            app.preflight_deps_items = Some((
                items.to_vec(),
                crate::state::modal::PreflightAction::Install,
            ));
            app.preflight_deps_resolving = true;
        }
    } else {
        tracing::debug!(
            "[Preflight] NOT setting preflight_deps_resolving (cache has {} deps)",
            dependency_info.len()
        );
    }
    if cached_files.is_empty() {
        if app.files_resolving {
            tracing::debug!(
                "[Preflight] NOT setting preflight_files_resolving (global files_resolving already in progress, will reuse result)"
            );
        } else {
            tracing::debug!(
                "[Preflight] Setting preflight_files_resolving=true for {} items (cache empty)",
                items.len()
            );
            app.preflight_files_items = Some(items.to_vec());
            app.preflight_files_resolving = true;
        }
    } else {
        tracing::debug!(
            "[Preflight] NOT setting preflight_files_resolving (cache has {} files)",
            cached_files.len()
        );
    }
    if services_loaded {
        tracing::debug!("[Preflight] NOT setting preflight_services_resolving (already loaded)");
    } else if app.services_resolving {
        tracing::debug!(
            "[Preflight] NOT setting preflight_services_resolving (global services_resolving already in progress, will reuse result)"
        );
    } else {
        tracing::debug!(
            "[Preflight] Setting preflight_services_resolving=true for {} items (not loaded)",
            items.len()
        );
        app.preflight_services_items = Some(items.to_vec());
        app.preflight_services_resolving = true;
    }
    if cached_sandbox.is_empty() {
        let aur_items: Vec<_> = items
            .iter()
            .filter(|p| matches!(p.source, crate::state::Source::Aur))
            .cloned()
            .collect();
        if aur_items.is_empty() {
            tracing::debug!("[Preflight] NOT setting preflight_sandbox_resolving (no AUR items)");
        } else if app.sandbox_resolving {
            tracing::debug!(
                "[Preflight] NOT setting preflight_sandbox_resolving (global sandbox_resolving already in progress, will reuse result)"
            );
        } else {
            tracing::debug!(
                "[Preflight] Setting preflight_sandbox_resolving=true for {} AUR items (cache empty)",
                aur_items.len()
            );
            app.preflight_sandbox_items = Some(aur_items);
            app.preflight_sandbox_resolving = true;
        }
    } else {
        tracing::debug!(
            "[Preflight] NOT setting preflight_sandbox_resolving (cache has {} sandbox entries)",
            cached_sandbox.len()
        );
    }
}

/// What: Open Preflight modal for install action with cached data.
///
/// Inputs:
/// - `app`: Mutable application state
///
/// Output:
/// - No return value; sets app.modal to Preflight with Install action
///
/// Details:
/// - Loads cached dependencies, files, services, and sandbox info
/// - Creates minimal summary for immediate display
/// - Triggers background resolution for missing data
pub fn open_preflight_install_modal(app: &mut AppState) {
    tracing::info!(
        "[Install] Opening preflight modal for {} packages",
        app.install_list.len()
    );
    let start_time = std::time::Instant::now();
    let item_count = app.install_list.len();
    let items = app.install_list.clone();

    let cache_start = std::time::Instant::now();
    let item_names: std::collections::HashSet<String> =
        items.iter().map(|i| i.name.clone()).collect();

    let cached_deps = load_cached_dependencies(app, &item_names);
    let cached_files = load_cached_files(app, &items);
    let (cached_services, services_loaded) = load_cached_services(app);
    let (cached_sandbox, sandbox_loaded) = load_cached_sandbox(app, &items);

    tracing::debug!("[Install] Cache loading took {:?}", cache_start.elapsed());

    let mut final_services = cached_services;
    restore_service_decisions(app, &mut final_services);

    let summary_start = std::time::Instant::now();
    let (minimal_summary, minimal_header) = create_minimal_summary(app, &items);
    tracing::debug!(
        "[Install] Minimal summary creation took {:?}",
        summary_start.elapsed()
    );

    let modal_set_start = std::time::Instant::now();
    let dependency_info = if cached_deps.is_empty() {
        tracing::debug!(
            "[Preflight] Cache empty, will trigger background dependency resolution for {} packages",
            items.len()
        );
        Vec::new()
    } else {
        cached_deps
    };

    app.preflight_cancelled
        .store(false, std::sync::atomic::Ordering::Relaxed);
    app.preflight_summary_items = Some((items.clone(), crate::state::PreflightAction::Install));
    // Don't set preflight_summary_resolving=true here - let the tick handler trigger it
    // This prevents the tick handler from being blocked by the flag already being set
    tracing::debug!(
        "[Preflight] Queued summary computation for {} items",
        items.len()
    );

    trigger_background_resolution(
        app,
        &items,
        &dependency_info,
        &cached_files,
        services_loaded,
        &cached_sandbox,
    );

    app.modal = crate::state::Modal::Preflight {
        items,
        action: crate::state::PreflightAction::Install,
        tab: crate::state::PreflightTab::Summary,
        summary: Some(Box::new(minimal_summary)),
        summary_scroll: 0,
        header_chips: minimal_header,
        dependency_info,
        dep_selected: 0,
        dep_tree_expanded: std::collections::HashSet::new(),
        deps_error: None,
        file_info: cached_files,
        file_selected: 0,
        file_tree_expanded: std::collections::HashSet::new(),
        files_error: None,
        service_info: final_services,
        service_selected: 0,
        services_loaded,
        services_error: None,
        sandbox_info: cached_sandbox,
        sandbox_selected: 0,
        sandbox_tree_expanded: std::collections::HashSet::new(),
        sandbox_loaded,
        sandbox_error: None,
        selected_optdepends: std::collections::HashMap::new(),
        cascade_mode: app.remove_cascade_mode,
        cached_reverse_deps_report: None,
    };
    tracing::debug!(
        "[Install] Modal state set in {:?}",
        modal_set_start.elapsed()
    );
    tracing::info!(
        "[Install] Preflight modal opened successfully in {:?} ({} packages)",
        start_time.elapsed(),
        item_count
    );
    app.remove_preflight_summary.clear();
}

/// What: Open Preflight modal for remove action.
///
/// Inputs:
/// - `app`: Mutable application state
///
/// Output:
/// - No return value; sets app.modal to Preflight with Remove action
///
/// Details:
/// - Opens modal immediately without blocking. Reverse dependency resolution can be triggered
///   manually via the Dependencies tab or will be computed when user tries to proceed.
///   This avoids blocking the UI when opening the modal.
pub fn open_preflight_remove_modal(app: &mut AppState) {
    let items = app.remove_list.clone();
    let item_count = items.len();

    // Reset cancellation flag when opening modal
    app.preflight_cancelled
        .store(false, std::sync::atomic::Ordering::Relaxed);
    // Queue summary computation in background - modal will render with None initially
    app.preflight_summary_items = Some((items.clone(), crate::state::PreflightAction::Remove));
    // Don't set preflight_summary_resolving=true here - let the tick handler trigger it
    // This prevents the tick handler from being blocked by the flag already being set
    tracing::debug!(
        "[Preflight] Queued summary computation for {} items (remove)",
        items.len()
    );
    app.pending_service_plan.clear();

    // Open modal immediately with empty dependency_info to avoid blocking UI
    // Dependency info can be resolved later via Dependencies tab or when proceeding
    app.modal = crate::state::Modal::Preflight {
        items,
        action: crate::state::PreflightAction::Remove,
        tab: crate::state::PreflightTab::Summary,
        summary: None, // Will be populated when background computation completes
        summary_scroll: 0,
        header_chips: crate::state::modal::PreflightHeaderChips {
            package_count: item_count,
            download_bytes: 0,
            install_delta_bytes: 0,
            aur_count: 0,
            risk_score: 0,
            risk_level: crate::state::modal::RiskLevel::Low,
        },
        dependency_info: Vec::new(), // Will be populated when user switches to Deps tab or proceeds
        dep_selected: 0,
        dep_tree_expanded: std::collections::HashSet::new(),
        deps_error: None,
        file_info: Vec::new(),
        file_selected: 0,
        file_tree_expanded: std::collections::HashSet::new(),
        files_error: None,
        service_info: Vec::new(),
        service_selected: 0,
        services_loaded: false,
        services_error: None,
        sandbox_info: Vec::new(),
        sandbox_selected: 0,
        sandbox_tree_expanded: std::collections::HashSet::new(),
        sandbox_loaded: false,
        sandbox_error: None,
        selected_optdepends: std::collections::HashMap::new(),
        cascade_mode: app.remove_cascade_mode,
        cached_reverse_deps_report: None,
    };
    app.remove_preflight_summary = Vec::new(); // Will be populated when dependencies are resolved
    app.toast_message = Some(crate::i18n::t(app, "app.toasts.preflight_remove_list"));
}

/// What: Open Preflight modal for downgrade action.
///
/// Inputs:
/// - `app`: Mutable application state
///
/// Output:
/// - No return value; sets app.modal to Preflight with Downgrade action
///
/// Details:
/// - Opens modal immediately without blocking. Similar to remove modal, but for downgrade operations.
pub fn open_preflight_downgrade_modal(app: &mut AppState) {
    let items = app.downgrade_list.clone();
    let item_count = items.len();

    // Reset cancellation flag when opening modal
    app.preflight_cancelled
        .store(false, std::sync::atomic::Ordering::Relaxed);
    // Queue summary computation in background - modal will render with None initially
    app.preflight_summary_items = Some((items.clone(), crate::state::PreflightAction::Downgrade));
    // Don't set preflight_summary_resolving=true here - let the tick handler trigger it
    // This prevents the tick handler from being blocked by the flag already being set
    tracing::debug!(
        "[Preflight] Queued summary computation for {} items (downgrade)",
        items.len()
    );
    app.pending_service_plan.clear();

    // Open modal immediately with empty dependency_info to avoid blocking UI
    // Dependency info can be resolved later via Dependencies tab or when proceeding
    app.modal = crate::state::Modal::Preflight {
        items,
        action: crate::state::PreflightAction::Downgrade,
        tab: crate::state::PreflightTab::Summary,
        summary: None, // Will be populated when background computation completes
        summary_scroll: 0,
        header_chips: crate::state::modal::PreflightHeaderChips {
            package_count: item_count,
            download_bytes: 0,
            install_delta_bytes: 0,
            aur_count: 0,
            risk_score: 0,
            risk_level: crate::state::modal::RiskLevel::Low,
        },
        dependency_info: Vec::new(), // Will be populated when user switches to Deps tab or proceeds
        dep_selected: 0,
        dep_tree_expanded: std::collections::HashSet::new(),
        deps_error: None,
        file_info: Vec::new(),
        file_selected: 0,
        file_tree_expanded: std::collections::HashSet::new(),
        files_error: None,
        service_info: Vec::new(),
        service_selected: 0,
        services_loaded: false,
        services_error: None,
        sandbox_info: Vec::new(),
        sandbox_selected: 0,
        sandbox_tree_expanded: std::collections::HashSet::new(),
        sandbox_loaded: false,
        sandbox_error: None,
        selected_optdepends: std::collections::HashMap::new(),
        cascade_mode: app.remove_cascade_mode,
        cached_reverse_deps_report: None,
    };
    app.toast_message = Some(crate::i18n::t(app, "app.toasts.preflight_downgrade_list"));
}