mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-02 03:16:42 +02:00
Update TrueAchievements button in Guide Menu
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { AppInterface } from "@utils/global";
|
||||
import { BxLogger } from "./bx-logger";
|
||||
import { BX_FLAGS } from "./bx-flags";
|
||||
|
||||
|
||||
export namespace BxEvent {
|
||||
@@ -75,6 +77,8 @@ export namespace BxEvent {
|
||||
|
||||
target.dispatchEvent(event);
|
||||
AppInterface && AppInterface.onEvent(eventName);
|
||||
|
||||
BX_FLAGS.Debug && BxLogger.warning('BxEvent', 'dispatch', eventName, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import { BxLogger } from "./bx-logger";
|
||||
|
||||
type BxFlags = {
|
||||
Debug: boolean;
|
||||
|
||||
CheckForUpdate: boolean;
|
||||
EnableXcloudLogging: boolean;
|
||||
SafariWorkaround: boolean;
|
||||
@@ -20,6 +22,8 @@ type BxFlags = {
|
||||
|
||||
// Setup flags
|
||||
const DEFAULT_FLAGS: BxFlags = {
|
||||
Debug: false,
|
||||
|
||||
CheckForUpdate: true,
|
||||
EnableXcloudLogging: false,
|
||||
SafariWorkaround: true,
|
||||
|
@@ -1,24 +1,43 @@
|
||||
import { BxIcon } from "./bx-icon";
|
||||
import { AppInterface, STATES } from "./global";
|
||||
import { ButtonStyle, CE, createButton, getReactProps } from "./html";
|
||||
import { t } from "./translation";
|
||||
|
||||
export class TrueAchievements {
|
||||
private static $taLink = createButton({
|
||||
private static $link = createButton({
|
||||
label: t('true-achievements'),
|
||||
url: 'https://www.trueachievements.com',
|
||||
url: '#',
|
||||
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
||||
style: ButtonStyle.FOCUSABLE | ButtonStyle.GHOST | ButtonStyle.FULL_WIDTH | ButtonStyle.NORMAL_LINK,
|
||||
onClick: e => {
|
||||
e.preventDefault();
|
||||
|
||||
const dataset = TrueAchievements.$taLink.dataset;
|
||||
TrueAchievements.open(true, dataset.xboxTitleId, dataset.id);
|
||||
},
|
||||
onClick: TrueAchievements.onClick,
|
||||
}) as HTMLAnchorElement;
|
||||
|
||||
static $button = createButton({
|
||||
title: t('true-achievements'),
|
||||
icon: BxIcon.TRUE_ACHIEVEMENTS,
|
||||
style: ButtonStyle.FOCUSABLE | ButtonStyle.FULL_WIDTH,
|
||||
onClick: TrueAchievements.onClick,
|
||||
}) as HTMLAnchorElement;
|
||||
|
||||
private static onClick(e: Event) {
|
||||
e.preventDefault();
|
||||
|
||||
const dataset = TrueAchievements.$link.dataset;
|
||||
TrueAchievements.open(true, dataset.xboxTitleId, dataset.id);
|
||||
}
|
||||
|
||||
private static $hiddenLink = CE<HTMLAnchorElement>('a', {
|
||||
target: '_blank',
|
||||
});
|
||||
|
||||
private static updateLinks(xboxTitleId?: string, id?: string) {
|
||||
TrueAchievements.$link.dataset.xboxTitleId = xboxTitleId;
|
||||
TrueAchievements.$link.dataset.id = id;
|
||||
|
||||
TrueAchievements.$button.dataset.xboxTitleId = xboxTitleId;
|
||||
TrueAchievements.$button.dataset.id = id;
|
||||
}
|
||||
|
||||
static injectAchievementDetailPage($parent: HTMLElement) {
|
||||
const props = getReactProps($parent);
|
||||
if (!props) {
|
||||
@@ -46,17 +65,14 @@ export class TrueAchievements {
|
||||
|
||||
// Found achievement -> add TrueAchievements button
|
||||
if (id) {
|
||||
TrueAchievements.$taLink.dataset.xboxTitleId = xboxTitleId;
|
||||
TrueAchievements.$taLink.dataset.id = id;
|
||||
|
||||
TrueAchievements.$taLink.href = `https://www.trueachievements.com/deeplink/${xboxTitleId}/${id}`;
|
||||
$parent.appendChild(TrueAchievements.$taLink);
|
||||
TrueAchievements.updateLinks(xboxTitleId, id);
|
||||
$parent.appendChild(TrueAchievements.$link);
|
||||
}
|
||||
} catch (e) {};
|
||||
}
|
||||
|
||||
static open(override: boolean, xboxTitleId?: number | string, id?: number | string) {
|
||||
if (!xboxTitleId) {
|
||||
if (!xboxTitleId || xboxTitleId === 'undefined') {
|
||||
xboxTitleId = STATES.currentStream.xboxTitleId || STATES.currentStream.titleInfo?.details.xboxTitleId;
|
||||
}
|
||||
|
||||
@@ -67,7 +83,7 @@ export class TrueAchievements {
|
||||
|
||||
let url = 'https://www.trueachievements.com';
|
||||
if (xboxTitleId) {
|
||||
if (id) {
|
||||
if (id && id !== 'undefined') {
|
||||
url += `/deeplink/${xboxTitleId}/${id}`;
|
||||
} else {
|
||||
url += `/deeplink/${xboxTitleId}`;
|
||||
|
Reference in New Issue
Block a user