Compare commits
No commits in common. "02b129fb84e4423268b9c211b293b24a29869442" and "b7ca6d9b2705bc667f806156d4e88fb55f114991" have entirely different histories.
02b129fb84
...
b7ca6d9b27
9 changed files with 138 additions and 188 deletions
|
@ -1,3 +1,3 @@
|
||||||
app_id = "de.j4ne.Paket"
|
app_id = "de.j4ne.Paket"
|
||||||
|
|
||||||
icons = ["plus", "minus", "package-x-generic", "mail"]
|
icons = ["plus", "minus"]
|
|
@ -15,14 +15,6 @@ pub fn device_string() -> &'static str {
|
||||||
"OnePlus 6T Build/RQ3A.211001.001"
|
"OnePlus 6T Build/RQ3A.211001.001"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn okhttp_user_agent() -> String {
|
|
||||||
format!(
|
|
||||||
"okhttp/4.11.0 Post & DHL/{} ({})",
|
|
||||||
app_version(),
|
|
||||||
linux_android_version()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn web_user_agent() -> String {
|
pub fn web_user_agent() -> String {
|
||||||
format!("Mozilla/5.0 ({}; {}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36",
|
format!("Mozilla/5.0 ({}; {}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/117.0.0.0 Mobile Safari/537.36",
|
||||||
linux_android_version(), device_string())
|
linux_android_version(), device_string())
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use reqwest::{header::HeaderMap, Request, RequestBuilder};
|
use reqwest::{header::HeaderMap, Request, RequestBuilder};
|
||||||
|
|
||||||
use crate::common::APIResult;
|
|
||||||
use crate::constants::okhttp_user_agent;
|
|
||||||
use crate::www::authorized_credentials;
|
use crate::www::authorized_credentials;
|
||||||
|
use crate::constants::{app_version, linux_android_version};
|
||||||
|
use crate::common::APIResult;
|
||||||
use crate::{login::DHLIdToken, LibraryResult};
|
use crate::{login::DHLIdToken, LibraryResult};
|
||||||
|
|
||||||
pub struct StammdatenClient {
|
pub struct StammdatenClient {
|
||||||
|
@ -15,19 +15,18 @@ impl StammdatenClient {
|
||||||
StammdatenClient {
|
StammdatenClient {
|
||||||
client: reqwest::ClientBuilder::new()
|
client: reqwest::ClientBuilder::new()
|
||||||
.default_headers(headers())
|
.default_headers(headers())
|
||||||
.user_agent(okhttp_user_agent())
|
.user_agent(user_agent())
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn base_request(
|
pub(crate) fn base_request(&self, request_builder: RequestBuilder, dhli: &DHLIdToken) -> Request {
|
||||||
&self,
|
|
||||||
request_builder: RequestBuilder,
|
|
||||||
dhli: &DHLIdToken,
|
|
||||||
) -> Request {
|
|
||||||
request_builder
|
request_builder
|
||||||
.basic_auth(authorized_credentials().0, Some(authorized_credentials().1))
|
.basic_auth(
|
||||||
|
authorized_credentials().0,
|
||||||
|
Some(authorized_credentials().1),
|
||||||
|
)
|
||||||
.headers(headers())
|
.headers(headers())
|
||||||
.header("cookie", format!("dhli={}", dhli.as_str()))
|
.header("cookie", format!("dhli={}", dhli.as_str()))
|
||||||
.build()
|
.build()
|
||||||
|
@ -69,6 +68,16 @@ impl StammdatenClient {
|
||||||
Err(err) => Err(err.into()),
|
Err(err) => Err(err.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn user_agent() -> String {
|
||||||
|
format!(
|
||||||
|
"okhttp/4.11.0 Post & DHL/{} ({})",
|
||||||
|
app_version(),
|
||||||
|
linux_android_version()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn headers() -> HeaderMap {
|
fn headers() -> HeaderMap {
|
||||||
|
@ -135,13 +144,9 @@ pub enum CustomerDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug)]
|
#[derive(serde::Deserialize, Debug)]
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CustomerDataFull {
|
pub struct CustomerDataFull {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub common: CustomerData,
|
pub common: CustomerData,
|
||||||
|
|
||||||
pub requested_services: Option<Vec<CustomerDataService>>,
|
|
||||||
//pub customer_actions: Option,
|
|
||||||
|
|
||||||
pub address: CustomerAddress,
|
pub address: CustomerAddress,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{login::DHLIdToken, LibraryError, LibraryResult};
|
use crate::{login::DHLIdToken, LibraryResult};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TrackingParams {
|
pub struct TrackingParams {
|
||||||
|
@ -32,16 +32,15 @@ impl crate::WebClient {
|
||||||
endpoint_data_search,
|
endpoint_data_search,
|
||||||
query(&query_parameters_data_search(¶ms, ids)),
|
query(&query_parameters_data_search(¶ms, ids)),
|
||||||
header(api_key.0, api_key.1),
|
header(api_key.0, api_key.1),
|
||||||
header("cookie", cookie_value),
|
header("Cookie", cookie_value)
|
||||||
header("x-requested-with", "de.dhl.paket"),
|
|
||||||
header("sec-ch-ua-platform", "\"Android\""),
|
|
||||||
header("sec-ch-ua", r#""Chromium";v="122", "Not(A:Brand";v="24", "Android WebView";v="122""#),
|
|
||||||
header("sec-ch-ua-mobile", "?1"),
|
|
||||||
header("content-type", "application/json"),
|
|
||||||
header("accept", "application/json")
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return Err(LibraryError::InvalidArgument("only supported with a logged-in session".to_string()));
|
request!(
|
||||||
|
self.web_client,
|
||||||
|
endpoint_data_search,
|
||||||
|
query(&query_parameters_data_search(¶ms, ids)),
|
||||||
|
header(api_key.0, api_key.1)
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = parse_json_response!(res, Response);
|
let resp = parse_json_response!(res, Response);
|
||||||
|
@ -415,17 +414,13 @@ fn query_parameters_data_search(
|
||||||
params: &TrackingParams,
|
params: &TrackingParams,
|
||||||
mut shippingnumbers: Vec<String>,
|
mut shippingnumbers: Vec<String>,
|
||||||
) -> Vec<(String, String)> {
|
) -> Vec<(String, String)> {
|
||||||
let mut out = vec![
|
let mut out = vec![("noRedirect".to_string(), "true".to_string())];
|
||||||
("noRedirect".to_string(), "true".to_string()),
|
|
||||||
("cid".to_string(), "app".to_string()),
|
|
||||||
];
|
|
||||||
|
|
||||||
if let Some(lang) = params.language.as_ref() {
|
if let Some(lang) = params.language.as_ref() {
|
||||||
out.push(("language".to_string(), lang.clone()));
|
out.push(("language".to_string(), lang.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if shippingnumbers.len() > 0 {
|
if shippingnumbers.len() > 0 {
|
||||||
out.push(("inputSearch".to_string(), "true".to_string()));
|
|
||||||
let mut shippingnumbers_string = shippingnumbers.pop().unwrap();
|
let mut shippingnumbers_string = shippingnumbers.pop().unwrap();
|
||||||
for number in shippingnumbers {
|
for number in shippingnumbers {
|
||||||
shippingnumbers_string = format!(",{}", number);
|
shippingnumbers_string = format!(",{}", number);
|
||||||
|
|
|
@ -26,13 +26,6 @@ impl CookieHeaderValueBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_key_value(mut self, key: String, value: String) -> Self {
|
|
||||||
self.list
|
|
||||||
.push((key, value));
|
|
||||||
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_string(self) -> String {
|
pub fn build_string(self) -> String {
|
||||||
let name_value = self
|
let name_value = self
|
||||||
.list
|
.list
|
||||||
|
@ -186,23 +179,15 @@ macro_rules! request_json {
|
||||||
|
|
||||||
macro_rules! parse_json_response {
|
macro_rules! parse_json_response {
|
||||||
($res: expr, $type: ty) => {{
|
($res: expr, $type: ty) => {{
|
||||||
let status = $res.status();
|
let res = $res.text().await.unwrap();
|
||||||
let res: String = $res.text().await.unwrap();
|
|
||||||
// Catch HTML Response early
|
|
||||||
if status == 200 {
|
|
||||||
let res = res.clone();
|
|
||||||
let res = res.trim();
|
|
||||||
if res.starts_with("<!DOCTYPE html>") {
|
|
||||||
println!("got html, exptected json with type {}", stringify!($type));
|
|
||||||
return Err(crate::LibraryError::APIChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
||||||
let mut unused = std::collections::BTreeSet::new();
|
let mut unused = std::collections::BTreeSet::new();
|
||||||
|
|
||||||
|
println!("res({}): {}", stringify!($type), res);
|
||||||
let res: Result<$type, _> = serde_ignored::deserialize(jd, |path| {
|
let res: Result<$type, _> = serde_ignored::deserialize(jd, |path| {
|
||||||
unused.insert(path.to_string());
|
unused.insert(path.to_string());
|
||||||
});
|
});
|
||||||
|
println!("res({}): {:?}", stringify!($type), unused);
|
||||||
|
|
||||||
let res: $type = match res {
|
let res: $type = match res {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
|
@ -215,23 +200,15 @@ macro_rules! parse_json_response {
|
||||||
|
|
||||||
macro_rules! parse_json_response_from_apiresult {
|
macro_rules! parse_json_response_from_apiresult {
|
||||||
($res: expr, $type: ty) => {{
|
($res: expr, $type: ty) => {{
|
||||||
let status = $res.status();
|
let res = $res.text().await.unwrap();
|
||||||
let res: String = $res.text().await.unwrap();
|
|
||||||
// Catch HTML Response early
|
|
||||||
if status == 200 {
|
|
||||||
let res = res.clone();
|
|
||||||
let res = res.trim();
|
|
||||||
if res.starts_with("<!DOCTYPE html>") {
|
|
||||||
println!("got html, exptected json with type {}", stringify!($type));
|
|
||||||
return Err(crate::LibraryError::APIChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
let jd = &mut serde_json::Deserializer::from_str(res.as_str());
|
||||||
let mut unused = std::collections::BTreeSet::new();
|
let mut unused = std::collections::BTreeSet::new();
|
||||||
|
|
||||||
|
println!("res({}): {}", stringify!($type), res);
|
||||||
let res: Result<APIResult<$type>, _> = serde_ignored::deserialize(jd, |path| {
|
let res: Result<APIResult<$type>, _> = serde_ignored::deserialize(jd, |path| {
|
||||||
unused.insert(path.to_string());
|
unused.insert(path.to_string());
|
||||||
});
|
});
|
||||||
|
println!("res({}): {:?}", stringify!($type), unused);
|
||||||
|
|
||||||
let res: LibraryResult<$type> = match res {
|
let res: LibraryResult<$type> = match res {
|
||||||
Ok(res) => res.into(),
|
Ok(res) => res.into(),
|
||||||
|
|
|
@ -6,11 +6,9 @@ license.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# using git version, for https://github.com/Relm4/Relm4/pull/677
|
relm4 = { version = "0.9" , features = [ "libadwaita", "macros" ] }
|
||||||
relm4 = { version = "0.9", features = [ "libadwaita", "macros" ], git = "https://github.com/Relm4/Relm4.git" }
|
relm4-components = { version = "0.9" }
|
||||||
relm4-components = { version = "0.9", git = "https://github.com/Relm4/Relm4.git" }
|
relm4-macros = { version = "0.9" }
|
||||||
relm4-macros = { version = "0.9", git = "https://github.com/Relm4/Relm4.git" }
|
|
||||||
relm4-icons = { version = "0.9", git = "https://github.com/Relm4/icons.git" }
|
|
||||||
tracker = "0.2"
|
tracker = "0.2"
|
||||||
adw = {package = "libadwaita", version = "0.7", features = [ "v1_5" ]}
|
adw = {package = "libadwaita", version = "0.7", features = [ "v1_5" ]}
|
||||||
webkit = { package = "webkit6", version = "0.4" }
|
webkit = { package = "webkit6", version = "0.4" }
|
||||||
|
@ -18,5 +16,6 @@ reqwest = "0.12"
|
||||||
libpaket = { path = "../libpaket" }
|
libpaket = { path = "../libpaket" }
|
||||||
glycin = { version = "2.0.0-beta", features = ["gdk4"] }
|
glycin = { version = "2.0.0-beta", features = ["gdk4"] }
|
||||||
oo7 = { version = "0.3" }
|
oo7 = { version = "0.3" }
|
||||||
|
relm4-icons = { version = "0.9" }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
gtk = { package = "gtk4", version = "0.9", features = ["v4_16"]}
|
gtk = { package = "gtk4", version = "0.9", features = ["v4_16"]}
|
|
@ -1,8 +1,15 @@
|
||||||
use adw::{self, glib, prelude::*};
|
use std::sync::Arc;
|
||||||
use gtk;
|
|
||||||
use paket::login::{new_login_shared_state, Login, LoginOutput};
|
use paket::login::{new_login_shared_state, Login, LoginOutput};
|
||||||
use paket::ready::{Ready, ReadyOutput};
|
use paket::ready::{Ready, ReadyOutput};
|
||||||
use relm4::{main_adw_application, prelude::*, AsyncComponentSender, RELM_THREADS};
|
use relm4::{
|
||||||
|
RELM_THREADS,
|
||||||
|
adw, gtk, main_adw_application, prelude::*, tokio::sync::Mutex,
|
||||||
|
AsyncComponentSender, SharedState,
|
||||||
|
};
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use adw::{glib, prelude::*};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
enum AppState {
|
enum AppState {
|
||||||
|
@ -234,13 +241,7 @@ impl AsyncComponent for App {
|
||||||
}
|
}
|
||||||
AppInput::FatalErrorOccoured(error) => {
|
AppInput::FatalErrorOccoured(error) => {
|
||||||
widgets.fatal_status_page.set_title(&error.short);
|
widgets.fatal_status_page.set_title(&error.short);
|
||||||
widgets.fatal_status_page.set_description(Some(
|
widgets.fatal_status_page.set_description(Some(format!("{}\nThis error is fatal, the app can't continue.", &error.long).as_str()));
|
||||||
format!(
|
|
||||||
"{}\nThis error is fatal, the app can't continue.",
|
|
||||||
&error.long
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
));
|
|
||||||
self.set_state(AppState::FatalError);
|
self.set_state(AppState::FatalError);
|
||||||
}
|
}
|
||||||
AppInput::SwitchToReady => {
|
AppInput::SwitchToReady => {
|
||||||
|
@ -291,8 +292,6 @@ fn main() {
|
||||||
theme.add_resource_path("/de/j4ne/Paket/icons/");
|
theme.add_resource_path("/de/j4ne/Paket/icons/");
|
||||||
theme.add_resource_path("/de/j4ne/Paket/scalable/actions/");
|
theme.add_resource_path("/de/j4ne/Paket/scalable/actions/");
|
||||||
relm4_icons::initialize_icons();
|
relm4_icons::initialize_icons();
|
||||||
|
|
||||||
let app = RelmApp::new(paket::constants::APP_ID);
|
let app = RelmApp::new(paket::constants::APP_ID);
|
||||||
|
|
||||||
app.run_async::<App>(());
|
app.run_async::<App>(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,13 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
|
use gtk::prelude::*;
|
||||||
use libpaket::{
|
use libpaket::{
|
||||||
login::{create_nonce, CodeVerfier, DHLIdToken, RefreshToken, TokenResponse},
|
login::{create_nonce, CodeVerfier, DHLIdToken, RefreshToken, TokenResponse},
|
||||||
LibraryError, LibraryResult, OpenIdClient,
|
LibraryError, LibraryResult, OpenIdClient,
|
||||||
};
|
};
|
||||||
use relm4::{
|
use relm4::{
|
||||||
|
adw, gtk,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
tokio::{sync::Mutex, time::sleep},
|
tokio::{sync::Mutex, time::sleep},
|
||||||
AsyncComponentSender, SharedState,
|
AsyncComponentSender, SharedState,
|
||||||
|
@ -117,47 +119,52 @@ impl AsyncComponent for Login {
|
||||||
tracker: 0,
|
tracker: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = oo7::Keyring::new().await;
|
{
|
||||||
match result {
|
let result = oo7::Keyring::new().await;
|
||||||
Ok(keyring) => {
|
match result {
|
||||||
KEYRING.set(keyring).unwrap();
|
Ok(keyring) => {
|
||||||
if let Err(err) = KEYRING.get().unwrap().unlock().await {
|
KEYRING.set(keyring).unwrap();
|
||||||
sender
|
|
||||||
.output(LoginOutput::KeyringError(err))
|
|
||||||
.expect("sender not worky");
|
|
||||||
} else {
|
|
||||||
let keyring = KEYRING.get().unwrap();
|
|
||||||
match keyring
|
|
||||||
.search_items(&HashMap::from(KEYRING_ATTRIBUTES))
|
|
||||||
.await
|
|
||||||
{
|
{
|
||||||
Ok(res) => {
|
let keyring = KEYRING.get().unwrap();
|
||||||
if res.len() > 0 {
|
if let Err(err) = keyring.unlock().await {
|
||||||
let item = &res[0];
|
|
||||||
let refresh_token = item.secret().await.unwrap();
|
|
||||||
let refresh_token =
|
|
||||||
std::str::from_utf8(refresh_token.as_slice()).unwrap();
|
|
||||||
model.refresh_token =
|
|
||||||
Some(RefreshToken::new(refresh_token.to_string()).unwrap());
|
|
||||||
sender.input(LoginInput::NeedsRefresh);
|
|
||||||
} else {
|
|
||||||
sender.input(LoginInput::NeedsLogin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
sender
|
sender
|
||||||
.output(LoginOutput::KeyringError(err))
|
.output(LoginOutput::KeyringError(err))
|
||||||
.expect("sender not worky");
|
.expect("sender not worky");
|
||||||
|
} else {
|
||||||
|
match keyring
|
||||||
|
.search_items(&HashMap::from(KEYRING_ATTRIBUTES))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(res) => {
|
||||||
|
if res.len() > 0 {
|
||||||
|
let item = &res[0];
|
||||||
|
let refresh_token = item.secret().await.unwrap();
|
||||||
|
let refresh_token =
|
||||||
|
std::str::from_utf8(refresh_token.as_slice()).unwrap();
|
||||||
|
model.refresh_token = Some(
|
||||||
|
RefreshToken::new(refresh_token.to_string()).unwrap(),
|
||||||
|
);
|
||||||
|
sender.input(LoginInput::NeedsRefresh);
|
||||||
|
} else {
|
||||||
|
sender.input(LoginInput::NeedsLogin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
sender
|
||||||
|
.output(LoginOutput::KeyringError(err))
|
||||||
|
.expect("sender not worky");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
Err(err) => {
|
sender
|
||||||
sender
|
.output(LoginOutput::KeyringError(err))
|
||||||
.output(LoginOutput::KeyringError(err))
|
.expect("sender not worky");
|
||||||
.expect("sender not worky");
|
}
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
let webcontext = WebContext::builder().build();
|
let webcontext = WebContext::builder().build();
|
||||||
{
|
{
|
||||||
|
@ -197,10 +204,7 @@ impl AsyncComponent for Login {
|
||||||
match message {
|
match message {
|
||||||
LoginInput::NeedsRefresh => {
|
LoginInput::NeedsRefresh => {
|
||||||
let refresh_token = self.refresh_token.as_ref().unwrap().clone();
|
let refresh_token = self.refresh_token.as_ref().unwrap().clone();
|
||||||
sender.oneshot_command(async {
|
sender.oneshot_command(async { use_refresh_token(refresh_token).await })
|
||||||
let res = use_refresh_token(refresh_token).await;
|
|
||||||
res
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
LoginInput::ReceivedAuthCode(auth_code) => {
|
LoginInput::ReceivedAuthCode(auth_code) => {
|
||||||
self.set_state(LoginState::Offline);
|
self.set_state(LoginState::Offline);
|
||||||
|
@ -250,6 +254,12 @@ impl AsyncComponent for Login {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum ResponseType {
|
||||||
|
Retry,
|
||||||
|
Okay,
|
||||||
|
}
|
||||||
|
|
||||||
impl Login {
|
impl Login {
|
||||||
fn construct_request_uri(&self) -> Option<URIRequest> {
|
fn construct_request_uri(&self) -> Option<URIRequest> {
|
||||||
if self.state != LoginState::InFlow {
|
if self.state != LoginState::InFlow {
|
||||||
|
|
|
@ -17,7 +17,9 @@ use relm4::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::advices::{AdvicesView, AdvicesViewInput};
|
use crate::advices::{AdvicesViewInput, AdvicesView};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[tracker::track]
|
#[tracker::track]
|
||||||
pub struct Ready {
|
pub struct Ready {
|
||||||
|
@ -25,7 +27,6 @@ pub struct Ready {
|
||||||
login: crate::LoginSharedState,
|
login: crate::LoginSharedState,
|
||||||
activate: bool,
|
activate: bool,
|
||||||
have_service_advices: bool,
|
have_service_advices: bool,
|
||||||
have_service_tracking: bool,
|
|
||||||
|
|
||||||
#[do_not_track]
|
#[do_not_track]
|
||||||
advices_component: AsyncController<AdvicesView>,
|
advices_component: AsyncController<AdvicesView>,
|
||||||
|
@ -50,18 +51,12 @@ pub enum ReadyCmds {
|
||||||
GotTracking(LibraryResult<Vec<Shipment>>),
|
GotTracking(LibraryResult<Vec<Shipment>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Services {
|
|
||||||
Advices,
|
|
||||||
SendungVerfolgung,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ReadyInput {
|
pub enum ReadyInput {
|
||||||
Activate,
|
Activate,
|
||||||
Deactivate,
|
Deactivate,
|
||||||
HaveService(Services),
|
HaveAdvicesService,
|
||||||
ServiceBorked(Services),
|
HavePaketankuendigungService,
|
||||||
SearchTracking(String),
|
SearchTracking(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,23 +70,18 @@ impl Component for Ready {
|
||||||
view! {
|
view! {
|
||||||
#[root]
|
#[root]
|
||||||
adw::ViewStack {
|
adw::ViewStack {
|
||||||
add = &model.advices_component.widget().clone() -> gtk::ScrolledWindow {
|
add = model.advices_component.widget() -> >k::ScrolledWindow {
|
||||||
#[track(model.changed_have_service_advices())]
|
/*#[track(model.changed_have_service_advices())]
|
||||||
set_visible: model.have_service_advices,
|
set_visible: model.have_service_advices,*/
|
||||||
|
|
||||||
} -> page_advices: adw::ViewStackPage {
|
} -> /*page_advices: adw::ViewStackPage*/ {
|
||||||
set_title: Some("Mail notification"),
|
set_title: Some("Mail notification"),
|
||||||
set_name: Some("page_advices"),
|
set_name: Some("page_advices"),
|
||||||
set_icon_name: Some(relm4_icons::icon_names::MAIL),
|
/*#[track(model.changed_have_service_advices())]
|
||||||
|
set_visible: model.have_service_advices,*/
|
||||||
#[track(model.changed_have_service_advices())]
|
|
||||||
set_visible: model.have_service_advices,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
add = &adw::Bin {
|
add = &adw::Bin {
|
||||||
#[track(model.changed_have_service_tracking())]
|
|
||||||
set_visible: model.have_service_tracking,
|
|
||||||
|
|
||||||
#[wrap(Some)]
|
#[wrap(Some)]
|
||||||
set_child = >k::ScrolledWindow {
|
set_child = >k::ScrolledWindow {
|
||||||
#[wrap(Some)]
|
#[wrap(Some)]
|
||||||
|
@ -120,13 +110,9 @@ impl Component for Ready {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} -> page_tracking: adw::ViewStackPage {
|
} -> {
|
||||||
set_title: Some("Shipment tracking"),
|
set_title: Some("Shipment tracking"),
|
||||||
set_name: Some("page_tracking"),
|
set_name: Some("page_tracking"),
|
||||||
set_icon_name: Some(relm4_icons::icon_names::PACKAGE_X_GENERIC),
|
|
||||||
|
|
||||||
#[track(model.changed_have_service_tracking())]
|
|
||||||
set_visible: model.have_service_tracking,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +127,6 @@ impl Component for Ready {
|
||||||
|
|
||||||
let model = Ready {
|
let model = Ready {
|
||||||
have_service_advices: false,
|
have_service_advices: false,
|
||||||
have_service_tracking: true,
|
|
||||||
login: init.clone(),
|
login: init.clone(),
|
||||||
activate: false,
|
activate: false,
|
||||||
tracking_factory,
|
tracking_factory,
|
||||||
|
@ -225,36 +210,29 @@ impl Component for Ready {
|
||||||
ReadyInput::Deactivate => {
|
ReadyInput::Deactivate => {
|
||||||
self.set_activate(false);
|
self.set_activate(false);
|
||||||
}
|
}
|
||||||
ReadyInput::HaveService(service) => match service {
|
ReadyInput::HavePaketankuendigungService => {
|
||||||
Services::Advices => {
|
let token = self.login.clone();
|
||||||
self.set_have_service_advices(true);
|
sender.oneshot_command(async move {
|
||||||
self.advices_component.emit(AdvicesViewInput::Fetch);
|
// fetching advices
|
||||||
}
|
let dhli_token = crate::login::get_id_token(&token).await.unwrap();
|
||||||
Services::SendungVerfolgung => {
|
let client = libpaket::WebClient::new();
|
||||||
self.set_have_service_tracking(true);
|
ReadyCmds::GotTracking(
|
||||||
let token = self.login.clone();
|
client
|
||||||
sender.oneshot_command(async move {
|
.tracking_search(
|
||||||
// fetching advices
|
TrackingParams {
|
||||||
let dhli_token = crate::login::get_id_token(&token).await.unwrap();
|
language: Some("de".to_string()),
|
||||||
let client = libpaket::WebClient::new();
|
},
|
||||||
ReadyCmds::GotTracking(
|
Vec::new(),
|
||||||
client
|
Some(&dhli_token),
|
||||||
.tracking_search(
|
)
|
||||||
TrackingParams {
|
.await,
|
||||||
language: Some("de".to_string()),
|
)
|
||||||
},
|
});
|
||||||
Vec::new(),
|
}
|
||||||
Some(&dhli_token),
|
ReadyInput::HaveAdvicesService => {
|
||||||
)
|
self.have_service_advices = true;
|
||||||
.await,
|
self.advices_component.emit(AdvicesViewInput::Fetch);
|
||||||
)
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ReadyInput::ServiceBorked(service) => match service {
|
|
||||||
Services::Advices => self.set_have_service_advices(false),
|
|
||||||
Services::SendungVerfolgung => self.set_have_service_tracking(false),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,13 +251,13 @@ impl Component for Ready {
|
||||||
match service {
|
match service {
|
||||||
libpaket::stammdaten::CustomerDataService::Packstation => (),
|
libpaket::stammdaten::CustomerDataService::Packstation => (),
|
||||||
libpaket::stammdaten::CustomerDataService::Paketankuendigung => {
|
libpaket::stammdaten::CustomerDataService::Paketankuendigung => {
|
||||||
sender.input(ReadyInput::HaveService(Services::SendungVerfolgung))
|
sender.input(ReadyInput::HavePaketankuendigungService);
|
||||||
}
|
}
|
||||||
libpaket::stammdaten::CustomerDataService::PostfilialeDirekt => (),
|
libpaket::stammdaten::CustomerDataService::PostfilialeDirekt => (),
|
||||||
libpaket::stammdaten::CustomerDataService::Digiben => (),
|
libpaket::stammdaten::CustomerDataService::Digiben => (),
|
||||||
libpaket::stammdaten::CustomerDataService::GeraetAktiviert => (),
|
libpaket::stammdaten::CustomerDataService::GeraetAktiviert => (),
|
||||||
libpaket::stammdaten::CustomerDataService::Briefankuendigung => {
|
libpaket::stammdaten::CustomerDataService::Briefankuendigung => {
|
||||||
sender.input(ReadyInput::HaveService(Services::Advices))
|
sender.input(ReadyInput::HaveAdvicesService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,15 +320,10 @@ impl Component for Ready {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err == LibraryError::APIChange {
|
sender.output(ReadyOutput::Error(err)).unwrap();
|
||||||
println!("Upstream API for parcel tracking broke");
|
|
||||||
sender.input(ReadyInput::ServiceBorked(Services::SendungVerfolgung));
|
|
||||||
sender.output(ReadyOutput::Notification("Shipment Tracking API has changed. Deactivating that service.".to_string())).unwrap();
|
|
||||||
} else {
|
|
||||||
sender.output(ReadyOutput::Error(err)).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue