Port the rest of the code

This commit is contained in:
redphx
2024-04-23 17:55:52 +07:00
parent 27a277309b
commit be0cbff344
30 changed files with 4338 additions and 234 deletions

40
src/utils/history.ts Normal file
View File

@@ -0,0 +1,40 @@
import { BxEvent } from "../modules/bx-event";
import { LoadingScreen } from "../modules/loading-screen";
import { RemotePlay } from "../modules/remote-play";
import { checkHeader } from "../modules/ui/header";
export function patchHistoryMethod(type: 'pushState' | 'replaceState') {
const orig = window.history[type];
return function(...args: any[]) {
BxEvent.dispatch(window, BxEvent.POPSTATE, {
arguments: args,
});
// @ts-ignore
return orig.apply(this, arguments);
};
};
export function onHistoryChanged(e: PopStateEvent) {
// @ts-ignore
if (e && e.arguments && e.arguments[0] && e.arguments[0].origin === 'better-xcloud') {
return;
}
setTimeout(RemotePlay.detect, 10);
const $settings = document.querySelector('.bx-settings-container');
if ($settings) {
$settings.classList.add('bx-gone');
}
// Hide Remote Play popup
RemotePlay.detachPopup();
LoadingScreen.reset();
setTimeout(checkHeader, 2000);
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
}