mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-07 08:07:18 +02:00
Optimize Guide Menu's buttons
This commit is contained in:
parent
ad0be634d2
commit
26b28564cc
11
src/assets/css/guide-menu.styl
Normal file
11
src/assets/css/guide-menu.styl
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
.bx-guide-home-buttons[data-is-playing="true"] {
|
||||||
|
button[data-state='normal'] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.bx-guide-home-buttons[data-is-playing="false"] {
|
||||||
|
button[data-state='playing'] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
@import 'loading-screen.styl';
|
@import 'loading-screen.styl';
|
||||||
@import 'remote-play.styl';
|
@import 'remote-play.styl';
|
||||||
@import 'web-components.styl';
|
@import 'web-components.styl';
|
||||||
|
@import 'guide-menu.styl';
|
||||||
|
|
||||||
@import 'stream.styl';
|
@import 'stream.styl';
|
||||||
@import 'number-stepper.styl';
|
@import 'number-stepper.styl';
|
||||||
|
@ -41,6 +41,9 @@ export class GuideMenu {
|
|||||||
onClick: e => {
|
onClick: e => {
|
||||||
AppInterface.closeApp();
|
AppInterface.closeApp();
|
||||||
},
|
},
|
||||||
|
attributes: {
|
||||||
|
'data-state': 'normal',
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
reloadPage: createButton({
|
reloadPage: createButton({
|
||||||
@ -64,69 +67,63 @@ export class GuideMenu {
|
|||||||
onClick: e => {
|
onClick: e => {
|
||||||
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
||||||
},
|
},
|
||||||
|
attributes: {
|
||||||
|
'data-state': 'playing',
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
static #renderButtons(buttons: HTMLElement[]) {
|
static #$renderedButtons: HTMLElement;
|
||||||
const $div = CE('div', {});
|
|
||||||
|
|
||||||
for (const $button of buttons) {
|
static #renderButtons() {
|
||||||
$div.appendChild($button);
|
if (GuideMenu.#$renderedButtons) {
|
||||||
|
return GuideMenu.#$renderedButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const $div = CE('div', {
|
||||||
|
class: 'bx-guide-home-buttons',
|
||||||
|
});
|
||||||
|
|
||||||
|
const buttons = [
|
||||||
|
GuideMenu.#BUTTONS.scriptSettings,
|
||||||
|
GuideMenu.#BUTTONS.reloadPage,
|
||||||
|
GuideMenu.#BUTTONS.backToHome,
|
||||||
|
AppInterface && GuideMenu.#BUTTONS.closeApp,
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const $button of buttons) {
|
||||||
|
$button && $div.appendChild($button);
|
||||||
|
}
|
||||||
|
|
||||||
|
GuideMenu.#$renderedButtons = $div;
|
||||||
return $div;
|
return $div;
|
||||||
}
|
}
|
||||||
|
|
||||||
static #injectHome($root: HTMLElement) {
|
static #injectHome($root: HTMLElement, isPlaying = false) {
|
||||||
// Find the last divider
|
// Find the element to add buttons to
|
||||||
const $dividers = $root.querySelectorAll('div[class*=Divider-module__divider]');
|
let $target: HTMLElement | null = null;
|
||||||
if (!$dividers) {
|
if (isPlaying) {
|
||||||
return;
|
// Quit button
|
||||||
}
|
$target = $root.querySelector('a[class*=QuitGameButton]');
|
||||||
|
|
||||||
const buttons: HTMLElement[] = [];
|
|
||||||
|
|
||||||
// "Better xCloud" button
|
|
||||||
buttons.push(GuideMenu.#BUTTONS.scriptSettings);
|
|
||||||
|
|
||||||
// "App settings" button
|
|
||||||
AppInterface && buttons.push(GuideMenu.#BUTTONS.appSettings);
|
|
||||||
|
|
||||||
// "Reload page" button
|
|
||||||
buttons.push(GuideMenu.#BUTTONS.reloadPage);
|
|
||||||
|
|
||||||
// "Close app" buttons
|
|
||||||
AppInterface && buttons.push(GuideMenu.#BUTTONS.closeApp);
|
|
||||||
|
|
||||||
const $buttons = GuideMenu.#renderButtons(buttons);
|
|
||||||
|
|
||||||
const $lastDivider = $dividers[$dividers.length - 1];
|
|
||||||
$lastDivider.insertAdjacentElement('afterend', $buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
static #injectHomePlaying($root: HTMLElement) {
|
|
||||||
const $btnQuit = $root.querySelector('a[class*=QuitGameButton]');
|
|
||||||
if (!$btnQuit) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const buttons: HTMLElement[] = [];
|
|
||||||
|
|
||||||
buttons.push(GuideMenu.#BUTTONS.scriptSettings);
|
|
||||||
AppInterface && buttons.push(GuideMenu.#BUTTONS.appSettings);
|
|
||||||
|
|
||||||
// Reload page
|
|
||||||
buttons.push(GuideMenu.#BUTTONS.reloadPage);
|
|
||||||
|
|
||||||
// Back to home
|
|
||||||
buttons.push(GuideMenu.#BUTTONS.backToHome);
|
|
||||||
|
|
||||||
const $buttons = GuideMenu.#renderButtons(buttons);
|
|
||||||
$btnQuit.insertAdjacentElement('afterend', $buttons);
|
|
||||||
|
|
||||||
// Hide xCloud's Home button
|
// Hide xCloud's Home button
|
||||||
const $btnXcloudHome = $root.querySelector('div[class^=HomeButtonWithDivider]') as HTMLElement;
|
const $btnXcloudHome = $root.querySelector('div[class^=HomeButtonWithDivider]') as HTMLElement;
|
||||||
$btnXcloudHome && ($btnXcloudHome.style.display = 'none');
|
$btnXcloudHome && ($btnXcloudHome.style.display = 'none');
|
||||||
|
} else {
|
||||||
|
// Last divider
|
||||||
|
const $dividers = $root.querySelectorAll('div[class*=Divider-module__divider]');
|
||||||
|
if ($dividers) {
|
||||||
|
$target = $dividers[$dividers.length - 1] as HTMLElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$target) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const $buttons = GuideMenu.#renderButtons();
|
||||||
|
$buttons.dataset.isPlaying = isPlaying.toString();
|
||||||
|
$target.insertAdjacentElement('afterend', $buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #onShown(e: Event) {
|
static async #onShown(e: Event) {
|
||||||
@ -134,13 +131,7 @@ export class GuideMenu {
|
|||||||
|
|
||||||
if (where === GuideMenuTab.HOME) {
|
if (where === GuideMenuTab.HOME) {
|
||||||
const $root = document.querySelector('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]') as HTMLElement;
|
const $root = document.querySelector('#gamepass-dialog-root div[role=dialog] div[role=tabpanel] div[class*=HomeLandingPage]') as HTMLElement;
|
||||||
if ($root) {
|
$root && GuideMenu.#injectHome($root, STATES.isPlaying);
|
||||||
if (STATES.isPlaying) {
|
|
||||||
GuideMenu.#injectHomePlaying($root);
|
|
||||||
} else {
|
|
||||||
GuideMenu.#injectHome($root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user