Skip to content

Commit

Permalink
nyaa
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Apr 21, 2024
1 parent 4ea2a6b commit 11e688d
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 276 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.33.2",
"prettier": "^2.8.8",
"replugged": "^4.7.9",
"replugged": "4.7.9",
"typescript": "^5.0.0"
}
}
52 changes: 13 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions src/Components/AccountDetailsButton.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { plugins } from "replugged";
import { contextMenu as ContextMenuApi, React } from "replugged/common";
import { SettingValues } from "../index";
import { PanelButton } from "../lib/requiredModules";
import Modules from "../lib/requiredModules";
import { defaultSettings } from "../lib/consts";
import UserSettingStore from "../lib/UserSettingStore";
import Icons from "../Components/Icons";
import SpotifyAccountsContextMenu from "./ContextMenu";
import Utils from "../lib/utils";
export const GameActivityPanelButton = (): React.ReactElement | null => {
const [enabled, setEnabled] = React.useState(
UserSettingStore.getSetting("status", "showCurrentGame"),
);
React.useEffect(() => {
setEnabled(UserSettingStore.getSetting("status", "showCurrentGame"));
}, [UserSettingStore.getSetting("status", "showCurrentGame")]);

const enabled = UserSettingStore.useSetting("status", "showCurrentGame");
if (
!SettingValues.get("userPanel", defaultSettings.userPanel) ||
plugins.getDisabled().includes("dev.tharki.ReGameActivityToggle")
Expand All @@ -34,7 +28,7 @@ export const GameActivityPanelButton = (): React.ReactElement | null => {
);

return (
<PanelButton
<Modules.PanelButton
onContextMenu={(event) =>
ContextMenuApi.open(event, (props) => (
<SpotifyAccountsContextMenu {...props} onClose={ContextMenuApi.close} />
Expand All @@ -48,6 +42,4 @@ export const GameActivityPanelButton = (): React.ReactElement | null => {
/>
);
};
export const _addPanelButton = (): React.ReactElement | null => {
return <GameActivityPanelButton />;
};
export default () => (Modules.PanelButton ? <GameActivityPanelButton /> : <></>);
67 changes: 24 additions & 43 deletions src/Components/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
import { React } from "replugged/common";
import { flux as Flux, React } from "replugged/common";
import { ContextMenu } from "replugged/components";
import { SettingValues } from "..";
import { Sounds, defaultSettings } from "../lib/consts";
import { ConnectedAccountsStore, ConnectedAccountsUtils, SoundUtils } from "../lib/requiredModules";
import Modules from "../lib/requiredModules";
import Icons from "./Icons";
import Utils from "../lib/utils";
const { MenuCheckboxItem, ContextMenu: Menu, MenuSeparator, MenuItem } = ContextMenu;

export default (props) => {
const ConnectedAccounts = ConnectedAccountsStore.getAccounts() as Array<{
type: string;
id: string;
name: string;
showActivity: boolean;
}>;
const SpotifyAccounts = ConnectedAccounts.filter((a) => a.type === "spotify").map((a) => {
const [value, onChange] = React.useState(a.showActivity);
return (
<MenuCheckboxItem
id={a.id}
label={a.name}
checked={value}
action={(e) => {
onChange((prev) => !prev);
a.showActivity = !a.showActivity;
ConnectedAccountsUtils.setShowActivity("spotify", a.id, a.showActivity);
if (
e &&
((!a.showActivity &&
(SettingValues.get("playAudio", defaultSettings.playAudio).spotifyDisable ?? true)) ||
(a.showActivity &&
(SettingValues.get("playAudio", defaultSettings.playAudio).spotifyEnable ?? true)))
) {
SoundUtils.playSound(value ? Sounds.SpotifyEnable : Sounds.SpotifyDisable, 0.5);
}
}}
/>
);
const { SpotifyAccounts } = Flux.useStateFromStores([Modules.ConnectedAccountsStore], () => {
const ConnectedAccounts = Modules.ConnectedAccountsStore.getAccounts();
return {
SpotifyAccounts: ConnectedAccounts.filter((a) => a.type === "spotify"),
};
});

return (
<Menu {...props} navId="yofukashino">
<MenuItem
Expand All @@ -45,19 +21,24 @@ export default (props) => {
id="spotify-accounts"
showIconFirst={true}
icon={() => <Icons.music height="16" width="16" />}
action={() => {
for (const {
props: { action },
} of SpotifyAccounts)
action(false);
if (SettingValues.get("playAudio", defaultSettings.playAudio).spotifyToogle ?? true) {
SoundUtils.playSound(Sounds.SpotifyToogle, 0.5);
}
}}
action={() => Utils.toggleSpotifyActivity()}
/>
<MenuSeparator />
{SpotifyAccounts.length ? (
SpotifyAccounts
SpotifyAccounts.map((a) => {
const [value, onChange] = React.useState(a.showActivity);
return (
<MenuCheckboxItem
id={a.id}
label={a.name}
checked={value}
action={() => {
onChange((prev) => !prev);
Utils.toggleSpotifyActivity(a);
}}
/>
);
})
) : (
<MenuItem
label="No Accounts"
Expand Down
1 change: 0 additions & 1 deletion src/Components/Icons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Types from "../types";
export const controller = ({
children,
...props
Expand Down
7 changes: 4 additions & 3 deletions src/Components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { common, components } from "replugged";
import { React } from "replugged/common";
import { Category, SwitchItem } from "replugged/components";
import { PluginLogger, SettingValues } from "../index";
const { React } = common;
import { defaultSettings } from "../lib/consts";
const { SwitchItem, Category } = components;
import KeybindRecorderItem from "./KeybindRecorderItem";
import Utils from "../lib/utils";
import Types from "../types";
Expand Down Expand Up @@ -94,3 +93,5 @@ export const Settings = React.memo((): React.ReactElement => {
</div>
);
});

export default { registerSettings, Settings };
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { Injector, Logger, settings } from "replugged";
import { defaultSettings } from "./lib/consts";
import "./style.css";
import { registerSettings } from "./Components/Settings";
export const PluginInjector = new Injector();
export const { utils: PluginInjectorUtils } = PluginInjector;
export const PluginLogger = Logger.plugin("ReGameActivityToggle");
export const SettingValues = await settings.init("dev.tharki.ReGameActivityToggle");
export const SettingValues = await settings.init(
"dev.tharki.ReGameActivityToggle",
defaultSettings,
);
export const CurrentlyPressed = new Map();
import Injections from "./patches/index";
import Settings from "./Components/Settings";
import Injections from "./injections/index";
import Listeners from "./listeners/index";

export const start = (): void => {
registerSettings();
Injections.applyInjections();
Listeners.addListeners();
Settings.registerSettings();
void Injections.applyInjections();
void Listeners.addListeners();
};

export const stop = (): void => {
PluginInjector.uninjectAll();
Listeners.removeListeners();
};

export { _addPanelButton } from "./Components/AccountDetailsButton";
export { default as _addPanelButton } from "./Components/AccountDetailsButton";

export { Settings } from "./Components/Settings.jsx";
Loading

0 comments on commit 11e688d

Please sign in to comment.