Skip to content

Commit

Permalink
Add launch_configurations and sdk_version component
Browse files Browse the repository at this point in the history
  • Loading branch information
itome committed Apr 14, 2024
1 parent ff8e5ff commit 63b08e4
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ use crate::components::devices::DevicesComponent;
use crate::components::frame_analysis::FrameAnalysisComponent;
use crate::components::frames::FramesComponent;
use crate::components::inspector::InspectorComponent;
use crate::components::launch_configurations::LaunchConfigurationsComponent;
use crate::components::logs::LogsComponent;
use crate::components::network::NetworkComponent;
use crate::components::network_request::NetworkRequestComponent;
use crate::components::performance::PerformanceComponent;
use crate::components::project::ProjectComponent;
use crate::components::pubspec::PubspecComponent;
use crate::components::runners::RunnersComponent;
use crate::components::sdk_version::SdkVersionComponent;
use crate::components::select_device_popup::SelectDevicePopupComponent;
use crate::components::select_launch_configuration_popup::SelectLaunchConfigurationPopupComponent;
use crate::components::select_tab_handler::SelectTabControllerComponent;
Expand Down Expand Up @@ -70,6 +72,8 @@ pub enum ComponentId {
App,
Performance,
Inspector,
LaunchConfigurations,
SdkVersion,
}

pub struct App {
Expand Down Expand Up @@ -165,6 +169,14 @@ impl App {
ComponentId::FrameAnalysis,
Box::new(FrameAnalysisComponent::new()) as Box<dyn Component>,
),
(
ComponentId::LaunchConfigurations,
Box::new(LaunchConfigurationsComponent::new()) as Box<dyn Component>,
),
(
ComponentId::SdkVersion,
Box::new(SdkVersionComponent::new()) as Box<dyn Component>,
),
]),
should_quit: false,
should_suspend: false,
Expand All @@ -186,6 +198,12 @@ impl App {
redux_action_tx.send(ThunkAction::LoadEmulators.into())?;
redux_action_tx.send(ThunkAction::LoadSupportedPlatforms.into())?;
redux_action_tx.send(ThunkAction::LoadVSCodeLaunchSetting.into())?;
redux_action_tx.send(
ThunkAction::LoadSdkVersions {
use_fvm: self.use_fvm,
}
.into(),
)?;

let mut tui = tui::Tui::new()?
.tick_rate(self.tick_rate)
Expand Down Expand Up @@ -336,6 +354,18 @@ impl App {
self.component(&ComponentId::Logs)
.draw(f, horizontal_layout[2], state);
}
} else {
let horizontal_layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Fill(1), Constraint::Fill(1)])
.split(layout[1]);
self.component(&ComponentId::LaunchConfigurations).draw(
f,
horizontal_layout[0],
state,
);
self.component(&ComponentId::SdkVersion)
.draw(f, horizontal_layout[1], state);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ pub mod devices;
pub mod frame_analysis;
pub mod frames;
pub mod inspector;
pub mod launch_configurations;
pub mod logs;
pub mod network;
pub mod network_request;
pub mod performance;
pub mod project;
pub mod pubspec;
pub mod runners;
pub mod sdk_version;
pub mod select_device_popup;
pub mod select_launch_configuration_popup;
pub mod select_tab_handler;
Expand Down
77 changes: 77 additions & 0 deletions src/components/launch_configurations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use std::sync::Arc;

use crossterm::event::{KeyCode, KeyEvent};
use ratatui::prelude::Rect;
use ratatui::{prelude::*, widgets::*};
use redux_rs::Selector;
use tokio::sync::mpsc::UnboundedSender;

use crate::action::TuiAction;
use crate::redux::action::Action;
use crate::redux::selector::selected_device::selected_device_selector;
use crate::redux::state::{Home, PopUp, State};
use crate::redux::thunk::ThunkAction;
use crate::redux::ActionOrThunk;
use crate::tui::Frame;
use color_eyre::eyre::{eyre, Result};
use daemon::flutter::FlutterDaemon;

use super::Component;

