diff --git a/src/commands/list_folders.rs b/src/commands/list_folders.rs index 05045ec..4b191c5 100644 --- a/src/commands/list_folders.rs +++ b/src/commands/list_folders.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::{collections::HashSet, time::Duration}; use anyhow::{anyhow, ensure, Context, Result}; use thirtyfour::{By, WebDriver, WebElement}; @@ -7,6 +7,26 @@ use tracing::debug; use crate::thirtyfour_util::FindExt; pub async fn list_folders(webdriver: &WebDriver) -> Result> { + tokio::time::timeout(Duration::from_secs(20), async { + loop { + let folders = list_folders_inner(webdriver).await?; + + if folders.is_empty() { + debug!("folders empty, waiting"); + + tokio::time::sleep(Duration::from_millis(100)).await; + } else { + debug!("found folders"); + + return Ok(folders); + } + } + }) + .await + .context("no timeout")? +} + +async fn list_folders_inner(webdriver: &WebDriver) -> Result> { let folder_column = webdriver .find_one(By::ClassName("folder-column")) .await @@ -41,8 +61,5 @@ pub async fn list_folders(webdriver: &WebDriver) -> Result