From 718d843df2d9acd9b23ee5f142223dd23ca2480a Mon Sep 17 00:00:00 2001 From: Kroonk Date: Thu, 21 May 2026 22:43:52 +0200 Subject: [PATCH] feat: open Nextcloud login flow on mobile --- app.js | 45 +++++++++++++++++++++++++++++++-------------- index.html | 2 +- services.json | 2 +- sw.js | 6 +++--- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/app.js b/app.js index 35cc1e9..a65d7bc 100644 --- a/app.js +++ b/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) { ${service.domain} `; - 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); }); } diff --git a/index.html b/index.html index 99aa891..fb5b888 100644 --- a/index.html +++ b/index.html @@ -117,6 +117,6 @@ - + diff --git a/services.json b/services.json index fd33a25..de6801f 100644 --- a/services.json +++ b/services.json @@ -39,7 +39,7 @@ "description": "Cloud-Speicher", "domain": "drive.mischlabs.de", "url": "https://drive.mischlabs.de", - "mobileUrl": "nextcloud://", + "mobileUrl": "https://drive.mischlabs.de/index.php/login/flow", "category": "media", "accent": "#60a5fa", "icon": "folder", diff --git a/sw.js b/sw.js index 4bfdd8f..894d339 100644 --- a/sw.js +++ b/sw.js @@ -1,10 +1,10 @@ -const CACHE_NAME = 'mischlabs-pwa-v9'; +const CACHE_NAME = 'mischlabs-pwa-v10'; const APP_SHELL = [ '/', '/index.html', '/offline.html', - '/style.css?v=20', - '/app.js?v=6', + '/style.css?v=27', + '/app.js?v=28', '/services.json?v=1', '/manifest.webmanifest?v=3', '/icons/icon-192.png',