Skip to content

Commit

Permalink
Show progress bar on all screens
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jul 26, 2020
1 parent f702071 commit 84f765b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* When a game has registry data to back up, registry.yaml no longer includes
unnecessary fields and is now sorted alphabetically. This means that identical
registry content will produce an identical registry.yaml across backups.
* The progress bar is now shown on all screens.

## v0.4.0 (2020-07-21)

Expand Down
64 changes: 28 additions & 36 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct App {
restore_screen: RestoreScreenComponent,
custom_games_screen: CustomGamesScreenComponent,
operation_should_cancel: std::sync::Arc<std::sync::atomic::AtomicBool>,
progress: DisappearingProgress,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -916,7 +917,7 @@ struct DisappearingProgress {
impl DisappearingProgress {
fn view(&mut self) -> ProgressBar {
let visible = self.current > 0.0 && self.current < self.max;
ProgressBar::new(0.0..=self.max, self.current).height(Length::FillPortion(if visible { 200 } else { 1 }))
ProgressBar::new(0.0..=self.max, self.current).height(Length::FillPortion(if visible { 100 } else { 1 }))
}

fn complete(&self) -> bool {
Expand All @@ -936,7 +937,6 @@ struct BackupScreenComponent {
backup_target_history: TextHistory,
backup_target_browse_button: button::State,
root_editor: RootEditor,
progress: DisappearingProgress,
}

impl BackupScreenComponent {
Expand Down Expand Up @@ -1077,12 +1077,7 @@ impl BackupScreenComponent {
)
.push(self.root_editor.view(&config, &translator, &operation))
.push(Space::new(Length::Units(0), Length::Units(30)))
.push(
self.log
.view(false, translator, &config)
.height(Length::FillPortion(10_000)),
)
.push(self.progress.view()),
.push(self.log.view(false, translator, &config)),
)
.height(Length::Fill)
.width(Length::Fill)
Expand All @@ -1102,7 +1097,6 @@ struct RestoreScreenComponent {
restore_source_history: TextHistory,
restore_source_browse_button: button::State,
redirect_editor: RedirectEditor,
progress: DisappearingProgress,
}

impl RestoreScreenComponent {
Expand Down Expand Up @@ -1245,12 +1239,7 @@ impl RestoreScreenComponent {
)
.push(self.redirect_editor.view(&config, &translator, &operation))
.push(Space::new(Length::Units(0), Length::Units(30)))
.push(
self.log
.view(true, translator, &config)
.height(Length::FillPortion(10_000)),
)
.push(self.progress.view()),
.push(self.log.view(true, translator, &config)),
)
.height(Length::Fill)
.width(Length::Fill)
Expand Down Expand Up @@ -1360,10 +1349,8 @@ impl Application for App {
Message::Idle => {
self.operation = None;
self.modal_theme = None;
self.backup_screen.progress.current = 0.0;
self.backup_screen.progress.max = 0.0;
self.restore_screen.progress.current = 0.0;
self.restore_screen.progress.max = 0.0;
self.progress.current = 0.0;
self.progress.max = 0.0;
self.operation_should_cancel
.swap(false, std::sync::atomic::Ordering::Relaxed);
Command::none()
Expand Down Expand Up @@ -1398,8 +1385,8 @@ impl Application for App {
self.backup_screen.status.clear();
self.backup_screen.log.entries.clear();
self.modal_theme = None;
self.backup_screen.progress.current = 0.0;
self.backup_screen.progress.max = all_games.len() as f32;
self.progress.current = 0.0;
self.progress.max = all_games.len() as f32;

self.operation = Some(if preview {
OngoingOperation::PreviewBackup
Expand Down Expand Up @@ -1484,8 +1471,8 @@ impl Application for App {
} else {
OngoingOperation::Restore
});
self.restore_screen.progress.current = 0.0;
self.restore_screen.progress.max = restorables.len() as f32;
self.progress.current = 0.0;
self.progress.max = restorables.len() as f32;

let mut commands: Vec<Command<Message>> = vec![];
for (name, subdir) in restorables {
Expand Down Expand Up @@ -1527,7 +1514,7 @@ impl Application for App {
backup_info,
decision,
} => {
self.backup_screen.progress.current += 1.0;
self.progress.current += 1.0;
if let Some(scan_info) = scan_info {
if scan_info.found_anything() {
self.backup_screen.status.add_game(
Expand All @@ -1542,7 +1529,7 @@ impl Application for App {
});
}
}
if self.backup_screen.progress.complete() {
if self.progress.complete() {
Command::perform(async move {}, move |_| Message::BackupComplete)
} else {
Command::none()
Expand All @@ -1553,7 +1540,7 @@ impl Application for App {
backup_info,
decision,
} => {
self.restore_screen.progress.current += 1.0;
self.progress.current += 1.0;
if let Some(scan_info) = scan_info {
if scan_info.found_anything() {
self.restore_screen.status.add_game(
Expand All @@ -1568,7 +1555,7 @@ impl Application for App {
});
}
}
if self.restore_screen.progress.complete() {
if self.progress.complete() {
Command::perform(async move {}, move |_| Message::RestoreComplete)
} else {
Command::none()
Expand Down Expand Up @@ -2039,15 +2026,20 @@ impl Application for App {
}),
),
)
.push(match self.screen {
Screen::Backup => self.backup_screen.view(&self.config, &self.translator, &self.operation),
Screen::Restore => self
.restore_screen
.view(&self.config, &self.translator, &self.operation),
Screen::CustomGames => self
.custom_games_screen
.view(&self.config, &self.translator, &self.operation),
})
.push(
match self.screen {
Screen::Backup => self.backup_screen.view(&self.config, &self.translator, &self.operation),
Screen::Restore => self
.restore_screen
.view(&self.config, &self.translator, &self.operation),
Screen::CustomGames => {
self.custom_games_screen
.view(&self.config, &self.translator, &self.operation)
}
}
.height(Length::FillPortion(10_000)),
)
.push(self.progress.view())
.into()
}
}
Expand Down
1 change: 1 addition & 0 deletions src/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Serialize, Serializer};
use std::collections::{BTreeMap, HashMap, HashSet};

#[allow(dead_code)]
pub fn ordered_map<S, V>(value: &HashMap<String, V>, serializer: S) -> Result<S::Ok, S::Error>
where
V: Serialize,
Expand Down

0 comments on commit 84f765b

Please sign in to comment.