#[derive(Default)]
pub struct LaunchConfigurationsComponent {
action_tx: Option<UnboundedSender<ActionOrThunk>>,
}

impl LaunchConfigurationsComponent {
pub fn new() -> Self {
Self::default()
}
}

impl Component for LaunchConfigurationsComponent {
fn draw(&mut self, f: &mut Frame<'_>, area: Rect, state: &State) {
let items = state
.launch_configurations
.iter()
.enumerate()
.flat_map(|(index, config)| {
let mut items = vec![ListItem::new(format!(" {} ", config.name.clone())).bold()];
if let Some(program) = &config.program {
items.push(ListItem::new(Line::from(vec![
Span::from(" Program ").style(Style::default().fg(Color::Yellow)),
Span::from(program),
])));
}
if let Some(mode) = &config.flutter_mode {
items.push(ListItem::new(Line::from(vec![
Span::from(" Mode ").style(Style::default().fg(Color::Yellow)),
Span::from(mode),
])));
}
if let Some(cwd) = &config.cwd {
items.push(ListItem::new(Line::from(vec![
Span::from(" Directory ").style(Style::default().fg(Color::Yellow)),
Span::from(cwd),
])));
}
if let Some(args) = &config.args {
items.push(ListItem::new(Line::from(vec![
Span::from(" Args ").style(Style::default().fg(Color::Yellow)),
Span::from(args.join(" ")),
])));
}
items
})
.collect::<Vec<_>>();

let block = Block::default()
.title("Launch configurations (from .vscode/launch.json)")
.borders(Borders::ALL)
.border_type(BorderType::Rounded);

let list = List::new(items).block(block);

f.render_widget(list, area);
}
}
88 changes: 88 additions & 0 deletions src/components/sdk_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use std::sync::Arc;

use crossterm::event::{KeyCode, KeyEvent};
use ratatui::prelude::Rect;
use ratatui::{prelude::*, widgets::*};
use redux_rs::Selector;
use tokio::sync::mpsc::UnboundedSender;

use crate::action::TuiAction;
use crate::redux::action::Action;
use crate::redux::selector::selected_device::selected_device_selector;
use crate::redux::state::{Home, PopUp, State};
use crate::redux::thunk::ThunkAction;
use crate::redux::ActionOrThunk;
use crate::tui::Frame;
use color_eyre::eyre::{eyre, Result};
use daemon::flutter::FlutterDaemon;

use super::Component;

#[derive(Default)]
pub struct SdkVersionComponent {}

impl SdkVersionComponent {
pub fn new() -> Self {
Self::default()
}
}

impl Component for SdkVersionComponent {
fn draw(&mut self, f: &mut Frame<'_>, area: Rect, state: &State) {
let block = Block::default()
.title("SDK Version")
.borders(Borders::ALL)
.padding(Padding::horizontal(1))
.border_type(BorderType::Rounded);

let Some(version) = state.sdk_version.as_ref() else {
f.render_widget(block.clone(), area);
return;
};

let widths = [Constraint::Length(21), Constraint::Fill(1)];

let rows = vec![
Row::new(vec![
Cell::from("Flutter Version").style(Style::default().fg(Color::Yellow)),
Cell::from(version.flutter_version.clone()),
]),
Row::new(vec![
Cell::from("Framework Version").style(Style::default().fg(Color::Yellow)),
Cell::from(version.framework_version.clone()),
]),
Row::new(vec![
Cell::from("Channel").style(Style::default().fg(Color::Yellow)),
Cell::from(version.channel.clone()),
]),
Row::new(vec![
Cell::from("Repository URL").style(Style::default().fg(Color::Yellow)),
Cell::from(version.repository_url.clone()),
]),
Row::new(vec![
Cell::from("Framework Revision").style(Style::default().fg(Color::Yellow)),
Cell::from(version.framework_revision.clone()),
]),
Row::new(vec![
Cell::from("Framework Commit Date").style(Style::default().fg(Color::Yellow)),
Cell::from(version.framework_commit_date.clone()),
]),
Row::new(vec![
Cell::from("Engine Revision").style(Style::default().fg(Color::Yellow)),
Cell::from(version.engine_revision.clone()),
]),
Row::new(vec![
Cell::from("Dart SDK Version").style(Style::default().fg(Color::Yellow)),
Cell::from(version.dart_sdk_version.clone()),
]),
Row::new(vec![
Cell::from("Flutter Root").style(Style::default().fg(Color::Yellow)),
Cell::from(version.flutter_root.clone()),
]),
];

let table = Table::new(rows, widths).block(block);

f.render_widget(table, area);
}
}
13 changes: 13 additions & 0 deletions src/redux/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ use std::time::Duration;

