From 30cca0ee0046b4205c9ac9d725a62df3cd68ec05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sverre=20Johann=20Bj=C3=B8rke?= Date: Sat, 17 Feb 2024 00:34:48 +0100 Subject: [PATCH] fixed a bug when no ETA --- src/food/mod.rs | 20 +++++++++++++------- src/food/server.rs | 6 ++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/food/mod.rs b/src/food/mod.rs index a73f30b..4043ace 100644 --- a/src/food/mod.rs +++ b/src/food/mod.rs @@ -5,7 +5,7 @@ use crate::ui::*; use chrono::Local; use log::{error, info}; use reqwest::Url; -use slint::Weak; +use slint::{SharedString, Weak}; use std::sync::mpsc::{self, Receiver, TryRecvError}; use std::thread; use tokio::runtime::Runtime; @@ -28,13 +28,12 @@ pub fn setup(main_window: &MainWindow) { } async fn food_worker_loop(window: Weak, rx: Receiver) { - let mut current_url: Option = None; + let mut current_url = None; let mut current_tracking = FoodTracking::default(); loop { match rx.try_recv() { Ok(tracking_url) => { - //TODO: Use logging instead of println info!("Got new tracking url: {}", tracking_url); current_url = Some(tracking_url); } @@ -49,12 +48,19 @@ async fn food_worker_loop(window: Weak, rx: Receiver) { current_tracking = match tracking_response { Ok(tracking_response) => { - let remaining_time = - ((tracking_response.delivery_eta.unwrap()) - Local::now()).num_minutes(); + let minutes_remaining: SharedString = match tracking_response.delivery_eta { + Some(eta) => ((eta) - Local::now()).num_minutes().to_string().into(), + None => "ukjent antall".into(), + }; + + let active = tracking_response.status != "delivered"; + if !active { + current_url = None; + } FoodTracking { resturant_name: tracking_response.from_location.name.en.into(), - minutes_remaining: remaining_time.to_string().into(), - active: tracking_response.status != "delivered", + minutes_remaining, + active, } } Err(e) => { diff --git a/src/food/server.rs b/src/food/server.rs index 69e9a5d..8c32533 100644 --- a/src/food/server.rs +++ b/src/food/server.rs @@ -4,10 +4,8 @@ use reqwest::Url; use serde::Deserialize; use tide::Request; -// const WOLT_TRACKING_URL: &str = -// "https://consumer-api.wolt.com/order-tracking-api/v1/details/tracking-code/track/"; - -const WOLT_TRACKING_URL: &str = "http://localhost:9000/"; +const WOLT_TRACKING_URL: &str = + "https://consumer-api.wolt.com/order-tracking-api/v1/details/tracking-code/track/"; pub async fn food_endpoint_server(tx: Sender) -> tide::Result<()> { let mut app = tide::new();