From 3d3c199259807812b4cb78c32a843957d30b497f Mon Sep 17 00:00:00 2001 From: ricewind012 <58827198+ricewind012@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:13:56 +0000 Subject: [PATCH] plugin: clean up code --- .gitattributes | 1 - .gitignore | 1 - .gitmodules | 3 + .../steamdesktop => components}/ribbon.tsx | 5 +- frontend/gamelistchange.ts | 15 +++++ frontend/gamelistchangeevent.ts | 5 -- frontend/index.tsx | 22 ++++--- frontend/parts/steamdesktop/actionbutton.tsx | 12 ++-- .../parts/steamdesktop/favoritebutton.tsx | 2 +- frontend/parts/steamdesktop/index.tsx | 59 +++++-------------- frontend/parts/titlebarcontrols.tsx | 4 +- frontend/types | 1 + .../ribbon.scss} | 0 steam-theming-utils.config.js | 15 +---- 14 files changed, 59 insertions(+), 86 deletions(-) create mode 100644 .gitmodules rename frontend/{parts/steamdesktop => components}/ribbon.tsx (93%) create mode 100644 frontend/gamelistchange.ts delete mode 100644 frontend/gamelistchangeevent.ts create mode 160000 frontend/types rename src/shared/{parts/steamdesktop.scss => components/ribbon.scss} (100%) diff --git a/.gitattributes b/.gitattributes index 266459b..3b2b6ef 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ dist linguist-generated -js_dist linguist-generated diff --git a/.gitignore b/.gitignore index fecfb91..bfed360 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ dist .millennium class_maps -frontend/types node_modules package-lock.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4f5f4e7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "frontend/types"] + path = frontend/types + url = https://github.com/ricewind012/steam-sharedjscontext-types diff --git a/frontend/parts/steamdesktop/ribbon.tsx b/frontend/components/ribbon.tsx similarity index 93% rename from frontend/parts/steamdesktop/ribbon.tsx rename to frontend/components/ribbon.tsx index c7b35d5..c812fb7 100644 --- a/frontend/parts/steamdesktop/ribbon.tsx +++ b/frontend/components/ribbon.tsx @@ -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; diff --git a/frontend/gamelistchange.ts b/frontend/gamelistchange.ts new file mode 100644 index 0000000..8a7c5f5 --- /dev/null +++ b/frontend/gamelistchange.ts @@ -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( + k_strGameListChangeEventName, + { + detail: { appid }, + }, + ); + window.dispatchEvent(ev); +} diff --git a/frontend/gamelistchangeevent.ts b/frontend/gamelistchangeevent.ts deleted file mode 100644 index 5b65847..0000000 --- a/frontend/gamelistchangeevent.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const k_GameListChangeEventName = "game-list-change"; - -export interface GameListChangeEvent { - appid: number; -} diff --git a/frontend/index.tsx b/frontend/index.tsx index 4a168c0..28e162a 100644 --- a/frontend/index.tsx +++ b/frontend/index.tsx @@ -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; @@ -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("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); }; } diff --git a/frontend/parts/steamdesktop/actionbutton.tsx b/frontend/parts/steamdesktop/actionbutton.tsx index 431cb4f..0ce67e4 100644 --- a/frontend/parts/steamdesktop/actionbutton.tsx +++ b/frontend/parts/steamdesktop/actionbutton.tsx @@ -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, @@ -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 = { generic: [ "#StreamingClient_AnotherDevice", "#StreamingClient_LinkDesc_Generic", @@ -103,7 +105,7 @@ function RemotePlayAnywhereContextMenuItem({ overview, onSelected }) { return null; } - const eCategory = (() => { + const eCategory: MobileCategory_t = (() => { switch (vecCategories.length) { case 1: return vecCategories[0]; @@ -119,12 +121,12 @@ function RemotePlayAnywhereContextMenuItem({ overview, onSelected }) { return ( -
+ <>
{strDevice}
{strLinkDesc}
-
+
); } diff --git a/frontend/parts/steamdesktop/favoritebutton.tsx b/frontend/parts/steamdesktop/favoritebutton.tsx index 45523ce..937f505 100644 --- a/frontend/parts/steamdesktop/favoritebutton.tsx +++ b/frontend/parts/steamdesktop/favoritebutton.tsx @@ -1,4 +1,4 @@ -import { RibbonGameSectionButton, RibbonButton } from "./ribbon"; +import { RibbonGameSectionButton, RibbonButton } from "../../components/ribbon"; interface FavoriteButtonState { text: string; diff --git a/frontend/parts/steamdesktop/index.tsx b/frontend/parts/steamdesktop/index.tsx index 153fe3e..ff535a0 100644 --- a/frontend/parts/steamdesktop/index.tsx +++ b/frontend/parts/steamdesktop/index.tsx @@ -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; @@ -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; @@ -163,7 +132,9 @@ export class SteamDesktop extends PartComponentBase { const { details } = appDetailsStore.GetAppData(appid); showModal( - , + + + , this.props.wnd, ); } @@ -173,14 +144,14 @@ export class SteamDesktop extends PartComponentBase { } 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); }); } diff --git a/frontend/parts/titlebarcontrols.tsx b/frontend/parts/titlebarcontrols.tsx index aa2b781..6b70676 100644 --- a/frontend/parts/titlebarcontrols.tsx +++ b/frontend/parts/titlebarcontrols.tsx @@ -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 ( - + ); diff --git a/frontend/types b/frontend/types new file mode 160000 index 0000000..4f42763 --- /dev/null +++ b/frontend/types @@ -0,0 +1 @@ +Subproject commit 4f427638daf95996a387d60ad593b8ce4c4d3269 diff --git a/src/shared/parts/steamdesktop.scss b/src/shared/components/ribbon.scss similarity index 100% rename from src/shared/parts/steamdesktop.scss rename to src/shared/components/ribbon.scss diff --git a/steam-theming-utils.config.js b/steam-theming-utils.config.js index 2d31d5b..d62c3b0 100644 --- a/steam-theming-utils.config.js +++ b/steam-theming-utils.config.js @@ -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"], }, };