#[derive(Debug)]
pub enum Action {
SetSdkVersion {
framework_version: String,
channel: String,
repository_url: String,
framework_revision: String,
framework_commit_date: String,
engine_revision: String,
dart_sdk_version: String,
dev_tools_version: String,
flutter_version: String,
flutter_root: String,
},

AddDevice {
device: Device,
},
Expand Down
29 changes: 28 additions & 1 deletion src/redux/reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,39 @@ use super::{
selected_device::{self, selected_device_selector},
},
state::{
DevTools, FlutterFrame, Home, SelectLaunchConfigurationPopupState, SessionState, State,
DevTools, FlutterFrame, Home, SdkVersion, SelectLaunchConfigurationPopupState,
SessionState, State,
},
};

pub fn reducer(state: State, action: Action) -> State {
match action {
Action::SetSdkVersion {
framework_version,
channel,
repository_url,
framework_revision,
framework_commit_date,
engine_revision,
dart_sdk_version,
dev_tools_version,
flutter_version,
flutter_root,
} => State {
sdk_version: Some(SdkVersion {
framework_version,
channel,
repository_url,
framework_revision,
framework_commit_date,
engine_revision,
dart_sdk_version,
dev_tools_version,
flutter_version,
flutter_root,
}),
..state
},
Action::AddDevice { device } => {
let mut new_state = State {
devices: [state.devices, vec![device.clone()]].concat(),
Expand Down
16 changes: 16 additions & 0 deletions src/redux/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ impl Default for Focus {
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct SdkVersion {
pub framework_version: String,
pub channel: String,
pub repository_url: String,
pub framework_revision: String,
pub framework_commit_date: String,
pub engine_revision: String,
pub dart_sdk_version: String,
pub dev_tools_version: String,
pub flutter_version: String,
pub flutter_root: String,
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct LaunchConfiguration {
pub name: String,
Expand Down Expand Up @@ -111,6 +125,8 @@ pub struct State {
pub focus: Focus,
pub popup: Option<PopUp>,

pub sdk_version: Option<SdkVersion>,

pub project_root: PathBuf,
pub devices: Vec<Device>,
pub emulators: Vec<Emulator>,
Expand Down
5 changes: 5 additions & 0 deletions src/redux/thunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod launch_emulator;
pub mod load_emulators;
pub mod load_full_request;
pub mod load_root_widget_summary_tree;
pub mod load_sdk_versions;
pub mod load_supported_platforms;
pub mod load_vscode_launch_setting;
pub mod run_new_app;
Expand All @@ -25,6 +26,7 @@ pub mod watch_requests;
#[derive(Debug)]
pub enum ThunkAction {
WatchDevices,
LoadSdkVersions { use_fvm: bool },
LoadSupportedPlatforms,
LoadEmulators,
LoadFullRequest,
Expand All @@ -47,6 +49,9 @@ where
match action {
ThunkAction::WatchDevices => Box::new(watch_devices::WatchDevicesThunk::new(context)),
ThunkAction::LoadEmulators => Box::new(load_emulators::LoadEmulatorsThunk::new(context)),
ThunkAction::LoadSdkVersions { use_fvm } => Box::new(
load_sdk_versions::LoadSdkVersionsThunk::new(context, use_fvm),
),
ThunkAction::LoadVSCodeLaunchSetting => {
Box::new(load_vscode_launch_setting::LoadVSCodeLaunchSettingThunk::new(context))
}
Expand Down
Loading

0 comments on commit 63b08e4

Please sign in to comment.