mirror of
https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation.git
synced 2026-08-24 06:24:19 +02:00
Merge pull request #1033 from alouiadel/feat/add-copy-button
feat(ui): add copy button to copy error messages
This commit is contained in:
commit
be03d78ffd
1 changed files with 42 additions and 1 deletions
|
|
@ -63,6 +63,7 @@ pub struct List {
|
|||
export_modal: bool,
|
||||
current_package_index: usize,
|
||||
is_adb_satisfied: bool,
|
||||
copy_confirmation: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -91,6 +92,8 @@ pub enum Message {
|
|||
ExportSelection,
|
||||
SelectionExported(Result<bool, String>),
|
||||
DescriptionEdit(text_editor::Action),
|
||||
CopyError(String),
|
||||
HideCopyConfirmation,
|
||||
}
|
||||
|
||||
pub struct SummaryEntry {
|
||||
|
|
@ -368,6 +371,19 @@ impl List {
|
|||
}
|
||||
Command::none()
|
||||
}
|
||||
Message::CopyError(err) => {
|
||||
self.copy_confirmation = true;
|
||||
Command::batch(vec![
|
||||
iced::clipboard::write::<Message>(err),
|
||||
Command::perform(Self::delay_hide_copy_confirmation(), |_| {
|
||||
Message::HideCopyConfirmation
|
||||
}),
|
||||
])
|
||||
}
|
||||
Message::HideCopyConfirmation => {
|
||||
self.copy_confirmation = false;
|
||||
Command::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -636,7 +652,7 @@ impl List {
|
|||
}
|
||||
|
||||
if let Some(err) = &self.error_modal {
|
||||
error_view(err, content).into()
|
||||
error_view(err, content, self.copy_confirmation).into()
|
||||
} else {
|
||||
container(content).height(Length::Fill).padding(10).into()
|
||||
}
|
||||
|
|
@ -909,11 +925,16 @@ impl List {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn delay_hide_copy_confirmation() {
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
|
||||
fn error_view<'a>(
|
||||
error: &'a str,
|
||||
content: Column<'a, Message, Theme, Renderer>,
|
||||
copy_confirmation: bool,
|
||||
) -> Modal<'a, Message, Theme, Renderer> {
|
||||
let title_ctn = container(
|
||||
row![text("Failed to perform ADB operation").size(24)].align_items(Alignment::Center),
|
||||
|
|
@ -925,6 +946,26 @@ fn error_view<'a>(
|
|||
.center_x();
|
||||
|
||||
let modal_btn_row = row![
|
||||
button(
|
||||
text(if copy_confirmation {
|
||||
"Copied!"
|
||||
} else {
|
||||
"Copy error"
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.horizontal_alignment(alignment::Horizontal::Center),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.on_press_maybe(if copy_confirmation {
|
||||
None
|
||||
} else {
|
||||
Some(Message::CopyError(error.to_string()))
|
||||
})
|
||||
.style(if copy_confirmation {
|
||||
style::Button::Primary
|
||||
} else {
|
||||
style::Button::default()
|
||||
}),
|
||||
button(
|
||||
text("Close")
|
||||
.width(Length::Fill)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue