Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(startup): inform user when ADB isn't installed #343

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/core/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ pub fn adb_shell_command(shell: bool, args: &str) -> Result<String, String> {
Err(e) => {
// TODO: better error handling with anyhow + thiserror
error!("ADB: {}", e);
error!("ADB was not found");
std::process::exit(1);
Err("ADB was not found".to_string())
}
Ok(o) => {
if o.status.success() {
Expand Down Expand Up @@ -331,3 +330,10 @@ pub async fn get_devices_list() -> Vec<Phone> {
)
.unwrap_or_default()
}

pub async fn initial_load() -> bool {
match adb_shell_command(false, "devices") {
Ok(_devices) => true,
Err(_err) => false,
}
}
8 changes: 7 additions & 1 deletion src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod style;
pub mod views;
pub mod widgets;

use crate::core::sync::{get_devices_list, perform_adb_commands, CommandType, Phone};
use crate::core::sync::{get_devices_list, initial_load, perform_adb_commands, CommandType, Phone};
use crate::core::theme::Theme;
use crate::core::uad_lists::UadListState;
use crate::core::update::{get_latest_release, Release, SelfUpdateState, SelfUpdateStatus};
Expand Down Expand Up @@ -69,6 +69,7 @@ pub enum Message {
GetLatestRelease(Result<Option<Release>, ()>),
FontLoaded(Result<(), iced::font::Error>),
Nothing,
ADBSatisfied(bool),
}

impl Application for UadGui {
Expand All @@ -84,6 +85,7 @@ impl Application for UadGui {
// Used in crate::gui::widgets::navigation_menu::ICONS. Name is `icomoon`.
font::load(include_bytes!("../../resources/assets/icons.ttf").as_slice())
.map(Message::FontLoaded),
Command::perform(initial_load(), Message::ADBSatisfied),
Command::perform(get_devices_list(), Message::LoadDevices),
Command::perform(
async move { get_latest_release() },
Expand Down Expand Up @@ -328,6 +330,10 @@ impl Application for UadGui {

Command::none()
}
Message::ADBSatisfied(result) => match result {
true => self.update(Message::AppsAction(AppsMessage::ADBSatisfied(true))),
false => self.update(Message::AppsAction(AppsMessage::ADBSatisfied(false))),
},
Message::Nothing => Command::none(),
}
}
Expand Down
50 changes: 37 additions & 13 deletions src/gui/views/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct List {
description: String,
selection_modal: bool,
current_package_index: usize,
is_adb_satisfied: bool,
}

#[derive(Debug, Clone)]
Expand All @@ -73,6 +74,7 @@ pub enum Message {
ModalHide,
ModalUserSelected(User),
ModalValidate,
ADBSatisfied(bool),
}

pub struct SummaryEntry {
Expand Down Expand Up @@ -289,6 +291,10 @@ impl List {
Message::UserSelected(user),
)
}
Message::ADBSatisfied(result) => {
self.is_adb_satisfied = result;
Command::none()
}
Message::Nothing => Command::none(),
}
}
Expand All @@ -301,21 +307,38 @@ impl List {
match &self.loading_state {
LoadingState::DownloadingList => {
let text = "Downloading latest UAD-ng lists from GitHub. Please wait...";
waiting_view(settings, text, true)
}
LoadingState::FindingPhones => {
waiting_view(settings, "Finding connected devices...", false)
waiting_view(settings, text, true, style::Text::Default)
}
LoadingState::FindingPhones => match self.is_adb_satisfied {
true => waiting_view(
settings,
"Finding connected devices...",
false,
style::Text::Default,
),
false => waiting_view(
settings,
"ADB is not installed in your system, install adb and relaunch application.",
edgy-b marked this conversation as resolved.
Show resolved Hide resolved
false,
style::Text::Danger,
),
},
LoadingState::LoadingPackages => {
let text = "Pulling packages from the device. Please wait...";
waiting_view(settings, text, false)
}
LoadingState::_UpdatingUad => {
waiting_view(settings, "Updating UAD-ng. Please wait...", false)
}
LoadingState::RestoringDevice(device) => {
waiting_view(settings, &format!("Restoring device: {device}"), false)
waiting_view(settings, text, false, style::Text::Default)
}
LoadingState::_UpdatingUad => waiting_view(
settings,
"Updating UAD-ng. Please wait...",
false,
style::Text::Default,
),
LoadingState::RestoringDevice(device) => waiting_view(
settings,
&format!("Restoring device: {device}"),
false,
style::Text::Default,
),
LoadingState::Ready => {
let search_packages = text_input("Search packages...", &self.input_value)
.width(Length::Fill)
Expand Down Expand Up @@ -728,6 +751,7 @@ fn waiting_view<'a>(
_settings: &Settings,
displayed_text: &str,
btn: bool,
text_style: style::Text,
) -> Element<'a, Message, Renderer<Theme>> {
let col = if btn {
let no_internet_btn = button("No internet?")
Expand All @@ -738,13 +762,13 @@ fn waiting_view<'a>(
column![]
.spacing(10)
.align_items(Alignment::Center)
.push(text(displayed_text).size(20))
.push(text(displayed_text).style(text_style).size(20))
.push(no_internet_btn)
} else {
column![]
.spacing(10)
.align_items(Alignment::Center)
.push(text(displayed_text).size(20))
.push(text(displayed_text).style(text_style).size(20))
};

container(col)
Expand Down