From 0ba8df734cc4349183035e3700ee20704e4d5828 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 28 Apr 2024 17:17:55 +0700 Subject: [PATCH] Fix problem with the Android app --- src/index.ts | 5 +---- src/modules/touch-controller.ts | 3 ++- src/utils/bx-flags.ts | 8 ++++---- src/utils/global.ts | 2 +- src/utils/network.ts | 3 ++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 10a1935..dc0e2b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ -import { getBuildConfig } from "./build-config" with { type: "macro" }; import "./utils/global"; import { BxEvent } from "./utils/bx-event"; import { BX_FLAGS } from "./utils/bx-flags"; import { BxExposed } from "./utils/bx-exposed"; import { t } from "./utils/translation"; +import { interceptHttpRequests } from "./utils/network"; import { CE } from "./utils/html"; import { showGamepadToast } from "./utils/gamepad"; import { MkbHandler } from "./modules/mkb/mkb-handler"; @@ -24,12 +24,9 @@ import { onHistoryChanged, patchHistoryMethod } from "./utils/history"; import { VibrationManager } from "./modules/vibration-manager"; import { PreloadedState } from "./utils/titles-info"; import { patchAudioContext, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "./utils/monkey-patches"; -import { interceptHttpRequests } from "./utils/network"; import { STATES } from "./utils/global"; import { injectStreamMenuButtons } from "./modules/stream/stream-ui"; -/* ADDITIONAL CODE */ - // Handle login page if (window.location.pathname.includes('/auth/msa')) { window.addEventListener('load', e => { diff --git a/src/modules/touch-controller.ts b/src/modules/touch-controller.ts index 08d5b7c..14792de 100644 --- a/src/modules/touch-controller.ts +++ b/src/modules/touch-controller.ts @@ -1,10 +1,11 @@ -import { NATIVE_FETCH, STATES } from "../utils/global"; +import { STATES } from "../utils/global"; import { CE } from "../utils/html"; import { Toast } from "../utils/toast"; import { BxEvent } from "../utils/bx-event"; import { BX_FLAGS } from "../utils/bx-flags"; import { getPref, PrefKey } from "../utils/preferences"; import { t } from "../utils/translation"; +import { NATIVE_FETCH } from "../utils/network"; export class TouchController { static readonly #EVENT_SHOW_DEFAULT_CONTROLLER = new MessageEvent('message', { diff --git a/src/utils/bx-flags.ts b/src/utils/bx-flags.ts index a205849..cb28738 100644 --- a/src/utils/bx-flags.ts +++ b/src/utils/bx-flags.ts @@ -19,7 +19,7 @@ const DEFAULT_FLAGS: BxFlags = { UseDevTouchLayout: false, } -const BX_FLAGS = Object.assign(DEFAULT_FLAGS, window.BX_FLAGS || {}); -delete window.BX_FLAGS; - -export { BX_FLAGS } +export const BX_FLAGS = Object.assign(DEFAULT_FLAGS, window.BX_FLAGS || {}); +try { + delete window.BX_FLAGS; +} catch (e) {} diff --git a/src/utils/global.ts b/src/utils/global.ts index d9b0985..4614e6b 100644 --- a/src/utils/global.ts +++ b/src/utils/global.ts @@ -2,7 +2,7 @@ export const SCRIPT_VERSION = Bun.env.SCRIPT_VERSION; export const SCRIPT_HOME = 'https://github.com/redphx/better-xcloud'; export const AppInterface = window.AppInterface; -export const NATIVE_FETCH = window.fetch; + export const STATES: BxStates = { isPlaying: false, appContext: {}, diff --git a/src/utils/network.ts b/src/utils/network.ts index a900d13..b8e1b05 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -5,10 +5,11 @@ import { PrefKey, getPref } from "./preferences"; import { RemotePlay } from "../modules/remote-play"; import { StreamBadges } from "../modules/stream/stream-badges"; import { TouchController } from "../modules/touch-controller"; -import { NATIVE_FETCH, STATES } from "./global"; +import { STATES } from "./global"; import { getPreferredServerRegion } from "./region"; import { TitlesInfo } from "./titles-info"; +export const NATIVE_FETCH = window.fetch; enum RequestType { XCLOUD = 'xcloud',