refactor: update main.rs for async ApiClient creation and use has_token
This commit is contained in:
+13
-6
@@ -35,10 +35,18 @@ fn main() -> io::Result<()> {
|
||||
let backend = CrosstermBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
let api_client = Arc::new(ApiClient::new(
|
||||
std::env::var("GOOGLE_CLIENT_ID").unwrap_or_default(),
|
||||
std::env::var("GOOGLE_CLIENT_SECRET").unwrap_or_default(),
|
||||
));
|
||||
let api_client = Arc::new(
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
ApiClient::new(
|
||||
std::env::var("GOOGLE_CLIENT_ID").unwrap_or_default(),
|
||||
std::env::var("GOOGLE_CLIENT_SECRET").unwrap_or_default(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to create ApiClient")
|
||||
}),
|
||||
);
|
||||
|
||||
let network_status = Arc::new(Mutex::new(NetworkStatus::Online));
|
||||
let (sync_tx, mut sync_rx) = tokio::sync::mpsc::channel::<SyncCommand>(32);
|
||||
@@ -159,8 +167,7 @@ async fn process_sync_queue(
|
||||
api: &Arc<ApiClient>,
|
||||
network_status: &Arc<Mutex<NetworkStatus>>,
|
||||
) {
|
||||
let token_available = api.load_token().await.is_some();
|
||||
if !token_available {
|
||||
if !api.has_token() {
|
||||
*network_status.lock().await = NetworkStatus::Offline;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user