feat: open Nextcloud login flow on mobile
All checks were successful
Build & Push Docker Image to Gitea Registry / build-and-push (push) Successful in 11s
All checks were successful
Build & Push Docker Image to Gitea Registry / build-and-push (push) Successful in 11s
This commit is contained in:
45
app.js
45
app.js
@@ -56,6 +56,17 @@ function serviceSearchText(service) {
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
function isMobileDevice() {
|
||||
return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
function getMobileUrl(service) {
|
||||
if (service.id === 'drive') {
|
||||
return 'https://drive.mischlabs.de/index.php/login/flow';
|
||||
}
|
||||
return service.mobileUrl;
|
||||
}
|
||||
|
||||
function createServiceCard(service) {
|
||||
const category = categoryById.get(service.category);
|
||||
const card = document.createElement('a');
|
||||
@@ -81,22 +92,28 @@ function createServiceCard(service) {
|
||||
<span class="card-domain">${service.domain}</span>
|
||||
`;
|
||||
|
||||
if (service.mobileUrl) {
|
||||
const mobileUrl = getMobileUrl(service);
|
||||
if (mobileUrl) {
|
||||
card.addEventListener('click', (e) => {
|
||||
const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
if (isMobile) {
|
||||
e.preventDefault();
|
||||
const start = Date.now();
|
||||
// Versuch, die mobile App über ihr registriertes Custom URL-Schema zu öffnen
|
||||
window.location.href = service.mobileUrl;
|
||||
|
||||
// Web-Fallback nach 800ms, falls die App nicht installiert ist
|
||||
setTimeout(() => {
|
||||
if (Date.now() - start < 1500) {
|
||||
window.open(service.url, '_blank');
|
||||
}
|
||||
}, 800);
|
||||
if (!isMobileDevice()) return;
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if (/^https?:\/\//i.test(mobileUrl)) {
|
||||
window.location.href = mobileUrl;
|
||||
return;
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
// Try to open the native mobile app through its registered URL scheme.
|
||||
window.location.href = mobileUrl;
|
||||
|
||||
// Web fallback if the app is not installed or the scheme is not handled.
|
||||
setTimeout(() => {
|
||||
if (Date.now() - start < 1500) {
|
||||
window.open(service.url, '_blank');
|
||||
}
|
||||
}, 800);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user