Skip to content

Commit 2a87bb7

Browse files
authored
Merge pull request #2 from wasabeef/feat-adk-installer
2 parents d4b4920 + 0528c90 commit 2a87bb7

34 files changed

Lines changed: 4115 additions & 718 deletions

CLAUDE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The `DeviceManager` trait (in `managers/common.rs`) provides a unified interface
5252
- Device type selection (iPhone, iPad models)
5353
- Runtime version selection
5454
- Basic device operations with status monitoring
55+
- Automatic Simulator.app lifecycle management (opens on start, quits when last device stops)
5556

5657
### User Interface
5758
- **Three-panel layout**: Android devices (30%) | iOS devices (30%) | Device details (40%)
@@ -153,6 +154,12 @@ cargo test startup_performance_test -- --nocapture
153154
- ✅ Device details with MB units and full paths
154155
- ✅ Comprehensive test suite
155156
- ✅ Operation status tracking and notifications
157+
- ✅ API level management with real-time installation
158+
- ✅ Device creation cache system (5-minute expiration)
159+
- ✅ Modular constants architecture (`src/constants/`)
160+
- ✅ Form validation framework (`src/utils/validation.rs`)
161+
- ✅ Enhanced command execution utilities with retry and error ignoring
162+
- ✅ iOS Simulator.app automatic lifecycle management
156163

157164
### Known Issues & Limitations
158165
- **Android state detection**: Occasional inaccuracy in AVD name to emulator serial mapping (improved but not perfect)
@@ -189,6 +196,18 @@ cargo test startup_performance_test -- --nocapture
189196
- `src/models/error.rs` - Error types and user-friendly formatting
190197
- `src/models/platform.rs` - Platform enums and device configurations
191198

199+
### Constants & Utilities
200+
- `src/constants/` - Modular constants system
201+
- `commands.rs` - CLI tool names and arguments
202+
- `defaults.rs` - Default values and configurations
203+
- `env_vars.rs` - Environment variable names
204+
- `files.rs` - File paths and extensions
205+
- `messages.rs` - User-facing strings
206+
- `patterns.rs` - Regular expressions
207+
- `performance.rs` - Performance tuning parameters
208+
- `src/utils/validation.rs` - Form field validation framework
209+
- `src/utils/command.rs` - Enhanced command execution with retry and error handling
210+
192211
## Code Conventions
193212

194213
### Error Handling

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ https://github.com/user-attachments/assets/0ff745ce-7329-4af8-b529-6c5b30d3c48e
1515
- Support for Phone, Tablet, TV, Wear OS, Automotive, Desktop device types
1616
- Advanced configuration: RAM (512MB-8GB), Storage (1GB-64GB)
1717
- Automatic placeholder naming (e.g., "Pixel 9 Pro Fold API 36")
18+
- Real-time system image installation with progress tracking
1819
- 🍎 **iOS Simulator Management** (macOS only): Manage simulators via `xcrun simctl`
1920
- Device type selection (iPhone, iPad models)
2021
- Runtime version selection with dynamic detection
@@ -28,6 +29,7 @@ https://github.com/user-attachments/assets/0ff745ce-7329-4af8-b529-6c5b30d3c48e
2829
- 🔍 **Comprehensive Details**: Device specifications, status, RAM/Storage in MB, full paths
2930
- 🧠 **Smart Caching**: Platform-aware cache invalidation and background loading
3031
- 📝 **Robust Testing**: 15 test files with 31+ test functions ensuring reliability
32+
- 📦 **API Level Management**: Install/uninstall system images directly from TUI
3133

3234
## Installation
3335

@@ -72,6 +74,7 @@ emu --debug
7274
| `j`/`k` | Navigate devices (vim-style) |
7375
| `Enter` | Start/Stop device |
7476
| `c` | Create new device |
77+
| `i` | Manage API levels (Android) |
7578
| `d` | Delete device |
7679
| `w` | Wipe device |
7780
| `r` | Refresh |

