mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-16 22:26:16 -08:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { AppConfig } from '../../environments/environment';
|
|
|
|
export interface IptvnatorRuntimeConfig {
|
|
readonly BACKEND_URL?: string;
|
|
}
|
|
|
|
export function resolveBackendUrl(
|
|
runtimeConfig: IptvnatorRuntimeConfig | undefined,
|
|
fallbackUrl: string
|
|
): string {
|
|
const runtimeUrl = runtimeConfig?.BACKEND_URL?.trim();
|
|
return runtimeUrl || fallbackUrl;
|
|
}
|
|
|
|
export function getRuntimeBackendUrl(): string {
|
|
return resolveBackendUrl(
|
|
globalThis.window?.__IPTVNATOR_CONFIG__,
|
|
AppConfig.BACKEND_URL
|
|
);
|
|
}
|
|
|
|
export interface ServiceWorkerRuntimeContext {
|
|
readonly electronBridge?: unknown;
|
|
readonly protocol?: string;
|
|
}
|
|
|
|
function getDefaultServiceWorkerRuntimeContext(): ServiceWorkerRuntimeContext {
|
|
const browserWindow = globalThis.window as
|
|
| (Window & { electron?: unknown })
|
|
| undefined;
|
|
|
|
return {
|
|
electronBridge: browserWindow?.electron,
|
|
protocol:
|
|
browserWindow?.location?.protocol ?? globalThis.location?.protocol,
|
|
};
|
|
}
|
|
|
|
export function shouldEnableServiceWorker(
|
|
production = AppConfig.production,
|
|
navigatorRef: Navigator | undefined = globalThis.navigator,
|
|
runtimeContext = getDefaultServiceWorkerRuntimeContext()
|
|
): boolean {
|
|
return (
|
|
production &&
|
|
!!navigatorRef &&
|
|
'serviceWorker' in navigatorRef &&
|
|
!runtimeContext.electronBridge &&
|
|
runtimeContext.protocol !== 'file:'
|
|
);
|
|
}
|