Skip to content

Commit

Permalink
Merge pull request #62 from moonlight-mod/lunast
Browse files Browse the repository at this point in the history
API v2
  • Loading branch information
NotNite authored Oct 3, 2024
2 parents 0498ec0 + db71350 commit 0373e98
Show file tree
Hide file tree
Showing 54 changed files with 518 additions and 916 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm-lock.yml
pnpm-lock.yaml
1 change: 1 addition & 0 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const external = [
"module",
"events",
"original-fs", // wtf asar?
"discord", // mappings

// Silence an esbuild warning
"./node-preload.js"
Expand Down
33 changes: 4 additions & 29 deletions packages/core-extensions/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
import { ExtensionWebExports } from "@moonlight-mod/types";

export const webpackModules: ExtensionWebExports["webpackModules"] = {
components: {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
"MasonryList:",
".flexGutterSmall,"
]
},

flux: {
dependencies: [{ ext: "spacepack", id: "spacepack" }, "connectStores:"]
},

fluxDispatcher: {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
"isDispatching",
"dispatch"
]
},

react: {
stores: {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
/\.?version(?:=|:)/,
/\.?createElement(?:=|:)/
{
id: "discord/packages/flux"
}
]
},

stores: {
dependencies: [{ ext: "common", id: "flux" }]
}
};
1 change: 1 addition & 0 deletions packages/core-extensions/src/common/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "common",
"apiLevel": 2,
"meta": {
"name": "Common",
"tagline": "A *lot* of common clientmodding utilities from the Discord client",
Expand Down
41 changes: 0 additions & 41 deletions packages/core-extensions/src/common/webpackModules/components.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/core-extensions/src/common/webpackModules/flux.ts

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions packages/core-extensions/src/common/webpackModules/react.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/core-extensions/src/common/webpackModules/stores.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Flux from "@moonlight-mod/wp/common_flux";
import { Store } from "@moonlight-mod/wp/discord/packages/flux";

module.exports = new Proxy(
{},
{
get: function (target, key, receiver) {
const allStores = Flux.Store.getAll();
const allStores = Store.getAll();

let targetStore;
for (const store of allStores) {
Expand Down
1 change: 1 addition & 0 deletions packages/core-extensions/src/contextMenu/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "contextMenu",
"apiLevel": 2,
"meta": {
"name": "Context Menu",
"tagline": "A library for patching and creating context menus",
Expand Down
1 change: 1 addition & 0 deletions packages/core-extensions/src/disableSentry/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "disableSentry",
"apiLevel": 2,
"meta": {
"name": "Disable Sentry",
"tagline": "Turns off Discord's error reporting systems",
Expand Down
1 change: 1 addition & 0 deletions packages/core-extensions/src/experiments/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "experiments",
"apiLevel": 2,
"meta": {
"name": "Experiments",
"tagline": "Allows you to configure Discord's internal A/B testing features",
Expand Down
1 change: 1 addition & 0 deletions packages/core-extensions/src/markdown/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "markdown",
"apiLevel": 2,
"meta": {
"name": "Markdown",
"tagline": "A library for adding new markdown rules",
Expand Down
12 changes: 6 additions & 6 deletions packages/core-extensions/src/moonbase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { ExtensionWebExports } from "@moonlight-mod/types";
export const webpackModules: ExtensionWebExports["webpackModules"] = {
stores: {
dependencies: [
{ ext: "common", id: "flux" },
{ ext: "common", id: "fluxDispatcher" }
{ id: "discord/packages/flux" },
{ id: "discord/Dispatcher" }
]
},

ui: {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
{ ext: "common", id: "react" },
{ ext: "common", id: "components" },
{ id: "react" },
{ id: "discord/components/common/index" },
{ ext: "moonbase", id: "stores" },
{ id: "discord/modules/guild_settings/IntegrationCard.css" },
"Masks.PANEL_BUTTON",
"renderArtisanalHack(){",
'"Missing channel in Channel.openChannelContextMenu"',
".forumOrHome]:"
]
Expand All @@ -25,7 +25,7 @@ export const webpackModules: ExtensionWebExports["webpackModules"] = {
dependencies: [
{ ext: "spacepack", id: "spacepack" },
{ ext: "settings", id: "settings" },
{ ext: "common", id: "react" },
{ id: "react" },
{ ext: "moonbase", id: "ui" }
],
entrypoint: true
Expand Down
1 change: 1 addition & 0 deletions packages/core-extensions/src/moonbase/manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "moonbase",
"apiLevel": 2,
"meta": {
"name": "Moonbase",
"tagline": "The official settings UI for moonlight",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import settings from "@moonlight-mod/wp/settings_settings";
import React from "@moonlight-mod/wp/common_react";
import React from "@moonlight-mod/wp/react";
import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
import { Moonbase, pages } from "@moonlight-mod/wp/moonbase_ui";

import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";
import { MenuItem } from "@moonlight-mod/wp/common_components";
import { MenuItem } from "@moonlight-mod/wp/discord/components/common/index";

const { open } = spacepack.findByExports("setSection", "clearSubsection")[0]
.exports.Z;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Config, ExtensionLoadSource } from "@moonlight-mod/types";
import { ExtensionState, MoonbaseExtension, MoonbaseNatives } from "../types";
import Flux from "@moonlight-mod/wp/common_flux";
import Dispatcher from "@moonlight-mod/wp/common_fluxDispatcher";
import { Store } from "@moonlight-mod/wp/discord/packages/flux";
import Dispatcher from "@moonlight-mod/wp/discord/Dispatcher";

const natives: MoonbaseNatives = moonlight.getNatives("moonbase");
const logger = moonlight.getLogger("moonbase");

class MoonbaseSettingsStore extends Flux.Store<any> {
class MoonbaseSettingsStore extends Store<any> {
private origConfig: Config;
private config: Config;
private extensionIndex: number;
Expand Down Expand Up @@ -46,6 +46,9 @@ class MoonbaseSettingsStore extends Flux.Store<any> {
for (const [repo, exts] of Object.entries(ret)) {
try {
for (const ext of exts) {
const level = ext.apiLevel ?? 1;
if (level !== window.moonlight.apiLevel) continue;

const uniqueId = this.extensionIndex++;
const extensionData = {
id: ext.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ const logLevels = Object.values(LogLevel).filter(
(v) => typeof v === "string"
) as string[];

import React from "@moonlight-mod/wp/common_react";
import React from "@moonlight-mod/wp/react";
import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
import {
FormDivider,
FormItem,
FormText,
FormSwitch,
TextInput,
Flex,
Button,
SingleSelect,
Tooltip,
Clickable
} from "@moonlight-mod/wp/common_components";
import CommonComponents from "@moonlight-mod/wp/common_components";
} from "@moonlight-mod/wp/discord/components/common/index";
import Flex from "@moonlight-mod/wp/discord/uikit/Flex";
import * as Components from "@moonlight-mod/wp/discord/components/common/index";

import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";

Expand All @@ -38,7 +38,9 @@ spacepack
.exports)
);

const { CircleXIcon } = CommonComponents;
// FIXME: type component keys
const { CircleXIcon } = Components;

function RemoveEntryButton({ onClick }: { onClick: () => void }) {
return (
<div className={RemoveButtonClasses.removeButtonContainer}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ExtensionState } from "../../../types";
import { ExtensionLoadSource } from "@moonlight-mod/types";

import React from "@moonlight-mod/wp/common_react";
import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
import CommonComponents from "@moonlight-mod/wp/common_components";
import * as Flux from "@moonlight-mod/wp/common_flux";
import * as Components from "@moonlight-mod/wp/discord/components/common/index";
import React from "@moonlight-mod/wp/react";
import { useStateFromStores } from "@moonlight-mod/wp/discord/packages/flux";
import Flex from "@moonlight-mod/wp/discord/uikit/Flex";
import MarkupUtils from "@moonlight-mod/wp/discord/modules/markup/MarkupUtils";
import IntegrationCard from "@moonlight-mod/wp/discord/modules/guild_settings/IntegrationCard.css";

import ExtensionInfo from "./info";
import Settings from "./settings";
Expand All @@ -17,7 +20,7 @@ export enum ExtensionPage {

import { MoonbaseSettingsStore } from "@moonlight-mod/wp/moonbase_stores";

const { DownloadIcon, TrashIcon, CircleWarningIcon } = CommonComponents;
const { DownloadIcon, TrashIcon, CircleWarningIcon } = Components;

const PanelButton = spacepack.findByCode("Masks.PANEL_BUTTON")[0].exports.Z;
const TabBarClasses = spacepack.findByExports(
Expand All @@ -30,7 +33,7 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
const [tab, setTab] = React.useState(ExtensionPage.Info);
const [restartNeeded, setRestartNeeded] = React.useState(false);

const { ext, enabled, busy, update, conflicting } = Flux.useStateFromStores(
const { ext, enabled, busy, update, conflicting } = useStateFromStores(
[MoonbaseSettingsStore],
() => {
return {
Expand All @@ -46,24 +49,15 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
// Why it work like that :sob:
if (ext == null) return <></>;

const {
Card,
CardClasses,
Flex,
Text,
MarkdownParser,
Switch,
TabBar,
Button
} = CommonComponents;
const { Card, Text, Switch, TabBar, Button } = Components;

const tagline = ext.manifest?.meta?.tagline;
const settings = ext.manifest?.settings;
const description = ext.manifest?.meta?.description;

return (
<Card editable={true} className={CardClasses.card}>
<div className={CardClasses.cardHeader}>
<Card editable={true} className={IntegrationCard.card}>
<div className={IntegrationCard.cardHeader}>
<Flex direction={Flex.Direction.VERTICAL}>
<Flex direction={Flex.Direction.HORIZONTAL}>
<Text variant="text-md/semibold">
Expand All @@ -72,9 +66,7 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
</Flex>

{tagline != null && (
<Text variant="text-sm/normal">
{MarkdownParser.parse(tagline)}
</Text>
<Text variant="text-sm/normal">{MarkupUtils.parse(tagline)}</Text>
)}
</Flex>

Expand Down Expand Up @@ -127,7 +119,7 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
<PanelButton
icon={() => (
<CircleWarningIcon
color={CommonComponents.tokens.colors.STATUS_DANGER}
color={Components.tokens.colors.STATUS_DANGER}
/>
)}
onClick={() => window.location.reload()}
Expand Down Expand Up @@ -195,7 +187,7 @@ export default function ExtensionCard({ uniqueId }: { uniqueId: number }) {
{tab === ExtensionPage.Info && <ExtensionInfo ext={ext} />}
{tab === ExtensionPage.Description && (
<Text variant="text-md/normal">
{MarkdownParser.parse(description ?? "*No description*")}
{MarkupUtils.parse(description ?? "*No description*")}
</Text>
)}
{tab === ExtensionPage.Settings && <Settings ext={ext} />}
Expand Down
Loading

0 comments on commit 0373e98

Please sign in to comment.