diff --git a/src/index.ts b/src/index.ts index 1115dbc..f5ce570 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,8 +92,8 @@ if (BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') { throw new Error('[Better xCloud] Executing workaround for Safari'); } -// Automatically reload the page when running into the "We are sorry..." error message window.addEventListener('load', e => { + // Automatically reload the page when running into the "We are sorry..." error message window.setTimeout(() => { if (document.body.classList.contains('legacyBackground')) { // Has error message -> reload page @@ -102,18 +102,29 @@ window.addEventListener('load', e => { window.location.reload(true); } }, 3000); - }); -// Hide "Play with Friends" skeleton section -if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) { - document.addEventListener('readystatechange', e => { - if (document.readyState === 'interactive') { - const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest('div[class*=HomePage-module]') as HTMLElement; - $parent && ($parent.style.display = 'none'); - } - }) -} +document.addEventListener('readystatechange', e => { + if (document.readyState !== 'interactive') { + return; + } + + STATES.isSignedIn = (window as any).xbcUser.isSignedIn; + + if (STATES.isSignedIn) { + // Preload Remote Play + getPref(PrefKey.REMOTE_PLAY_ENABLED) && BX_FLAGS.PreloadRemotePlay && RemotePlay.preload(); + } else { + // Show Settings button in the header when not signed + HeaderSection.watchHeader(); + } + + // Hide "Play with Friends" skeleton section + if (getPref(PrefKey.UI_HIDE_SECTIONS).includes(UiSection.FRIENDS)) { + const $parent = document.querySelector('div[class*=PlayWithFriendsSkeleton]')?.closest('div[class*=HomePage-module]') as HTMLElement; + $parent && ($parent.style.display = 'none'); + } +}) window.BX_EXPOSED = BxExposed; @@ -342,9 +353,6 @@ function main() { BxLogger.info('startPointerServer', 'Port', STATES.pointerServerPort.toString()); } - // Preload Remote Play - getPref(PrefKey.REMOTE_PLAY_ENABLED) && BX_FLAGS.PreloadRemotePlay && RemotePlay.preload(); - // Show wait time in game card getPref(PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME) && GameTile.setup(); } diff --git a/src/modules/ui/global-settings.ts b/src/modules/ui/global-settings.ts index 9bb1fec..54ff303 100644 --- a/src/modules/ui/global-settings.ts +++ b/src/modules/ui/global-settings.ts @@ -162,7 +162,7 @@ export function setupSettingsUi() { } // "Stream settings" button - topButtons.push(createButton({ + (STATES.supportedRegion && STATES.isSignedIn) && topButtons.push(createButton({ label: t('stream-settings'), icon: BxIcon.STREAM_SETTINGS, style: ButtonStyle.FULL_WIDTH | ButtonStyle.FOCUSABLE, @@ -228,6 +228,11 @@ export function setupSettingsUi() { // Render settings for (let groupLabel in SETTINGS_UI) { + // Don't render other settings when not signed in + if (groupLabel !== 'Better xCloud' && (!STATES.supportedRegion || !STATES.isSignedIn)) { + continue; + } + const $group = CE('span', {'class': 'bx-settings-group-label'}, groupLabel); // Render note diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 055fa51..4d4f7aa 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -28,7 +28,7 @@ type BxStates = { serverRegions: any; selectedRegion: any; gsToken: string; - + isSignedIn: boolean; isPlaying: boolean; appContext: any | null; diff --git a/src/utils/global.ts b/src/utils/global.ts index 3551466..88646d0 100644 --- a/src/utils/global.ts +++ b/src/utils/global.ts @@ -17,6 +17,7 @@ export const STATES: BxStates = { serverRegions: {}, selectedRegion: {}, gsToken: '', + isSignedIn: false, isPlaying: false, appContext: {}, diff --git a/src/utils/preferences.ts b/src/utils/preferences.ts index a7b586a..c1c1b0d 100644 --- a/src/utils/preferences.ts +++ b/src/utils/preferences.ts @@ -128,7 +128,7 @@ export class Preferences { }, [PrefKey.SERVER_BYPASS_RESTRICTION]: { label: t('bypass-region-restriction'), - note: t('use-this-at-your-own-risk'), + note: '⚠️ ' + t('use-this-at-your-own-risk'), default: 'off', options: Object.assign({ 'off': t('off'),