From 88b63a55186d373185fbab7e1a5ed37ba3fcff5c Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Sun, 19 May 2024 10:43:44 +0700 Subject: [PATCH] App option to disable context menu in Home page --- src/modules/ui/global-settings.ts | 1 + src/utils/network.ts | 23 +++++++++++++++++++++++ src/utils/preferences.ts | 7 +++++++ src/utils/preload-state.ts | 9 +++++++++ 4 files changed, 40 insertions(+) diff --git a/src/modules/ui/global-settings.ts b/src/modules/ui/global-settings.ts index 1f27b9a..1ff6b14 100644 --- a/src/modules/ui/global-settings.ts +++ b/src/modules/ui/global-settings.ts @@ -84,6 +84,7 @@ const SETTINGS_UI = { [t('ui')]: { items: [ PrefKey.UI_LAYOUT, + PrefKey.UI_HOME_CONTEXT_MENU_DISABLED, PrefKey.STREAM_SIMPLIFY_MENU, PrefKey.SKIP_SPLASH_VIDEO, !AppInterface && PrefKey.UI_SCROLLBAR_HIDE, diff --git a/src/utils/network.ts b/src/utils/network.ts index 27caecf..5333879 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -565,6 +565,29 @@ export function interceptHttpRequests() { BxEvent.dispatch(window, BxEvent.STREAM_STARTING); } + // Override experimentals + if (url.startsWith('https://emerald.xboxservices.com/xboxcomfd/experimentation')) { + try { + 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] + } + + response.json = () => Promise.resolve(json); + return response; + } catch (e) { + console.log(e); + } + } + // Add list of games with custom layouts to the official list if (STATES.hasTouchSupport && url.includes('catalog.gamepass.com/sigls/')) { const response = await NATIVE_FETCH(request, init); diff --git a/src/utils/preferences.ts b/src/utils/preferences.ts index 5b4cd02..3f0a28c 100644 --- a/src/utils/preferences.ts +++ b/src/utils/preferences.ts @@ -65,6 +65,8 @@ export enum PrefKey { UI_LAYOUT = 'ui_layout', UI_SCROLLBAR_HIDE = 'ui_scrollbar_hide', + UI_HOME_CONTEXT_MENU_DISABLED = 'ui_home_context_menu_disabled', + VIDEO_CLARITY = 'video_clarity', VIDEO_RATIO = 'video_ratio', VIDEO_BRIGHTNESS = 'video_brightness', @@ -470,6 +472,11 @@ export class Preferences { default: false, }, + [PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: { + label: t('disable-home-context-menu'), + default: false, + }, + [PrefKey.BLOCK_SOCIAL_FEATURES]: { label: t('disable-social-features'), default: false, diff --git a/src/utils/preload-state.ts b/src/utils/preload-state.ts index b1c5910..48b35de 100644 --- a/src/utils/preload-state.ts +++ b/src/utils/preload-state.ts @@ -2,6 +2,7 @@ import { STATES } from "@utils/global"; import { BxLogger } from "./bx-logger"; import { TouchController } from "@modules/touch-controller"; import { GamePassCloudGallery } from "./gamepass-gallery"; +import { getPref, PrefKey } from "./preferences"; const LOG_TAG = 'PreloadState'; @@ -41,6 +42,14 @@ export function overridePreloadState() { } } + if (getPref(PrefKey.UI_HOME_CONTEXT_MENU_DISABLED)) { + try { + state.experiments.experimentationInfo.data.treatments.EnableHomeContextMenu = false; + } catch (e) { + BxLogger.error(LOG_TAG, e); + } + } + // @ts-ignore _state = state; STATES.appContext = structuredClone(state.appContext);