From ebb4d3c1414ceb762aa8d9ff9bb440e73909dab1 Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 9 Jun 2024 18:31:15 +0700 Subject: [PATCH] Add FeatureGates --- src/modules/patcher.ts | 9 ++++----- src/utils/bx-exposed.ts | 2 +- src/utils/bx-flags.ts | 4 +++- src/utils/feature-gates.ts | 20 ++++++++++++++++++++ src/utils/network.ts | 13 ++++--------- 5 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 src/utils/feature-gates.ts diff --git a/src/modules/patcher.ts b/src/modules/patcher.ts index b08e6ee..f497f23 100644 --- a/src/modules/patcher.ts +++ b/src/modules/patcher.ts @@ -11,6 +11,7 @@ import codeLocalCoOpEnable from "./patches/local-co-op-enable.js" with { type: " import codeRemotePlayEnable from "./patches/remote-play-enable.js" with { type: "text" }; import codeRemotePlayKeepAlive from "./patches/remote-play-keep-alive.js" with { type: "text" }; import codeVibrationAdjust from "./patches/vibration-adjust.js" with { type: "text" }; +import { FeatureGates } from "@/utils/feature-gates.js"; type PatchArray = (keyof typeof PATCHES)[]; @@ -228,12 +229,10 @@ if (!!window.BX_REMOTE_PLAY_CONFIG) { // Find the next "}," const endIndex = str.indexOf('},', index); - const newSettings = [ - // 'EnableStreamGate: false', - 'PwaPrompt: false', - ]; + let newSettings = JSON.stringify(FeatureGates); + newSettings = newSettings.substring(1, newSettings.length - 1); - const newCode = newSettings.join(','); + const newCode = newSettings; str = str.substring(0, endIndex) + ',' + newCode + str.substring(endIndex); return str; diff --git a/src/utils/bx-exposed.ts b/src/utils/bx-exposed.ts index 74c44b2..5763d75 100644 --- a/src/utils/bx-exposed.ts +++ b/src/utils/bx-exposed.ts @@ -23,7 +23,7 @@ export const BxExposed = { let supportedInputTypes = titleInfo.details.supportedInputTypes; - if (BX_FLAGS.ForceNativeMkbTitles.includes(titleInfo.details.productId)) { + if (BX_FLAGS.ForceNativeMkbTitles?.includes(titleInfo.details.productId)) { supportedInputTypes.push(InputType.MKB); } diff --git a/src/utils/bx-flags.ts b/src/utils/bx-flags.ts index cab900d..6df6e86 100644 --- a/src/utils/bx-flags.ts +++ b/src/utils/bx-flags.ts @@ -8,6 +8,7 @@ type BxFlags = Partial<{ UseDevTouchLayout: boolean; ForceNativeMkbTitles: string[]; + FeatureGates: {[key: string]: boolean} | null, }> // Setup flags @@ -21,9 +22,10 @@ const DEFAULT_FLAGS: BxFlags = { UseDevTouchLayout: false, ForceNativeMkbTitles: [], + FeatureGates: null, } -export const BX_FLAGS = Object.assign(DEFAULT_FLAGS, window.BX_FLAGS || {}); +export const BX_FLAGS: BxFlags = Object.assign(DEFAULT_FLAGS, window.BX_FLAGS || {}); try { delete window.BX_FLAGS; } catch (e) {} diff --git a/src/utils/feature-gates.ts b/src/utils/feature-gates.ts new file mode 100644 index 0000000..a42beaa --- /dev/null +++ b/src/utils/feature-gates.ts @@ -0,0 +1,20 @@ +import { BX_FLAGS } from "./bx-flags"; +import { getPref, PrefKey } from "./preferences"; + +export let FeatureGates: {[key: string]: boolean} = { + 'PwaPrompt': false, +}; + +// Disable context menu in Home page +if (getPref(PrefKey.UI_HOME_CONTEXT_MENU_DISABLED)) { + FeatureGates['EnableHomeContextMenu'] = false; +} + +// Disable chat feature +if (getPref(PrefKey.BLOCK_SOCIAL_FEATURES)) { + FeatureGates['EnableGuideChatTab'] = false; +} + +if (BX_FLAGS.FeatureGates) { + FeatureGates = Object.assign(BX_FLAGS.FeatureGates, FeatureGates); +} diff --git a/src/utils/network.ts b/src/utils/network.ts index 3c6c7fb..05c61f7 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -9,6 +9,7 @@ import { STATES } from "@utils/global"; import { getPreferredServerRegion } from "@utils/region"; import { GamePassCloudGallery } from "./gamepass-gallery"; import { InputType } from "./bx-exposed"; +import { FeatureGates } from "./feature-gates"; enum RequestType { XCLOUD = 'xcloud', @@ -440,7 +441,7 @@ class XcloudInterceptor { let overrideMkb: boolean | null = null; - if (getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' || BX_FLAGS.ForceNativeMkbTitles.includes(STATES.currentStream.titleInfo!.details.productId)) { + if (getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' || BX_FLAGS.ForceNativeMkbTitles?.includes(STATES.currentStream.titleInfo!.details.productId)) { overrideMkb = true; } @@ -578,14 +579,8 @@ export function interceptHttpRequests() { const response = await NATIVE_FETCH(request, init); const json = await response.json(); - const overrideTreatments: {[key: string]: boolean} = {}; - - if (getPref(PrefKey.UI_HOME_CONTEXT_MENU_DISABLED)) { - overrideTreatments['EnableHomeContextMenu'] = false; - } - - for (const key in overrideTreatments) { - json.exp.treatments[key] = overrideTreatments[key] + for (const key in FeatureGates) { + json.exp.treatments[key] = FeatureGates[key] } response.json = () => Promise.resolve(json);