frontend: Add redirection to DAVx5 activity

This commit is contained in:
Lennart
2025-06-08 23:02:26 +02:00
parent 152bf374d7
commit 6ae2276035
3 changed files with 9 additions and 1 deletions

View File

@@ -39,4 +39,5 @@
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -54,6 +54,9 @@
</td> </td>
</tr> </tr>
</table> </table>
{% if let Some(hostname) = davx5_hostname %}
<a href="intent://{{ hostname | urlencode }}#Intent;action=android.intent.action.VIEW;component=at.bitfire.davdroid.ui.setup.LoginActivity;scheme=davx5;package=at.bitfire.davdroid;S.loginFlow=1;end">Configure in DAVx5</a>
{% endif %}
</section> </section>
<section> <section>

View File

@@ -7,7 +7,7 @@ use axum::{
extract::Path, extract::Path,
response::{IntoResponse, Redirect}, response::{IntoResponse, Redirect},
}; };
use axum_extra::TypedHeader; use axum_extra::{TypedHeader, extract::Host};
use headers::UserAgent; use headers::UserAgent;
use http::StatusCode; use http::StatusCode;
use rustical_store::{ use rustical_store::{
@@ -25,6 +25,7 @@ pub struct UserPage {
pub addressbooks: Vec<Addressbook>, pub addressbooks: Vec<Addressbook>,
pub deleted_addressbooks: Vec<Addressbook>, pub deleted_addressbooks: Vec<Addressbook>,
pub is_apple: bool, pub is_apple: bool,
pub davx5_hostname: Option<String>,
} }
pub async fn route_user_named< pub async fn route_user_named<
@@ -37,6 +38,7 @@ pub async fn route_user_named<
Extension(addr_store): Extension<Arc<AS>>, Extension(addr_store): Extension<Arc<AS>>,
Extension(auth_provider): Extension<Arc<AP>>, Extension(auth_provider): Extension<Arc<AP>>,
TypedHeader(user_agent): TypedHeader<UserAgent>, TypedHeader(user_agent): TypedHeader<UserAgent>,
Host(host): Host,
user: User, user: User,
) -> impl IntoResponse { ) -> impl IntoResponse {
if user_id != user.id { if user_id != user.id {
@@ -64,6 +66,7 @@ pub async fn route_user_named<
} }
let is_apple = user_agent.as_str().contains("Apple") || user_agent.as_str().contains("Mac OS"); let is_apple = user_agent.as_str().contains("Apple") || user_agent.as_str().contains("Mac OS");
let davx5_hostname = user_agent.as_str().contains("Android").then_some(host);
UserPage { UserPage {
app_tokens: auth_provider.get_app_tokens(&user.id).await.unwrap(), app_tokens: auth_provider.get_app_tokens(&user.id).await.unwrap(),
@@ -73,6 +76,7 @@ pub async fn route_user_named<
deleted_addressbooks, deleted_addressbooks,
user, user,
is_apple, is_apple,
davx5_hostname,
} }
.into_response() .into_response()
} }