docs/ARCHITECTURE.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ pub struct AppState {
8484
pub active_panel: Panel,
8585
pub selected_android: usize,
8686
pub selected_ios: usize,
87+
pub mode: Mode,
88+
89+
// API Level Management (New in v2.0)
90+
pub api_level_management: Option<ApiLevelManagementState>,
8791

8892
// Background operations
8993
pub is_loading: bool,
@@ -96,6 +100,11 @@ pub struct AppState {
96100
// Logging and notifications
97101
pub device_logs: VecDeque<LogEntry>,
98102
pub notifications: VecDeque<Notification>,
103+
104+
// Dialogs
105+
pub create_device_form: CreateDeviceForm,
106+
pub confirm_delete_dialog: Option<ConfirmDeleteDialog>,
107+
pub confirm_wipe_dialog: Option<ConfirmWipeDialog>,
99108
}
100109
```
101110

@@ -179,7 +188,27 @@ impl DeviceManager for IosManager {
179188
- Easy testing with mock implementations
180189
- Clear separation of platform-specific logic
181190

182-
### 2. Async State Management
191+
### 2. API Level Management System (New)
192+
193+
**Purpose**: Dynamic system image management for Android devices.
194+
195+
```rust
196+
pub struct ApiLevelManagementState {
197+
pub api_levels: Vec<ApiLevel>,
198+
pub selected_index: usize,
199+
pub is_loading: bool,
200+
pub install_progress: Option<InstallProgress>,
201+
pub scroll_offset: usize,
202+
}
203+
```
204+
205+
**Features**:
206+
- Real-time installation progress tracking
207+
- Scrollable UI with keyboard navigation
208+
- Automatic cache invalidation on changes
209+
- Background installation with progress callbacks
210+
211+
### 3. Async State Management
183212

184213
**Purpose**: Provide thread-safe state access with non-blocking operations.
185214

@@ -312,7 +341,7 @@ App::new() → tokio::spawn() → list_devices() → state.devices = ... → ren
312341
1. **Immediate UI Rendering**: Show interface within ~50ms
313342
2. **Background Data Loading**: Load device lists asynchronously
314343
3. **Progressive Enhancement**: Add features as data becomes available
315-
4. **Cache Utilization**: Use cached data when available
344+
4. **Cache Preloading**: Preload device types and API levels at startup
316345
5. **Target Performance**: Startup time < 150ms (typical: ~104ms)
317346

318347
### Runtime Optimization
@@ -466,4 +495,44 @@ async fn test_startup_performance() {
466495
- **predicates**: Complex assertion conditions
467496
- **Custom Assertions**: Domain-specific test helpers
468497

498+
## New Features in v2.0
499+
500+
### API Level Management
501+
- **Dynamic System Image Discovery**: Real-time detection of available system images
502+
- **Installation Progress Tracking**: Live progress updates during installation
503+
- **Smart Cache Invalidation**: Automatic cache refresh on system image changes
504+
- **Architecture Detection**: Automatic selection of optimal architecture (x86_64/arm64)
505+
506+
### Enhanced Caching System
507+
- **Device Creation Cache**: Pre-loaded device types and API levels
508+
- **Background Refresh**: Automatic cache updates without blocking UI
509+
- **Context-Aware Invalidation**: Cache cleared on relevant operations
510+
511+
### Improved User Experience
512+
- **Scrollable Dialogs**: Better handling of long lists
513+
- **Loading Indicators**: Clear feedback during async operations
514+
- **Keyboard Navigation**: Circular navigation in device lists
515+
- **Real-time Status Updates**: Live device status monitoring
516+
517+
### iOS Simulator Integration
518+
- **Automatic App Lifecycle**: Simulator.app opens automatically when starting devices
519+
- **Smart Cleanup**: Simulator.app quits automatically when last device stops
520+
- **Graceful Shutdown**: Uses AppleScript for clean app termination with fallback
521+
- **Dock Management**: Prevents Simulator.app icon from lingering in Dock
522+
523+
## Constants Architecture
524+
525+
The application uses a modular constants system (`constants/`):
526+
527+
```
528+
constants/
529+
├── commands.rs # CLI tool names and arguments
530+
├── defaults.rs # Default values and configurations
531+
├── env_vars.rs # Environment variable names
532+
├── files.rs # File paths and extensions
533+
├── messages.rs # User-facing strings and messages
534+
├── patterns.rs # Regular expressions for parsing
535+
└── performance.rs # Performance tuning parameters
536+
```
537+
469538
This architecture provides a solid foundation for building a responsive, maintainable, and cross-platform terminal application while ensuring reliability through comprehensive testing.

docs/DEVELOPMENT.md

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ src/
135135
│ ├── command.rs # Command execution
136136
│ ├── logger.rs # Logging utilities
137137
│ └── mod.rs # Module exports
138-
├── constants.rs # Application constants
138+
├── constants/ # Modular constants system
139+
│ ├── mod.rs # Module exports
140+
│ ├── commands.rs # CLI tool names and arguments
141+
│ ├── defaults.rs # Default values and configurations
142+
│ ├── env_vars.rs # Environment variable names
143+
│ ├── files.rs # File paths and extensions
144+
│ ├── messages.rs # User-facing strings
145+
│ ├── patterns.rs # Regular expressions
146+
│ └── performance.rs # Performance tuning parameters
139147
├── lib.rs # Library root
140148
└── main.rs # Application entry point
141149
```
@@ -653,6 +661,128 @@ cargo publish
653661
2. **Monitor issues**: Watch for bug reports
654662
3. **Plan next release**: Update development roadmap
655663

664+
## Constants Architecture
665+
666+
### Overview
667+
The application uses a modular constants system to eliminate hardcoded strings and improve maintainability. Constants are organized by category in the `src/constants/` directory.
668+
669+
### Module Structure
670+
671+
```rust
672+
// src/constants/mod.rs - Public API
673+
pub mod commands;
674+
pub mod defaults;
675+
pub mod env_vars;
676+
pub mod files;
677+
pub mod messages;
678+
pub mod patterns;
679+
pub mod performance;
680+
681+
// Usage example
682+
use crate::constants::{
683+
commands::ANDROID_COMMANDS,
684+
defaults::DEFAULT_RAM_SIZE,
685+
messages::MSG_DEVICE_CREATED,
686+
};
687+
```
688+
689+
### Categories
690+
691+
#### Commands (`commands.rs`)
692+
- CLI tool names and paths
693+
- Command arguments
694+
- Platform-specific commands
695+
696+
```rust
697+
pub const ADB: &str = "adb";
698+
pub const EMULATOR: &str = "emulator";
699+
pub const AVDMANAGER: &str = "avdmanager";
700+
```
701+
702+
#### Defaults (`defaults.rs`)
703+
- Default configuration values
704+
- UI dimensions
705+
- Resource limits
706+
707+
```rust
708+
pub const DEFAULT_RAM_SIZE: u32 = 2048; // MB
709+
pub const DEFAULT_STORAGE_SIZE: u32 = 8192; // MB
710+
pub const MAX_LOG_ENTRIES: usize = 1000;
711+
```
712+
713+
#### Environment Variables (`env_vars.rs`)
714+
- System environment variable names
715+
- Configuration paths
716+
717+
```rust
718+
pub const ANDROID_HOME: &str = "ANDROID_HOME";
719+
pub const RUST_LOG: &str = "RUST_LOG";
720+
```
721+
722+
#### Files (`files.rs`)
723+
- File paths and extensions
724+
- Configuration file names
725+
726+
```rust
727+
pub const AVD_CONFIG_FILE: &str = "config.ini";
728+
pub const HARDWARE_QEMU_INI: &str = "hardware-qemu.ini";
729+
```
730+
731+
#### Messages (`messages.rs`)
732+
- User-facing strings
733+
- Error messages
734+
- Status notifications
735+
736+
```rust
737+
pub const MSG_DEVICE_CREATED: &str = "Device created successfully";
738+
pub const MSG_LOADING_DEVICES: &str = "Loading devices...";
739+
```
740+
741+
#### Patterns (`patterns.rs`)
742+
- Regular expressions
743+
- Parsing patterns
744+
745+
```rust
746+
pub const DEVICE_NAME_PATTERN: &str = r"^[a-zA-Z0-9_.-]+$";
747+
pub const API_LEVEL_PATTERN: &str = r"API (\d+)";
748+
```
749+
750+
#### Performance (`performance.rs`)
751+
- Timing constants
752+
- Debounce delays
753+
- Cache durations
754+
755+
```rust
756+
pub const STARTUP_MAX_TIME_MS: u64 = 150;
757+
pub const UI_DEBOUNCE_MS: u64 = 50;
758+
pub const CACHE_EXPIRY_SECS: u64 = 300; // 5 minutes
759+
```
760+
761+
### Best Practices
762+
763+
1. **Naming Convention**: Use SCREAMING_SNAKE_CASE for constants
764+
2. **Documentation**: Add doc comments explaining usage
765+
3. **Organization**: Group related constants together
766+
4. **Type Safety**: Use appropriate types (not just `&str`)
767+
5. **Visibility**: Only export what's needed
768+
769+
### Adding New Constants
770+
771+
1. Determine the appropriate module based on category
772+
2. Add the constant with documentation
773+
3. Update module exports if needed
774+
4. Replace hardcoded values throughout codebase
775+
776+
Example:
777+
```rust
778+
// In messages.rs
779+
/// Message shown when device deletion is confirmed
780+
pub const MSG_DEVICE_DELETED: &str = "Device deleted successfully";
781+
782+
// Usage
783+
state.add_notification(MSG_DEVICE_DELETED, NotificationType::Success);
784+
```
785+
656786
## Best Practices Summary
657787

658788
### Code Quality

0 commit comments

Comments
 (0)