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

hotfix(settings): patch regression and refactor a bit #533

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/core/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct UserBackup {
pub packages: Vec<CorePackage>,
}

// Backup all `Uninstalled` and `Disabled` packages
/// Backup all `Uninstalled` and `Disabled` packages
pub async fn backup_phone(
users: Vec<User>,
device_id: String,
Expand Down
12 changes: 6 additions & 6 deletions src/core/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,9 @@ pub async fn open_folder() -> Result<PathBuf, Error> {
/// Export uninstalled packages in a csv file.
/// Exported information will contain package name and description.
pub async fn export_packages(
user: Option<User>,
user: User,
phone_packages: Vec<Vec<PackageRow>>,
) -> Result<bool, String> {
let uninstalled_packages: Vec<&PackageRow> = phone_packages[user.unwrap().index]
.iter()
.filter(|p| p.state.to_string() == "Uninstalled")
.collect();

let backup_file = format!(
"{}_{}.csv",
UNINSTALLED_PACKAGES_FILE_NAME,
Expand All @@ -191,6 +186,11 @@ pub async fn export_packages(
wtr.write_record(["Package Name", "Description"])
.map_err(|err| err.to_string())?;

let uninstalled_packages: Vec<&PackageRow> = phone_packages[user.index]
.iter()
.filter(|p| p.state == PackageState::Uninstalled)
.collect();

for package in uninstalled_packages {
wtr.write_record([&package.name, &package.description.replace('\n', " ")])
.map_err(|err| err.to_string())?;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl Application for UadGui {
&self.apps_view.phone_packages,
&mut self.nb_running_async_adb_commands,
msg,
&self.apps_view.selected_user,
self.apps_view.selected_user,
)
.map(Message::SettingsAction)
}
Expand Down
44 changes: 22 additions & 22 deletions src/gui/views/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Settings {
packages: &[Vec<PackageRow>],
nb_running_async_adb_commands: &mut u32,
msg: Message,
selected_user: &Option<User>,
selected_user: Option<User>,
) -> Command<Message> {
match msg {
Message::ModalHide => {
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Settings {
}
}
Message::ExportPackages => Command::perform(
export_packages(*selected_user, packages.to_vec()),
export_packages(selected_user.unwrap_or_default(), packages.to_vec()),
Message::PackagesExported,
),
Message::PackagesExported(exported) => {
Expand Down Expand Up @@ -472,33 +472,14 @@ impl Settings {
row![]
};

let export_row = row![
export_btn,
"Export uninstalled packages with their description",
Space::new(Length::Fill, Length::Shrink),
text(format!(
"Selected: user {}",
apps_view.selected_user.unwrap().id
)),
]
.spacing(10)
.align_items(Alignment::Center);

let backup_restore_ctn =
container(column![backup_row, restore_row, export_row].spacing(10))
.padding(10)
.width(Length::Fill)
.height(Length::Shrink)
.style(style::Container::Frame);

let no_device_ctn = || {
container(text("No device detected").style(style::Text::Danger))
.padding(10)
.width(Length::Fill)
.style(style::Container::BorderedFrame)
};

let content = if phone.adb_id.clone().is_empty() {
let content = if phone.adb_id.is_empty() {
column![
text("Theme").size(26),
theme_ctn,
Expand All @@ -512,6 +493,25 @@ impl Settings {
.width(Length::Fill)
.spacing(20)
} else {
let export_row = row![
export_btn,
"Export uninstalled packages with their description",
Space::new(Length::Fill, Length::Shrink),
text(format!(
"Selected: user {}",
apps_view.selected_user.unwrap_or_default().id
)),
]
.spacing(10)
.align_items(Alignment::Center);

let backup_restore_ctn =
container(column![backup_row, restore_row, export_row].spacing(10))
.padding(10)
.width(Length::Fill)
.height(Length::Shrink)
.style(style::Container::Frame);

column![
text("Theme").size(26),
theme_ctn,
Expand Down
Loading