Rename Confirmer to UIThread

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-10 13:45:20 +10:00
parent 9349fbabdc
commit 88c3f15b3f
No known key found for this signature in database
GPG key ID: 591C0B03040416D6
3 changed files with 16 additions and 16 deletions

View file

@ -19,8 +19,8 @@ pub use async_extracter::extract_archive_stream;
mod auto_abort_join_handle; mod auto_abort_join_handle;
pub use auto_abort_join_handle::AutoAbortJoinHandle; pub use auto_abort_join_handle::AutoAbortJoinHandle;
mod confirm; mod ui_thread;
pub use confirm::Confirmer; pub use ui_thread::UIThread;
mod extracter; mod extracter;
mod readable_rx; mod readable_rx;

View file

@ -6,7 +6,7 @@ use tokio::task::spawn_blocking;
use crate::BinstallError; use crate::BinstallError;
#[derive(Debug)] #[derive(Debug)]
struct ConfirmerInner { struct UIThreadInner {
/// Request for confirmation /// Request for confirmation
request_tx: mpsc::Sender<()>, request_tx: mpsc::Sender<()>,
@ -14,7 +14,7 @@ struct ConfirmerInner {
confirm_rx: mpsc::Receiver<Result<(), BinstallError>>, confirm_rx: mpsc::Receiver<Result<(), BinstallError>>,
} }
impl ConfirmerInner { impl UIThreadInner {
fn new() -> Self { fn new() -> Self {
let (request_tx, mut request_rx) = mpsc::channel(1); let (request_tx, mut request_rx) = mpsc::channel(1);
let (confirm_tx, confirm_rx) = mpsc::channel(10); let (confirm_tx, confirm_rx) = mpsc::channel(10);
@ -75,13 +75,13 @@ impl ConfirmerInner {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Confirmer(Option<ConfirmerInner>); pub struct UIThread(Option<UIThreadInner>);
impl Confirmer { impl UIThread {
/// * `enable` - `true` to enable confirmation, `false` to disable it. /// * `enable` - `true` to enable confirmation, `false` to disable it.
pub fn new(enable: bool) -> Self { pub fn new(enable: bool) -> Self {
Self(if enable { Self(if enable {
Some(ConfirmerInner::new()) Some(UIThreadInner::new())
} else { } else {
None None
}) })

View file

@ -191,7 +191,7 @@ async fn entry() -> Result<()> {
) )
.unwrap(); .unwrap();
let mut confirmer = Confirmer::new(!opts.no_confirm); let mut uithread = UIThread::new(!opts.no_confirm);
// Compute install directory // Compute install directory
let install_path = get_install_path(opts.install_path.as_deref()).ok_or_else(|| { let install_path = get_install_path(opts.install_path.as_deref()).ok_or_else(|| {
@ -231,7 +231,7 @@ async fn entry() -> Result<()> {
); );
if !opts.dry_run { if !opts.dry_run {
confirmer.confirm().await?; uithread.confirm().await?;
} }
} }
@ -305,7 +305,7 @@ async fn entry() -> Result<()> {
opts, opts,
package, package,
temp_dir, temp_dir,
&mut confirmer, &mut uithread,
) )
.await .await
} }
@ -320,7 +320,7 @@ async fn entry() -> Result<()> {
.first() .first()
.ok_or_else(|| miette!("No viable targets found, try with `--targets`"))?; .ok_or_else(|| miette!("No viable targets found, try with `--targets`"))?;
install_from_source(opts, package, target, &mut confirmer).await install_from_source(opts, package, target, &mut uithread).await
} }
} }
} }
@ -334,7 +334,7 @@ async fn install_from_package(
opts: Options, opts: Options,
package: Package<Meta>, package: Package<Meta>,
temp_dir: TempDir, temp_dir: TempDir,
confirmer: &mut Confirmer, uithread: &mut UIThread,
) -> Result<()> { ) -> Result<()> {
// Prompt user for third-party source // Prompt user for third-party source
if fetcher.is_third_party() { if fetcher.is_third_party() {
@ -343,7 +343,7 @@ async fn install_from_package(
fetcher.source_name() fetcher.source_name()
); );
if !opts.dry_run { if !opts.dry_run {
confirmer.confirm().await?; uithread.confirm().await?;
} }
} else { } else {
info!( info!(
@ -433,7 +433,7 @@ async fn install_from_package(
return Ok(()); return Ok(());
} }
confirmer.confirm().await?; uithread.confirm().await?;
info!("Installing binaries..."); info!("Installing binaries...");
for file in &bin_files { for file in &bin_files {
@ -462,12 +462,12 @@ async fn install_from_source(
opts: Options, opts: Options,
package: Package<Meta>, package: Package<Meta>,
target: &str, target: &str,
confirmer: &mut Confirmer, uithread: &mut UIThread,
) -> Result<()> { ) -> Result<()> {
// Prompt user for source install // Prompt user for source install
warn!("The package will be installed from source (with cargo)",); warn!("The package will be installed from source (with cargo)",);
if !opts.dry_run { if !opts.dry_run {
confirmer.confirm().await?; uithread.confirm().await?;
} }
if opts.dry_run { if opts.dry_run {