From d19b67701efd3e661f3fd9b70a3fe1cdd8f77aec Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sun, 22 Sep 2024 01:34:55 +1200 Subject: [PATCH] 1.5.5 --- .../src/lib/patches/androidRequests.ts | 37 ++++++++++++++----- update_versions.py | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/materialious/src/lib/patches/androidRequests.ts b/materialious/src/lib/patches/androidRequests.ts index 30e18f44..5d7a9a91 100644 --- a/materialious/src/lib/patches/androidRequests.ts +++ b/materialious/src/lib/patches/androidRequests.ts @@ -1,6 +1,6 @@ import { goto } from "$app/navigation"; import { Capacitor } from "@capacitor/core"; - +import { NodeJS } from 'capacitor-nodejs'; if (Capacitor.getPlatform() === 'android') { const originalFetch = window.fetch; @@ -9,17 +9,32 @@ if (Capacitor.getPlatform() === 'android') { const corsAnywhereProxyUrl: string = 'http://localhost:3000/'; // Overwrite fetch to use CORS-Anywhere proxy - window.fetch = async (requestInput: RequestInfo | URL, requestOptions: RequestInit = {}): Promise => { - const requestUrl: string = - typeof requestInput === 'string' ? requestInput : requestInput.toString(); + window.fetch = async (requestInput: string | URL | Request, requestOptions?: RequestInit): Promise => { + let requestUrl: string; - // Check if the URL is already proxied, to avoid double proxying - if (!requestUrl.startsWith(corsAnywhereProxyUrl) && !requestUrl.startsWith('/') && !requestUrl.startsWith('blob:') && !requestUrl.startsWith('/')) { + if (typeof requestInput === 'string') { + requestUrl = requestInput; + } else if ('url' in requestInput) { + requestUrl = requestInput.url; + requestOptions = { + body: requestInput.body, + cache: requestInput.cache, + credentials: requestInput.credentials, + headers: requestInput.headers, + method: requestInput.method, + mode: requestInput.mode, + redirect: requestInput.redirect, + referrer: requestInput.referrer, + signal: requestInput.signal, + }; + } else { + requestUrl = requestInput.toString(); + } + + if (!requestUrl.startsWith(corsAnywhereProxyUrl) && !requestUrl.startsWith('/') && !requestUrl.startsWith('blob:')) { requestInput = corsAnywhereProxyUrl + requestUrl; } - // Ensure options.method is set to a valid value - requestOptions.method = requestOptions.method ? requestOptions.method.toUpperCase() : 'GET'; // Use the original fetch with the proxied URL and options return originalFetch(requestInput, requestOptions); @@ -38,5 +53,7 @@ if (Capacitor.getPlatform() === 'android') { }; // Must reload page after patches - goto('/', { replaceState: true }); -} \ No newline at end of file + NodeJS.whenReady().then(() => { + goto('/', { replaceState: true }); + }); +} diff --git a/update_versions.py b/update_versions.py index d802a161..40b6dce3 100644 --- a/update_versions.py +++ b/update_versions.py @@ -5,7 +5,7 @@ import json import os import re -LATEST_VERSION = "1.5.4" +LATEST_VERSION = "1.5.5" WORKING_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "materialious") ROOT_PACKAGE = os.path.join(WORKING_DIR, "package.json")