From aa2529cfd8358e7dfa746422b8714061a4fd173d Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Thu, 22 Aug 2024 16:22:20 +0200 Subject: [PATCH] feat: Enable HttpServer on iOS when offline In iOS, we disabled HttpServer for all cozy-apps as the WebView API may behave differently The side effect is that we cannot open those app when offline as we cannot inject minimal code to make them work without network access So we want to enable HttpServer on those apps when we detect the app to be offline Related PR: #486 --- src/libs/httpserver/httpServerProvider.tsx | 2 +- src/libs/httpserver/indexGenerator.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libs/httpserver/httpServerProvider.tsx b/src/libs/httpserver/httpServerProvider.tsx index 7fae1d7c7..27a087a90 100644 --- a/src/libs/httpserver/httpServerProvider.tsx +++ b/src/libs/httpserver/httpServerProvider.tsx @@ -149,7 +149,7 @@ export const HttpServerProvider = ( } await setCookie(cookie, client) - const rawHtml = await getIndexForFqdnAndSlug(fqdn, slug) + const rawHtml = await getIndexForFqdnAndSlug(fqdn, slug, source) if (!rawHtml) { return { diff --git a/src/libs/httpserver/indexGenerator.ts b/src/libs/httpserver/indexGenerator.ts index a90ec0e3a..2f2486516 100644 --- a/src/libs/httpserver/indexGenerator.ts +++ b/src/libs/httpserver/indexGenerator.ts @@ -13,6 +13,7 @@ import { prepareAssets } from '/libs/httpserver/copyAllFilesFromBundleAssets' import { TemplateValues } from '/libs/httpserver/indexDataFetcher' +import { HtmlSource } from '/libs/httpserver/models' import { getCurrentAppConfigurationForFqdnAndSlug, setCurrentAppVersionForFqdnAndSlug @@ -87,11 +88,17 @@ const isSlugInBlocklist = (currentSlug: string): boolean => export const getIndexForFqdnAndSlug = async ( fqdn: string, - slug: string + slug: string, + source: HtmlSource ): Promise => { if (shouldDisableGetIndex()) return false // Make cozy-app hosted by webpack-dev-server work with HTTPServer - if (!isSlugInAllowlist(slug) || isSlugInBlocklist(slug)) return false + if ( + (!isSlugInAllowlist(slug) || isSlugInBlocklist(slug)) && + source !== 'cache' + ) { + return false + } await initLocalBundleIfNotExist(fqdn, slug)