mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-08 22:27:44 +02:00
Block notifications
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { AppInterface, SCRIPT_VERSION, STATES } from "@utils/global";
|
||||
import { BX_FLAGS } from "@utils/bx-flags";
|
||||
import { BxLogger } from "@utils/bx-logger";
|
||||
import { hashCode, renderString } from "@utils/utils";
|
||||
import { blockSomeNotifications, hashCode, renderString } from "@utils/utils";
|
||||
import { BxEvent } from "@/utils/bx-event";
|
||||
|
||||
import codeControllerShortcuts from "./patches/controller-shortcuts.js" with { type: "text" };
|
||||
@@ -14,7 +14,7 @@ import { PrefKey, StorageKey } from "@/enums/pref-keys.js";
|
||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||
import { GamePassCloudGallery } from "@/enums/game-pass-gallery";
|
||||
import { t } from "@/utils/translation";
|
||||
import { NativeMkbMode, TouchControllerMode, UiLayout, UiSection } from "@/enums/pref-values";
|
||||
import { BlockFeature, NativeMkbMode, TouchControllerMode, UiLayout, UiSection } from "@/enums/pref-values";
|
||||
import { PatcherUtils } from "./patcher-utils.js";
|
||||
|
||||
export type PatchName = keyof typeof PATCHES;
|
||||
@@ -935,7 +935,43 @@ if (this.baseStorageKey in window.BX_EXPOSED.overrideSettings) {
|
||||
|
||||
str = str.replace(text, text + 'return;');
|
||||
return str;
|
||||
}
|
||||
},
|
||||
|
||||
changeNotificationsSubscription(str: string) {
|
||||
let text = ';buildSubscriptionQueryParamsForNotifications(';
|
||||
let index = str.indexOf(text);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
index += text.length;
|
||||
// Get parameter name
|
||||
const subsVar = str[index];
|
||||
|
||||
// Find index after {
|
||||
index = str.indexOf('{', index) + 1;
|
||||
const blockFeatures = getPref<BlockFeature[]>(PrefKey.BLOCK_FEATURES);
|
||||
const filters = [];
|
||||
if (blockFeatures.includes(BlockFeature.NOTIFICATIONS_INVITES)) {
|
||||
filters.push('GameInvite', 'PartyInvite');
|
||||
}
|
||||
|
||||
if (blockFeatures.includes(BlockFeature.FRIENDS)) {
|
||||
filters.push('Follower');
|
||||
}
|
||||
|
||||
if (blockFeatures.includes(BlockFeature.NOTIFICATIONS_ACHIEVEMENTS)) {
|
||||
filters.push('AchievementUnlock');
|
||||
}
|
||||
|
||||
const newCode = `
|
||||
let subs = ${subsVar};
|
||||
subs = subs.filter(val => !${JSON.stringify(filters)}.includes(val));
|
||||
${subsVar} = subs;
|
||||
`;
|
||||
str = PatcherUtils.insertAt(str, index, newCode);
|
||||
return str;
|
||||
},
|
||||
};
|
||||
|
||||
let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
@@ -1001,13 +1037,18 @@ let PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
'enableConsoleLogging',
|
||||
'enableXcloudLogger',
|
||||
] : []),
|
||||
|
||||
...(blockSomeNotifications() ? [
|
||||
'changeNotificationsSubscription',
|
||||
] : []),
|
||||
]);
|
||||
|
||||
const hideSections = getPref<UiSection[]>(PrefKey.UI_HIDE_SECTIONS);
|
||||
let HOME_PAGE_PATCH_ORDERS = PatcherUtils.filterPatches([
|
||||
getPref<UiSection>(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS) && 'ignorePlayWithFriendsSection',
|
||||
getPref<UiSection>(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.ALL_GAMES) && 'ignoreAllGamesSection',
|
||||
STATES.browser.capabilities.touch && getPref<UiSection>(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.TOUCH) && 'ignorePlayWithTouchSection',
|
||||
(getPref<UiSection>(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.NATIVE_MKB) || getPref<UiSection>(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.MOST_POPULAR)) && 'ignoreSiglSections',
|
||||
hideSections.includes(UiSection.FRIENDS) && 'ignorePlayWithFriendsSection',
|
||||
hideSections.includes(UiSection.ALL_GAMES) && 'ignoreAllGamesSection',
|
||||
STATES.browser.capabilities.touch && hideSections.includes(UiSection.TOUCH) && 'ignorePlayWithTouchSection',
|
||||
hideSections.some(value => [UiSection.NATIVE_MKB, UiSection.MOST_POPULAR].includes(value)) && 'ignoreSiglSections',
|
||||
]);
|
||||
|
||||
// Only when playing
|
||||
|
@@ -12,6 +12,7 @@ import { PrefKey } from "@/enums/pref-keys";
|
||||
import { getPref } from "./settings-storages/global-settings-storage";
|
||||
import type { RemotePlayConsoleAddresses } from "@/types/network";
|
||||
import { BlockFeature, StreamResolution } from "@/enums/pref-values";
|
||||
import { blockAllNotifications } from "./utils";
|
||||
|
||||
type RequestType = 'xcloud' | 'xhome';
|
||||
|
||||
@@ -128,13 +129,13 @@ export function interceptHttpRequests() {
|
||||
// Clear Applications Insight buffers
|
||||
clearAllLogs();
|
||||
|
||||
BLOCKED_URLS = BLOCKED_URLS.concat([
|
||||
BLOCKED_URLS.push(
|
||||
'https://arc.msn.com',
|
||||
'https://browser.events.data.microsoft.com',
|
||||
'https://dc.services.visualstudio.com',
|
||||
'https://2c06dea3f26c40c69b8456d319791fd0@o427368.ingest.sentry.io',
|
||||
'https://mscom.demdex.net',
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,16 +143,23 @@ export function interceptHttpRequests() {
|
||||
// 'https://accounts.xboxlive.com/family/memberXuid',
|
||||
const blockFeatures = getPref<BlockFeature[]>(PrefKey.BLOCK_FEATURES);
|
||||
if (blockFeatures.includes(BlockFeature.CHAT)) {
|
||||
BLOCKED_URLS = BLOCKED_URLS.concat([
|
||||
BLOCKED_URLS.push(
|
||||
'https://xblmessaging.xboxlive.com/network/xbox/users/me/inbox',
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
if (blockFeatures.includes(BlockFeature.FRIENDS)) {
|
||||
BLOCKED_URLS = BLOCKED_URLS.concat([
|
||||
BLOCKED_URLS.push(
|
||||
'https://peoplehub.xboxlive.com/users/me/people/social',
|
||||
'https://peoplehub.xboxlive.com/users/me/people/recommendations',
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
// Block all notifications
|
||||
if (blockAllNotifications()) {
|
||||
BLOCKED_URLS.push(
|
||||
'https://notificationinbox.xboxlive.com/',
|
||||
);
|
||||
}
|
||||
|
||||
const xhrPrototype = XMLHttpRequest.prototype;
|
||||
@@ -166,11 +174,13 @@ export function interceptHttpRequests() {
|
||||
};
|
||||
|
||||
xhrPrototype.send = function(...arg) {
|
||||
for (const blocked of BLOCKED_URLS) {
|
||||
if ((this as any)._url.startsWith(blocked)) {
|
||||
if (blocked === 'https://dc.services.visualstudio.com') {
|
||||
for (const url of BLOCKED_URLS) {
|
||||
if ((this as any)._url.startsWith(url)) {
|
||||
if (url === 'https://dc.services.visualstudio.com') {
|
||||
window.setTimeout(clearAllLogs, 1000);
|
||||
}
|
||||
|
||||
BxLogger.warning('Blocked URL', url);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -202,6 +212,7 @@ export function interceptHttpRequests() {
|
||||
// Check blocked URLs
|
||||
for (const blocked of BLOCKED_URLS) {
|
||||
if (url.startsWith(blocked)) {
|
||||
BxLogger.warning('Blocked URL', url);
|
||||
return new Response('{"acc":1,"webResult":{}}', {
|
||||
status: 200,
|
||||
statusText: '200 OK',
|
||||
|
@@ -603,8 +603,8 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||
[BlockFeature.CHAT]: t('chat'),
|
||||
[BlockFeature.FRIENDS]: t('friends-followers'),
|
||||
[BlockFeature.BYOG]: t('byog'),
|
||||
// [BlockFeature.NOTIFICATIONS_INVITES]: ut('Notifications: Invites'),
|
||||
// [BlockFeature.NOTIFICATIONS_ACHIEVEMENTS]: ut('Notifications: Achievements'),
|
||||
[BlockFeature.NOTIFICATIONS_INVITES]: t('notifications') + ': ' + t('invites'),
|
||||
[BlockFeature.NOTIFICATIONS_ACHIEVEMENTS]: t('notifications') + ': ' + t('achievements'),
|
||||
},
|
||||
},
|
||||
|
||||
|
@@ -27,6 +27,9 @@ export const SUPPORTED_LANGUAGES = {
|
||||
};
|
||||
|
||||
const Texts = {
|
||||
"notifications": "Notifications",
|
||||
"invites": "Invites",
|
||||
"achievements": "Achievements",
|
||||
"chat": "Chat",
|
||||
"friends-followers": "Friends and followers",
|
||||
"byog": "Stream your own game",
|
||||
|
@@ -5,6 +5,7 @@ import { Toast } from "./toast";
|
||||
import { PrefKey } from "@/enums/pref-keys";
|
||||
import { getPref, setPref } from "./settings-storages/global-settings-storage";
|
||||
import { LocalDb } from "./local-db/local-db";
|
||||
import { BlockFeature } from "@/enums/pref-values";
|
||||
|
||||
/**
|
||||
* Check for update
|
||||
@@ -155,3 +156,19 @@ export function clearAllData() {
|
||||
|
||||
alert(t('clear-data-success'));
|
||||
}
|
||||
|
||||
export function blockAllNotifications() {
|
||||
const blockFeatures = getPref<BlockFeature[]>(PrefKey.BLOCK_FEATURES);
|
||||
const blockAll = [BlockFeature.FRIENDS, BlockFeature.NOTIFICATIONS_ACHIEVEMENTS, BlockFeature.NOTIFICATIONS_INVITES].every(value => blockFeatures.includes(value));
|
||||
return blockAll;
|
||||
}
|
||||
|
||||
export function blockSomeNotifications() {
|
||||
const blockFeatures = getPref<BlockFeature[]>(PrefKey.BLOCK_FEATURES);
|
||||
if (blockAllNotifications()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const blockSome = [BlockFeature.FRIENDS, BlockFeature.NOTIFICATIONS_ACHIEVEMENTS, BlockFeature.NOTIFICATIONS_INVITES].some(value => blockFeatures.includes(value));
|
||||
return blockSome;
|
||||
}
|
||||
|
Reference in New Issue
Block a user