Skip to content

Commit

Permalink
swc
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Jun 25, 2024
1 parent cce98b0 commit a4186a1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
35 changes: 23 additions & 12 deletions src/Components/TokenLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { webpack } from "replugged";
import { modal as ModalUtils, React } from "replugged/common";
import { Button, Modal, Text, TextInput } from "replugged/components";
import { Button, Modal, Flex, Text, TextInput } from "replugged/components";
import Modules from "../lib/requiredModules";
import Types from "../types";
export const TokenLoginForm = (props) => {
const [token, setToken] = React.useState(null);
const handleLogin = () => {
Expand All @@ -11,8 +13,10 @@ export const TokenLoginForm = (props) => {
return (
<Modal.ModalRoot className="login-with-token" size="small" {...props}>
<Modal.ModalHeader className="token-login-header">
<Text tag="h3">Login With Token</Text>
<Modal.ModalCloseButton onClick={props.onClose} className="token-login-close" />
<Flex justify={Flex.Justify.BETWEEN} align={Flex.Align.CENTER}>
<Text tag="h3">Login With Token</Text>
<Modal.ModalCloseButton onClick={props.onClose} className="token-login-close" />
</Flex>
</Modal.ModalHeader>
<Modal.ModalContent>
<TextInput
Expand All @@ -31,12 +35,19 @@ export const TokenLoginForm = (props) => {
</Modal.ModalRoot>
);
};
export const TokenLoginLink = () => (
<Modules.WebAuth.Button
color={Modules.WebAuth.Button.Colors.LINK}
look={Modules.WebAuth.Button.Looks.LINK}
className="token-login"
onClick={() => ModalUtils.openModal((props) => <TokenLoginForm {...props} />)}>
Login With Token
</Modules.WebAuth.Button>
);
export const TokenLoginLink = () => {
const Button = webpack.getExportsForProps<Types.WebAuth["Button"]>(Modules.WebAuth, [
"Colors",
"Sizes",
"Looks",
]);
return (
<Button
color={Button.Colors.LINK}
look={Button.Looks.LINK}
className="token-login"
onClick={() => ModalUtils.openModal((props) => <TokenLoginForm {...props} />)}>
Login With Token
</Button>
);
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Injections from "./injections";
export const start = (): void => {
Settings.registerSettings();
HBCM.getAPI().addItem("Token", TokenMenuItem);
void Injections.applyInjections();
void Injections.applyInjections().catch((err) => PluginLogger.error(err));
};

export const stop = (): void => {
Expand Down
6 changes: 4 additions & 2 deletions src/injections/TokenLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { util } from "replugged";
import { util, webpack } from "replugged";
import { PluginInjector } from "../index";
import Modules from "../lib/requiredModules";
import { TokenLoginLink } from "../Components/TokenLogin";
import Types from "../types";
export default (): void => {
PluginInjector.before(Modules.WebAuth, "default", (args) => {
const { WebAuth } = Modules;
const loader = webpack.getFunctionKeyBySource(WebAuth, ".authBoxExpanded") as "default";
PluginInjector.before(WebAuth, loader, (args) => {
const [props] = args;
const container = util.findInReactTree(props, (c: Types.ReactTree) =>
c?.props?.children?.some?.((m) =>
Expand Down
21 changes: 15 additions & 6 deletions src/lib/requiredModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import Types from "../types";
export const Modules: Types.Modules = {};

Modules.loadModules = async (): Promise<void> => {
Modules.AuthenticationStore ??= await webpack.waitForProps<Types.AuthenticationStore>(
"getToken",
"getLoginStatus",
);
Modules.AuthenticationStore ??=
webpack.getByStoreName<Types.AuthenticationStore>("AuthenticationStore");

Modules.WebAuth ??= await webpack.waitForProps<Types.WebAuth>("IncompatibleBrowser");
Modules.WebAuth ??= await webpack
.waitForModule<Types.WebAuth>(
webpack.filters.bySource("Messages.MULTI_ACCOUNT_SERVER_INVITE_JOINING_AS"),
{ timeout: 10000 },
)
.catch(() => {
throw new Error("Failed To Find WebAuth Module");
});

Modules.LoginUtils ??= await webpack.waitForProps<Types.LoginUtils>("login", "logout");
Modules.LoginUtils ??= await webpack
.waitForProps<Types.LoginUtils>(["login", "logout"], { timeout: 10000 })
.catch(() => {
throw new Error("Failed To Find LoginUtils Module");
});
};

export default Modules;
6 changes: 2 additions & 4 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.token-login-header [class*="close"] {
position: absolute;
right: 2.25%;
top: 12%;
.token-login-header {
box-shadow: unset !important;
}
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { types } from "replugged";
import type Util from "replugged/dist/renderer/util";
import type HBCM from "./lib/HomeButtonContextMenuApi";
import { Store } from "replugged/dist/renderer/modules/common/flux";

export namespace Types {
export import DefaultTypes = types;
export type ReactTree = Util.Tree & React.ReactElement;
Expand Down Expand Up @@ -86,7 +88,7 @@ export namespace Types {
verifySSOToken: DefaultTypes.AnyFunction;
}

export interface AuthenticationStore {
export interface AuthenticationStore extends Store {
allowLogoutRedirect: DefaultTypes.AnyFunction;
didVerifyFail: DefaultTypes.AnyFunction;
didVerifySucceed: DefaultTypes.AnyFunction;
Expand Down

0 comments on commit a4186a1

Please sign in to comment.