Skip to content

Commit

Permalink
plugin: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ricewind012 committed Jan 28, 2025
1 parent e114445 commit 3d3c199
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 86 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dist linguist-generated
js_dist linguist-generated
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dist
.millennium
class_maps
frontend/types
node_modules
package-lock.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "frontend/types"]
path = frontend/types
url = https://github.com/ricewind012/steam-sharedjscontext-types
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FC, ReactNode } from "react";
import { IconButton } from "../../components/iconbutton";
import { BuildClassName, PartComponentBase } from "../../shared";

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

interface RibbonButtonProps {
disabled?: boolean;
Expand Down
15 changes: 15 additions & 0 deletions frontend/gamelistchange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const k_strGameListChangeEventName = "game-list-change";

export interface GameListChangeEvent {
appid: number;
}

export function DispatchGameListChange(appid: number) {
const ev = new CustomEvent<GameListChangeEvent>(
k_strGameListChangeEventName,
{
detail: { appid },
},
);
window.dispatchEvent(ev);
}
5 changes: 0 additions & 5 deletions frontend/gamelistchangeevent.ts

This file was deleted.

22 changes: 10 additions & 12 deletions frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { render } from "react-dom";
import * as parts from "./parts";
import { CLog } from "./logger";
import { classes, waitForElement } from "./shared";
import type { SteamPopup } from "./types/sharedjscontext/normal";
import type { GameListChangeEvent } from "./gamelistchangeevent";
import type { CPopupManager, SteamPopup } from "./types/normal";
import { DispatchGameListChange } from "./gamelistchange";

declare global {
const appStore: any;
const appDetailsStore: any;
const badgeStore: any;
const collectionStore: any;
const g_PopupManager: CPopupManager;
const LocalizationManager: any;
const MainWindowBrowserManager: any;
const SteamUIStore: any;
const StoreItemCache: any;
Expand Down Expand Up @@ -72,26 +74,22 @@ function PatchUIStore(popup: SteamPopup) {
const logger = new CLog("PatchUIStore");
const doc = popup.m_popup.document.documentElement;

store.SetGameListSelection = async function (section: string, appId: number) {
const ev = new CustomEvent<GameListChangeEvent>("game-list-change", {
detail: { appid: appId },
});
window.dispatchEvent(ev);

const app = appStore.GetAppOverviewByAppID(appId);
store.SetGameListSelection = async function (section: string, appid: number) {
const app = appStore.GetAppOverviewByAppID(appid);
const iconFilePath = urlStore.BuildCachedLibraryAssetURL(
appId,
appid,
`${app.icon_hash}.jpg`,
);
const url = app.icon_data
? `data:image/${app.icon_data_format};base64,${app.icon_data}`
: iconFilePath;

DispatchGameListChange(appid);
doc.style.setProperty("--library_game-icon", `url("${url}")`);
doc.style.setProperty("--library_game-name", `"${app.display_name}"`);
logger.Log("Called CUIStore.SetGameListSelection(%o, %s)", section, appId);
logger.Log("Called CUIStore.SetGameListSelection(%o, %s)", section, appid);

return orig.call(this, section, appId);
return orig.call(this, section, appid);
};
}

Expand Down
12 changes: 7 additions & 5 deletions frontend/parts/steamdesktop/actionbutton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { showContextMenu, sleep } from "@steambrew/client";

import { RibbonButton, RibbonGameSectionButton } from "../../components/ribbon";
import { classes } from "../../shared";
import { RibbonButton, RibbonGameSectionButton } from "./ribbon";

import {
ContextMenu,
Expand All @@ -17,9 +17,11 @@ import { Config } from "../../modules/config";
import { Localize } from "../../modules/localization";
import { GetAppMobileCategories } from "../../modules/remoteplay";

type MobileCategory_t = "generic" | "mobile" | "phone" | "tablet" | "tv";

const k_ELaunchSource_2ftLibraryDetails = 100;

const mapCategoryLocTokens = {
const mapCategoryLocTokens: Record<MobileCategory_t, string[]> = {
generic: [
"#StreamingClient_AnotherDevice",
"#StreamingClient_LinkDesc_Generic",
Expand Down Expand Up @@ -103,7 +105,7 @@ function RemotePlayAnywhereContextMenuItem({ overview, onSelected }) {
return null;
}

const eCategory = (() => {
const eCategory: MobileCategory_t = (() => {
switch (vecCategories.length) {
case 1:
return vecCategories[0];
Expand All @@ -119,12 +121,12 @@ function RemotePlayAnywhereContextMenuItem({ overview, onSelected }) {

return (
<StreamingContextMenuItem onSelected={onSelected}>
<div>
<>
<div>{strDevice}</div>
<div className={classes.appactionbutton.RemotePlayAnywhereDescription}>
{strLinkDesc}
</div>
</div>
</>
</StreamingContextMenuItem>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/parts/steamdesktop/favoritebutton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RibbonGameSectionButton, RibbonButton } from "./ribbon";
import { RibbonGameSectionButton, RibbonButton } from "../../components/ribbon";

interface FavoriteButtonState {
text: string;
Expand Down
59 changes: 15 additions & 44 deletions frontend/parts/steamdesktop/index.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,25 @@
import { findModuleByExport, showModal } from "@steambrew/client";
import { ModalPosition, showModal } from "@steambrew/client";

import { PartComponentBase } from "../../shared";
import {
k_GameListChangeEventName,
RibbonButton,
RibbonContainer,
RibbonSection,
} from "../../components/ribbon";
import {
k_strGameListChangeEventName,
type GameListChangeEvent,
} from "../../gamelistchangeevent";
} from "../../gamelistchange";
import { PartComponentBase } from "../../shared";

import { BIsChinaLauncher, Config } from "../../modules/config";
import { CKioskModeManager } from "../../modules/kioskmodemgr";
import { AppGameInfo } from "../../modules/appgameinfo";

import { RibbonButton, RibbonContainer, RibbonSection } from "./ribbon";
import { FavoriteButton } from "./favoritebutton";
import { ActionButton } from "./actionbutton";

const k_EAppType_Demo = 8;

interface StoreItemDataRequest {
include_assets: boolean;
include_release: boolean;
include_platforms: boolean;
include_all_purchase_options: boolean;
include_screenshots: boolean;
include_trailers: boolean;
include_ratings: boolean;
include_tag_count: boolean;
include_reviews: boolean;
include_basic_info: boolean;
include_supported_languages: boolean;
include_full_description: boolean;
include_included_items: boolean;
include_assets_without_overrides: boolean;
apply_user_filters: boolean;
include_links: boolean;
}

const some_hard_to_get_fn: (
unAppID: number,
param1: StoreItemDataRequest,
param2: any,
) => any[] = (() => {
const mod = findModuleByExport((e) =>
e.toString?.().includes("useStoreItemCache: unmounting"),
);
// there are 2 of these, but the first one is correct
const key = Object.keys(mod).find((func) =>
mod[func].toString().match(/^function \w\(e,t,r\){return \w\(e,0,t,r\)}$/),
);

return mod[key];
})();

interface LibraryLink {
label: string;
icon: string;
Expand Down Expand Up @@ -80,7 +49,7 @@ function GetAppLinks(appid: number) {

const { app_type: eAppType, optional_parent_app_id: unParentAppID } =
overview;
const bIsDemo = k_EAppType_Demo === eAppType;
const bIsDemo = eAppType === k_EAppType_Demo;
const actual_appid =
bIsDemo && unParentAppID ? unParentAppID : overview.appid;

Expand Down Expand Up @@ -163,7 +132,9 @@ export class SteamDesktop extends PartComponentBase<SteamDesktopState> {
const { details } = appDetailsStore.GetAppData(appid);

showModal(
<AppGameInfo expand={true} overview={overview} details={details} />,
<ModalPosition>
<AppGameInfo expand={true} overview={overview} details={details} />
</ModalPosition>,
this.props.wnd,
);
}
Expand All @@ -173,14 +144,14 @@ export class SteamDesktop extends PartComponentBase<SteamDesktopState> {
}

componentDidMount() {
window.addEventListener(k_GameListChangeEventName, (ev) => {
window.addEventListener(k_strGameListChangeEventName, (ev) => {
this.OnGameListChangeEvent(ev);
});
}

// TODO: i bet this doesn't actually work
componentWillUnmount() {
window.removeEventListener(k_GameListChangeEventName, (ev) => {
window.removeEventListener(k_strGameListChangeEventName, (ev) => {
this.OnGameListChangeEvent(ev);
});
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/parts/titlebarcontrols.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { ToolTip } from "../modules/tooltip";

export class TitleBarControls extends PartComponentBase {
render() {
const content = Localize("#Menu_Support");
const text = Localize("#Menu_Support");
const url = urlStore.GetHelpURL();
const onClick = () => {
SteamClient.System.OpenInSystemBrowser(url);
};

return (
<ToolTip bNavStop={true} direction="bottom" toolTipContent={content}>
<ToolTip direction="bottom" toolTipContent={text}>
<IconButton name="help" onClick={onClick} />
</ToolTip>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/types
Submodule types added at 4f4276
File renamed without changes.
15 changes: 2 additions & 13 deletions steam-theming-utils.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
/** @type {import("steam-theming-utils").Config} */
export default {
paths: {
classMaps: "class_maps",
dist: "dist",
src: {
client: "src",
},
ignore: {
client: ["shared"],
},
},
sass: {
use: true,
options: {},
ignore: {
client: ["shared"],
},
};

0 comments on commit 3d3c199

Please sign in to comment.