Skip to content

Commit

Permalink
feat(plugin): add account sectionin profiles tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ricewind012 committed Feb 7, 2025
1 parent 274ac79 commit a2fb23c
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 19 deletions.
7 changes: 5 additions & 2 deletions frontend/components/ribbon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import type { FC, ReactNode } from "react";

import { IconButton } from "./iconbutton";
import { BuildClassName, PartComponentBase } from "../shared";
import { Localize } from "../modules/localization";

interface RibbonButtonProps {
/** Arguments for localization. */
args?: string[];
disabled?: boolean;
/** Icon name for {@link IconButton}. */
icon: string;
Expand All @@ -16,7 +19,7 @@ interface RibbonButtonProps {
}

export function RibbonButton(props: RibbonButtonProps) {
const { disabled, icon, text, vertical, onClick, onArrowClick } = props;
const { args, disabled, icon, text, vertical, onClick, onArrowClick } = props;
const strContainerClassName = BuildClassName([
"ribbon-button-container",
disabled && "disabled",
Expand All @@ -35,7 +38,7 @@ export function RibbonButton(props: RibbonButtonProps) {
onContextMenu={onArrowClick}
>
<IconButton name={icon} />
{LocalizationManager.LocalizeIfToken(text)}
{Localize(text, ...(args || []))}
</div>
{onArrowClick && (
<div className={strArrowClassName} onClick={onArrowClick} />
Expand Down
2 changes: 2 additions & 0 deletions frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { DispatchTabChange } from "./events/tabchange";
import { DispatchGameListChange } from "./events/gamelistchange";

declare global {
const App: any;
const appStore: any;
const appDetailsStore: any;
const badgeStore: any;
const collectionStore: any;
const g_PopupManager: CPopupManager;
const LocalizationManager: any;
const loginStore: any;
const MainWindowBrowserManager: any;
const settingsStore: any;
const SteamUIStore: any;
Expand Down
28 changes: 28 additions & 0 deletions frontend/modules/parentalfeatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { findModuleExport } from "@steambrew/client";

// TODO: are the ones in SteamTracking outdated ? why would they use Max ?
export enum EParentalFeature {
Invalid,
Store,
Community,
Profile,
Friends,
News,
Trading,
Settings,
Console,
Browser,
ParentalSetup,
Library,
Test,
SiteLicense,
KioskMode,
Max,
}

interface ParentalFeaturesManager {
BIsFeatureBlocked(feature: EParentalFeature): boolean;
}

export const CParentalFeaturesManager: ParentalFeaturesManager =
findModuleExport((e) => e.GetFeatureBlockReason);
104 changes: 87 additions & 17 deletions frontend/parts/steamdesktop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
GAME_LIST_CHANGE_EVENT_NAME,
} from "../../events/gamelistchange";

import {
EParentalFeature,
CParentalFeaturesManager,
} from "../../modules/parentalfeatures";
import { BIsChinaLauncher, Config } from "../../modules/config";
import { CKioskModeManager } from "../../modules/kioskmodemgr";
import { AppGameInfo } from "../../modules/appgameinfo";
Expand Down Expand Up @@ -120,6 +124,47 @@ function GetAppLinks(appid: number) {
return vecLinks.filter(Boolean);
}

function GetAccountEntries() {
const { strAccountBalance, strAccountName } = App.GetCurrentUser();
const { secureComputer } = loginStore;

return [
{
feature: EParentalFeature.Profile,
icon: "info",
text: "#Menu_ViewMyProfile",
url: "steam://url/SteamIDMyProfile",
},
{
args: [strAccountName],
feature: EParentalFeature.Max,
icon: "info",
text: "#Menu_ViewMyAccount",
url: "steam://url/StoreAccount",
},
{
feature: EParentalFeature.Max,
icon: "store",
text: "#Menu_StorePreferences",
url: "steam://url/SteamPreferences",
},
{
args: [strAccountBalance],
feature: EParentalFeature.Store,
icon: "store",
text: "#Menu_ViewMyWallet",
url: "steam://url/StoreAddFundsPage",
},
{
disabled: !secureComputer,
icon: "update",
text: "#Menu_ChangeAccount",
url: "steam://changeuser",
},
{ icon: "nav-back", text: "#Menu_Logout", url: "steam://signout" },
];
}

function GetDefaltTabState() {
const [eDefaultTab] = settingsStore.GetClientSetting("start_page");
return GetESuperNavTabFromSetting(eDefaultTab);
Expand Down Expand Up @@ -192,6 +237,44 @@ export class SteamDesktop extends PartComponentBase<SteamDesktopState> {
return <RibbonContainer />;
}

const accountSection = GetAccountEntries().map((e) => {
const { args, icon, feature, text, url } = e;
const onClick = () => {
SteamClient.URL.ExecuteSteamURL(url);
};
const disabled =
e.disabled || CParentalFeaturesManager.BIsFeatureBlocked(feature);

return (
<RibbonButton
args={args}
icon={icon}
disabled={disabled}
text={text}
onClick={onClick}
/>
);
});
const browserSection = (
<RibbonSection title="Browser">
<RibbonButton
icon="nav-back"
text="Go back"
onClick={this.OnGoBackButtonClick}
/>
<RibbonButton
icon="nav-forward"
text="Go forward"
onClick={this.OnGoForwardButtonClick}
/>
<RibbonButton
icon="update"
text="Reload"
onClick={this.OnReloadButtonClick}
/>
</RibbonSection>
);

switch (tab) {
case ESuperNavTab.Library: {
const links = GetAppLinks(appid).map((e) => {
Expand Down Expand Up @@ -234,23 +317,10 @@ export class SteamDesktop extends PartComponentBase<SteamDesktopState> {
default:
return (
<RibbonContainer>
<RibbonSection title="Browser">
<RibbonButton
icon="nav-back"
text="Go back"
onClick={this.OnGoBackButtonClick}
/>
<RibbonButton
icon="nav-forward"
text="Go forward"
onClick={this.OnGoForwardButtonClick}
/>
<RibbonButton
icon="update"
text="Reload"
onClick={this.OnReloadButtonClick}
/>
</RibbonSection>
{browserSection}
{tab === ESuperNavTab.Profile && (
<RibbonSection title="Account">{accountSection}</RibbonSection>
)}
</RibbonContainer>
);
}
Expand Down

0 comments on commit a2fb23c

Please sign in to comment.