From a1f0be2715b0188deba0585f00c29d2c7f82ec2f Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 14 Jan 2025 18:28:03 -0700 Subject: [PATCH] Update types and move extensions to component editor All Activities, DM Favorites, Platform Icons --- package.json | 2 +- pnpm-lock.yaml | 10 +++--- src/allActivities/index.ts | 13 ++------ src/allActivities/manifest.json | 4 +-- src/allActivities/webpackModules/icons.tsx | 13 ++++++-- src/dmFavorites/index.ts | 14 ++------ src/dmFavorites/manifest.json | 4 +-- src/dmFavorites/webpackModules/icon.tsx | 5 ++- src/platformIcons/index.ts | 37 +++------------------- src/platformIcons/manifest.json | 4 +-- src/platformIcons/webpackModules/icons.tsx | 28 +++++++++++++++- 11 files changed, 63 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 8e3fc7e..952f1a8 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,6 @@ "typescript": "^5.3.2" }, "dependencies": { - "@moonlight-mod/types": "^1.3.5" + "@moonlight-mod/types": "^1.3.6" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6afc103..4203a9e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@moonlight-mod/types': - specifier: ^1.3.5 - version: 1.3.5 + specifier: ^1.3.6 + version: 1.3.6 devDependencies: '@electron/asar': specifier: ^3.2.8 @@ -252,8 +252,8 @@ packages: '@moonlight-mod/moonmap@1.0.3': resolution: {integrity: sha512-G7pwvrcVDimc388IX6VZFzBXpbuyvqbJ+w9/v+MUIc8P7dADJXQ9YkBWvobtRc6eaBBl1FWUwTeU8oobbxLVag==} - '@moonlight-mod/types@1.3.5': - resolution: {integrity: sha512-zUZtk+rAxkpv9tl68t1VGBhG9bW2GB8v+rNtTjtgreXilM8Ok8cUH6afNMxUmxL0uiXg/EfnieA/NYf6Fb97tQ==} + '@moonlight-mod/types@1.3.6': + resolution: {integrity: sha512-j8mkRf5ek/9ZMIAvhmNptC8D2H+hc8b9n6JCsMvcmCNC58Q5Wwn8XeGwEllYpzXhRwTQbEO7tZgPRKJ7UxI0Uw==} '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -1387,7 +1387,7 @@ snapshots: '@moonlight-mod/moonmap@1.0.3': {} - '@moonlight-mod/types@1.3.5': + '@moonlight-mod/types@1.3.6': dependencies: '@moonlight-mod/lunast': 1.0.0 '@moonlight-mod/mappings': 1.0.10(@moonlight-mod/lunast@1.0.0)(@moonlight-mod/moonmap@1.0.3) diff --git a/src/allActivities/index.ts b/src/allActivities/index.ts index 03490e9..ce63273 100644 --- a/src/allActivities/index.ts +++ b/src/allActivities/index.ts @@ -26,17 +26,6 @@ export const patches: Patch[] = [ match: /\(0,\i\.uniqWith\)/, replacement: "((inp)=>inp)" } - }, - - // Icons - { - find: ".lostPermission", - replace: { - match: /name:null==\i\?(\(0,\i\.jsx\))\("span"/, - replacement: (orig, createElement) => - `children:${createElement}(require("allActivities_icons").default,{user:arguments[0].user}),${orig}` - }, - prerequisite: () => moonlight.getConfigOption("allActivities", "icons") ?? true } ]; @@ -45,12 +34,14 @@ export const webpackModules: Record = { dependencies: [{ id: "react" }, { ext: "spacepack", id: "spacepack" }] }, icons: { + entrypoint: true, dependencies: [ { ext: "spacepack", id: "spacepack" }, { id: "react" }, { ext: "common", id: "stores" }, { id: "discord/Constants" }, { id: "discord/components/common/index" }, + { ext: "componentEditor", id: "memberList" }, 'applicationStreamingPreviewWrapper:"applicationStreamingPreviewWrapper_' ] } diff --git a/src/allActivities/manifest.json b/src/allActivities/manifest.json index 66ab579..9a15101 100644 --- a/src/allActivities/manifest.json +++ b/src/allActivities/manifest.json @@ -1,7 +1,7 @@ { "$schema": "https://moonlight-mod.github.io/manifest.schema.json", "id": "allActivities", - "version": "1.0.1", + "version": "1.0.2", "meta": { "name": "All Activities", "tagline": "Shows all activities in user popouts, and optionally icons in the member list", @@ -17,6 +17,6 @@ "advice": "reload" } }, - "dependencies": ["spacepack", "common"], + "dependencies": ["spacepack", "common", "componentEditor"], "apiLevel": 2 } diff --git a/src/allActivities/webpackModules/icons.tsx b/src/allActivities/webpackModules/icons.tsx index e42acde..f589a9c 100644 --- a/src/allActivities/webpackModules/icons.tsx +++ b/src/allActivities/webpackModules/icons.tsx @@ -3,6 +3,7 @@ import spacepack from "@moonlight-mod/wp/spacepack_spacepack"; import { Tooltip } from "@moonlight-mod/wp/discord/components/common/index"; import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux"; import { ApplicationStore, GameStore, UserStore } from "@moonlight-mod/wp/common_stores"; +import MemberList from "@moonlight-mod/wp/componentEditor_memberList"; // FIXME: mappings const { ActivityTypes, PlatformTypes } = spacepack.require("discord/Constants"); @@ -33,7 +34,12 @@ type ActivityIconIconProps = { function ActivityIconIcon({ card, icon }: ActivityIconIconProps) { return ( - + {(tooltipProps: any) => } ); @@ -78,7 +84,7 @@ function ActivityIcon({ user, currentUser, activity }: ActivityIconProps) { return null; } -export default function ActivityIcons({ user }: ActivityIconsProps) { +function ActivityIcons({ user }: ActivityIconsProps) { const currentUser = useStateFromStores([UserStore], () => UserStore.getCurrentUser()); const { live } = useUserProfileActivity(user.id); @@ -90,3 +96,6 @@ export default function ActivityIcons({ user }: ActivityIconsProps) { ); } + +if (moonlight.getConfigOption("allActivities", "icons") ?? true) + MemberList.addItem("activityIcons", ActivityIcons); diff --git a/src/dmFavorites/index.ts b/src/dmFavorites/index.ts index 41a101c..210cdc1 100644 --- a/src/dmFavorites/index.ts +++ b/src/dmFavorites/index.ts @@ -8,16 +8,6 @@ export const patches: Patch[] = [ match: "isFavorite:!1,", replacement: `isFavorite:((require("common_stores").UserGuildSettingsStore.getChannelOverrides("null")[arguments[0].id]??{}).flags&2048)!==0,` } - }, - - // icon indicator - { - find: ".interactiveSystemDM]:", - replace: { - match: /:null,((\(0,(\i)\.jsx\))\(\i,{"aria-label":)/, - replacement: (_, orig, createElement, ReactJSX) => - `:null,${createElement}(require("dmFavorites_icon")?.default??${ReactJSX}.Fragment,arguments[0]),${orig}` - } } ]; @@ -34,11 +24,13 @@ export const webpackModules: Record = { ] }, icon: { + entrypoint: true, dependencies: [ { id: "react" }, { ext: "spacepack", id: "spacepack" }, { ext: "common", id: "stores" }, - { id: "discord/components/common/index" } + { id: "discord/components/common/index" }, + { ext: "componentEditor", id: "dmList" } ] } }; diff --git a/src/dmFavorites/manifest.json b/src/dmFavorites/manifest.json index 31c25e7..0018371 100644 --- a/src/dmFavorites/manifest.json +++ b/src/dmFavorites/manifest.json @@ -1,7 +1,7 @@ { "$schema": "https://moonlight-mod.github.io/manifest.schema.json", "id": "dmFavorites", - "version": "1.0.0", + "version": "1.0.1", "meta": { "name": "DM Favorites", "tagline": "Implements favorited direct messages from mobile", @@ -9,6 +9,6 @@ "tags": ["chat", "qol"], "source": "https://github.com/Cynosphere/moonlight-extensions" }, - "dependencies": ["common", "spacepack", "contextMenu"], + "dependencies": ["common", "spacepack", "contextMenu", "componentEditor"], "apiLevel": 2 } diff --git a/src/dmFavorites/webpackModules/icon.tsx b/src/dmFavorites/webpackModules/icon.tsx index ea60180..e72d1d5 100644 --- a/src/dmFavorites/webpackModules/icon.tsx +++ b/src/dmFavorites/webpackModules/icon.tsx @@ -2,12 +2,15 @@ import React from "@moonlight-mod/wp/react"; import spacepack from "@moonlight-mod/wp/spacepack_spacepack"; import { UserGuildSettingsStore } from "@moonlight-mod/wp/common_stores"; +const DMList = spacepack.require("componentEditor_dmList").default; const { StarIcon } = spacepack.require("discord/components/common/index"); -export default function FavoritedIcon(props: any) { +function FavoritedIcon(props: any) { const id = props.channel.id; const override = UserGuildSettingsStore.getChannelOverrides("null")[id] ?? {}; const isFavorite = (override.flags & 2048) !== 0; return isFavorite ? : null; } + +DMList.addItem("dmFavorites", FavoritedIcon, "close-button", true); diff --git a/src/platformIcons/index.ts b/src/platformIcons/index.ts index b94183e..599a5d8 100644 --- a/src/platformIcons/index.ts +++ b/src/platformIcons/index.ts @@ -3,39 +3,6 @@ import { Patch, ExtensionWebpackModule } from "@moonlight-mod/types"; const alwaysShowMobile = () => moonlight.getConfigOption("platformIcons", "alwaysShowMobile") ?? true; export const patches: Patch[] = [ - // Messages - // TODO: probably api-ify this - { - find: '},"new-member")),', - replace: { - match: /(?<=(\(0,\i\.jsx\)).+?)\.BADGES]=(.);/, - replacement: (_, createElement, badges) => - `.BADGES]=[${createElement}(require("platformIcons_icons").default,{user:arguments[0].message.author,configKey:"messages",extraClasses:["platform-icons-message"],size:"sm"}),...${badges}];` - } - }, - - // Member list - // TODO: api-ify - { - find: ".lostPermission", - replace: { - match: /(\(0,\i\.jsxs\))\(\i\.Fragment,{children:\[\i\(\),/, - replacement: (orig: string, createElement) => - `${orig}${createElement}(require("platformIcons_icons").default,{user:arguments[0].user,configKey:"memberList",extraClasses:["platform-icons-member-list"]}),` - } - }, - - // DM list - // TODO: api-ify - { - find: ".interactiveSystemDM]:", - replace: { - match: /decorators:(\i\.isSystemDM\(\)\?(\(0,\i\.jsx\))\(.+?verified:!0}\):null)/, - replacement: (_, orig, createElement) => - `decorators:[${orig},${createElement}(require("platformIcons_icons").default,{user:arguments[0].user,configKey:"directMessages",extraClasses:["platform-icons-private-message"]})]` - } - }, - // Profile // TODO: api-ify { @@ -103,12 +70,16 @@ export const patches: Patch[] = [ export const webpackModules: Record = { icons: { + entrypoint: true, dependencies: [ { ext: "spacepack", id: "spacepack" }, { id: "react" }, { id: "discord/packages/flux" }, { id: "discord/components/common/index" }, { ext: "common", id: "stores" }, + { ext: "componentEditor", id: "dmList" }, + { ext: "componentEditor", id: "memberList" }, + { ext: "componentEditor", id: "messages" }, "humanizeStatus:" ] }, diff --git a/src/platformIcons/manifest.json b/src/platformIcons/manifest.json index f897670..7858b14 100644 --- a/src/platformIcons/manifest.json +++ b/src/platformIcons/manifest.json @@ -1,7 +1,7 @@ { "$schema": "https://moonlight-mod.github.io/manifest.schema.json", "id": "platformIcons", - "version": "1.0.3", + "version": "1.0.4", "meta": { "name": "Platform Icons", "tagline": "Shows what platform(s) a user is on", @@ -9,7 +9,7 @@ "tags": ["qol", "chat"], "source": "https://github.com/Cynosphere/moonlight-extensions" }, - "dependencies": ["spacepack"], + "dependencies": ["spacepack", "common", "componentEditor"], "settings": { "self": { "displayName": "Show own platforms", diff --git a/src/platformIcons/webpackModules/icons.tsx b/src/platformIcons/webpackModules/icons.tsx index 2be342c..84e76ce 100644 --- a/src/platformIcons/webpackModules/icons.tsx +++ b/src/platformIcons/webpackModules/icons.tsx @@ -1,6 +1,9 @@ import React from "@moonlight-mod/wp/react"; import spacepack from "@moonlight-mod/wp/spacepack_spacepack"; import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux"; +import MemberList from "@moonlight-mod/wp/componentEditor_memberList"; +import DMList from "@moonlight-mod/wp/componentEditor_dmList"; +import Messages from "@moonlight-mod/wp/componentEditor_messages"; import { AuthenticationStore, PresenceStore, SessionsStore } from "@moonlight-mod/wp/common_stores"; import * as Components from "@moonlight-mod/wp/discord/components/common/index"; @@ -28,7 +31,7 @@ type IconsProps = { user: any; extraClasses: string[]; configKey: string; - size: "xxs" | "xs" | "sm" | "md" | "lg" | "custom" | "refresh_sm"; + size?: "xxs" | "xs" | "sm" | "md" | "lg" | "custom" | "refresh_sm"; width?: number; height?: number; }; @@ -93,3 +96,26 @@ export default function PlatformIcons({ user, extraClasses, configKey, size = "x
{elements}
); } + +DMList.addDecorator("platformIcons", (props: any) => ( + +)); +MemberList.addDecorator( + "platformIcons", + (props: any) => ( + + ), + "bot-tag" +); +Messages.addUsernameBadge( + "platformIcons", + (props: any) => ( + + ), + "role-icon" +);