Fix updates dialog on Android by portaling above Settings and resolving Capacitor asset URLs.
Trigger cinny-mobile / dispatch (push) Successful in 2s
Trigger cinny-mobile / dispatch (push) Successful in 2s
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { trimTrailingSlash } from '../utils/common';
|
||||
|
||||
const UPDATE_BASE_PATH = `${trimTrailingSlash(import.meta.env.BASE_URL)}/update`;
|
||||
function getUpdateBaseUrl(): string {
|
||||
const basePath = trimTrailingSlash(import.meta.env.BASE_URL || './');
|
||||
const relative =
|
||||
basePath === '.' || basePath === '' ? 'update/' : `${basePath}/update/`;
|
||||
return new URL(relative, window.location.href).href.replace(/\/$/, '');
|
||||
}
|
||||
|
||||
function getUpdateFileUrl(file: string): string {
|
||||
return new URL(file, `${getUpdateBaseUrl()}/`).href;
|
||||
}
|
||||
|
||||
export type UpdateManifestEntry = {
|
||||
file: string;
|
||||
@@ -61,12 +70,12 @@ export function resolveUpdateAssetUrl(src: string | undefined): string | undefin
|
||||
if (src.startsWith('/')) return src;
|
||||
|
||||
const normalized = src.replace(/^\.\//, '');
|
||||
return `${UPDATE_BASE_PATH}/${normalized}`;
|
||||
return new URL(normalized, `${getUpdateBaseUrl()}/`).href;
|
||||
}
|
||||
|
||||
export async function loadUpdateManifest(): Promise<UpdateManifest | null> {
|
||||
try {
|
||||
const response = await fetch(`${UPDATE_BASE_PATH}/manifest.json`, { cache: 'no-cache' });
|
||||
const response = await fetch(getUpdateFileUrl('manifest.json'), { cache: 'no-cache' });
|
||||
if (!response.ok) return null;
|
||||
|
||||
const data = (await response.json()) as UpdateManifest;
|
||||
@@ -86,7 +95,7 @@ export async function loadUpdateDocument(file: string): Promise<ParsedUpdateDoc
|
||||
if (!safeFile || safeFile.includes('..')) return null;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${UPDATE_BASE_PATH}/${safeFile}`, { cache: 'no-cache' });
|
||||
const response = await fetch(getUpdateFileUrl(safeFile), { cache: 'no-cache' });
|
||||
if (!response.ok) return null;
|
||||
|
||||
const source = await response.text();
|
||||
|
||||
Reference in New Issue
Block a user