Skip to content

Commit

Permalink
#358: Don't wait for input after ui::alert with --force
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Sep 30, 2024
1 parent b2a3b5e commit b2926a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* GUI: Fixed some inconsistent spacing between elements.
* CLI: On Linux, the `wrap` command's `--infer steam` option would fail
to find the `SteamAppId` environment variable due to a case mismatch.
* CLI: In some error conditions, the `wrap` command would show an alert
and wait for the user to press a key, even if `--force` was specified.
Now, with `--force`, Ludusavi will not wait for any input.
* Changed:
* GUI: Updated to the latest version of [Iced](https://github.com/iced-rs/iced).
If the GUI fails to load, Ludusavi will log the error info.
Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
try_manifest_update,
) {
log::error!("WRAP::restore: failed for game {:?} with: {:?}", wrap_game_info, err);
ui::alert_with_error(gui, &TRANSLATOR.restore_one_game_failed(game_name), &err)?;
ui::alert_with_error(gui, force, &TRANSLATOR.restore_one_game_failed(game_name), &err)?;
return Err(err);
}
}
Expand All @@ -939,7 +939,7 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
}
Err(err) => {
log::error!("WRAP::execute: Game command execution failed with: {:#?}", err);
ui::alert_with_raw_error(gui, &TRANSLATOR.game_did_not_launch(), &err.to_string())?;
ui::alert_with_raw_error(gui, force, &TRANSLATOR.game_did_not_launch(), &err.to_string())?;
return Err(Error::GameDidNotLaunch { why: err.to_string() });
}
}
Expand Down Expand Up @@ -979,7 +979,7 @@ pub fn run(sub: Subcommand, no_manifest_update: bool, try_manifest_update: bool)
try_manifest_update,
) {
log::error!("WRAP::backup: failed with: {:#?}", err);
ui::alert_with_error(gui, &TRANSLATOR.back_up_one_game_failed(game_name), &err)?;
ui::alert_with_error(gui, force, &TRANSLATOR.back_up_one_game_failed(game_name), &err)?;
return Err(err);
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/cli/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ fn pause() -> Result<(), Error> {
Ok(())
}

pub fn alert_with_raw_error(gui: bool, msg: &str, error: &str) -> Result<(), Error> {
pub fn alert_with_raw_error(gui: bool, force: bool, msg: &str, error: &str) -> Result<(), Error> {
alert(
gui,
force,
&format!("{}{}{}", msg, get_separator(gui), TRANSLATOR.prefix_error(error)),
)
}

pub fn alert_with_error(gui: bool, msg: &str, error: &Error) -> Result<(), Error> {
pub fn alert_with_error(gui: bool, force: bool, msg: &str, error: &Error) -> Result<(), Error> {
alert(
gui,
force,
&format!("{}{}{}", msg, get_separator(gui), TRANSLATOR.handle_error(error)),
)
}

pub fn alert(gui: bool, msg: &str) -> Result<(), Error> {
log::debug!("Showing alert to user (GUI={}): {}", gui, msg);
pub fn alert(gui: bool, force: bool, msg: &str) -> Result<(), Error> {
log::debug!("Showing alert to user (GUI={}, force={}): {}", gui, force, msg);
if gui {
match native_dialog::MessageDialog::new()
.set_title(&TRANSLATOR.app_name())
Expand All @@ -55,17 +57,19 @@ pub fn alert(gui: bool, msg: &str) -> Result<(), Error> {
Err(Error::CliUnableToRequestConfirmation)
}
}
} else {
} else if !force {
// TODO: Dialoguer doesn't have an alert type.
// https://github.com/console-rs/dialoguer/issues/287
println!("{}", msg);
pause()
} else {
Ok(())
}
}

pub fn confirm_with_question(gui: bool, force: Option<bool>, msg: &str, question: &str) -> Result<bool, Error> {
if let Some(force) = force {
_ = alert(gui, msg);
_ = alert(gui, true, msg);
return Ok(force);
}

Expand Down

0 comments on commit b2926a4

Please sign in to comment.