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;
pub use auto_abort_join_handle::AutoAbortJoinHandle;
mod confirm;
pub use confirm::Confirmer;
mod ui_thread;
pub use ui_thread::UIThread;
mod extracter;
mod readable_rx;

View file

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

View file

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