mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-10 18:06:22 +00:00
finished settings ✨
This commit is contained in:
parent
13f909bc9a
commit
cd917a4ba2
2 changed files with 106 additions and 18 deletions
|
@ -8,7 +8,7 @@ import { CheckedTextInput } from "@components/CheckedTextInput";
|
|||
import { Margins } from "@utils/margins";
|
||||
import { identity } from "@utils/misc";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
import { Card, Forms, PresenceStore, React, Select, SnowflakeUtils, Switch, UserStore } from "@webpack/common";
|
||||
import { Card, Forms, PresenceStore, React, Select, SnowflakeUtils, Switch, TextInput, UserStore } from "@webpack/common";
|
||||
|
||||
import { Activity, ActivityType, AppIdSetting, makeEmptyAppId } from ".";
|
||||
|
||||
|
@ -38,7 +38,7 @@ export function ReplaceTutorial() {
|
|||
{
|
||||
activities.length === 0 ? <Forms.FormText>No running activities</Forms.FormText> : activities.map(activity => { return activity.flags !== 48 ? <Forms.FormText>{activity.name}: {activity.application_id}</Forms.FormText> : null; /* hide spotify */ })
|
||||
}
|
||||
<Forms.FormTitle tag="h3" style={{ marginTop: "7px" }}>Available variables</Forms.FormTitle>
|
||||
<Forms.FormTitle tag="h3" className={Margins.top8}>Available variables</Forms.FormTitle>
|
||||
<Forms.FormText>
|
||||
In all fields, you can put in variables that'll automatically be replaced by their content:
|
||||
<pre style={{ fontFamily: "monospace" }}>
|
||||
|
@ -47,6 +47,12 @@ export function ReplaceTutorial() {
|
|||
:large_image:, :large_text:, :small_image:, :small_text:
|
||||
</pre>
|
||||
</Forms.FormText>
|
||||
<Forms.FormTitle tag="h3" className={Margins.top8}>More details</Forms.FormTitle>
|
||||
<Forms.FormText>
|
||||
Leave a field empty to leave it as is.
|
||||
<br />
|
||||
Set a field to "null" to hide it on the presence.
|
||||
</Forms.FormText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -58,13 +64,6 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
|||
|
||||
appIds[index][key] = val;
|
||||
|
||||
if (val && key === "appId") {
|
||||
appIds[index].appName = "Unknown";
|
||||
}
|
||||
|
||||
if (appIds[index].appId === "" && index !== appIds.length - 1)
|
||||
appIds.splice(index, 1);
|
||||
|
||||
save();
|
||||
update();
|
||||
}
|
||||
|
@ -73,9 +72,9 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
|||
<>
|
||||
{
|
||||
appIds.map((setting, i) =>
|
||||
<Card style={{ padding: "1em" }}>
|
||||
<Card style={{ padding: "1em", opacity: !setting.enabled ? "60%" : "" }}>
|
||||
{
|
||||
setting.appId ?
|
||||
isValidSnowflake(setting.appId) ?
|
||||
<Switch
|
||||
value={setting.enabled}
|
||||
onChange={value => {
|
||||
|
@ -84,10 +83,10 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
|||
className={Margins.bottom8}
|
||||
hideBorder={true}
|
||||
>
|
||||
Edit the app
|
||||
Apply edits to app
|
||||
</Switch> : <Forms.FormTitle tag="h3">Add new application</Forms.FormTitle>
|
||||
}
|
||||
<Forms.FormTitle className={Margins.top8}>Application ID</Forms.FormTitle>
|
||||
<Forms.FormTitle className={`${Margins.top8} ${Margins.bottom8}`}>Application ID</Forms.FormTitle>
|
||||
<CheckedTextInput
|
||||
value={setting.appId}
|
||||
onChange={async v => {
|
||||
|
@ -98,7 +97,7 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
|||
}
|
||||
/>
|
||||
{
|
||||
setting.appId && <>
|
||||
isValidSnowflake(setting.appId) && <>
|
||||
<Forms.FormTitle className={Margins.top8}>New activity type</Forms.FormTitle>
|
||||
<Select
|
||||
options={[
|
||||
|
@ -109,12 +108,102 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
|||
{ label: "Streaming", value: ActivityType.STREAMING }
|
||||
]}
|
||||
select={value => {
|
||||
onChange(value, i, "activityType");
|
||||
onChange(value, i, "newActivityType");
|
||||
}}
|
||||
className={Margins.top8}
|
||||
isSelected={value => setting.newActivityType === value}
|
||||
serialize={identity}
|
||||
/>
|
||||
{
|
||||
setting.newActivityType === ActivityType.STREAMING &&
|
||||
<>
|
||||
<Forms.FormTitle className={`${Margins.top8} ${Margins.bottom8}`}>Stream URL (must be YouTube or Twitch)</Forms.FormTitle>
|
||||
<CheckedTextInput
|
||||
value={setting.newStreamUrl}
|
||||
onChange={async (v) => {
|
||||
onChange(v, i, "newStreamUrl");
|
||||
}}
|
||||
validate={v => {
|
||||
return /https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+/.test(v) || "Invalid stream URL";
|
||||
}}
|
||||
/>
|
||||
|
||||
</>
|
||||
}
|
||||
{
|
||||
setting.newActivityType !== ActivityType.STREAMING &&
|
||||
<>
|
||||
<Forms.FormTitle className={Margins.top8}>New name {setting.newActivityType === ActivityType.PLAYING && "(first line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newName}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newName");
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
<Forms.FormTitle className={Margins.top8}>New details {setting.newActivityType === ActivityType.PLAYING ? "(second line)" : "(first line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newDetails}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newDetails");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>New state {setting.newActivityType === ActivityType.PLAYING ? "(third line)" : "(second line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newState}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newState");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormText style={{ fontSize: "1.05rem", fontWeight: "500" }} className={Margins.top8}>Large image</Forms.FormText>
|
||||
<Forms.FormTitle className={Margins.top8}>Text {setting.newActivityType !== ActivityType.PLAYING && "(also third line)"}</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newLargeImageText}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newLargeImageText");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>URL</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newLargeImageUrl}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newLargeImageUrl");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormText style={{ fontSize: "1.05rem", fontWeight: "500" }} className={Margins.top8}>Small image</Forms.FormText>
|
||||
<Forms.FormTitle className={Margins.top8}>Text</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newSmallImageText}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newSmallImageText");
|
||||
}}
|
||||
/>
|
||||
<Forms.FormTitle className={Margins.top8}>URL</Forms.FormTitle>
|
||||
<TextInput
|
||||
className={Margins.top8}
|
||||
value={setting.newSmallImageUrl}
|
||||
onChange={async v => {
|
||||
onChange(v, i, "newSmallImageUrl");
|
||||
}}
|
||||
/>
|
||||
<Switch
|
||||
value={setting.disableTimestamps}
|
||||
onChange={value => {
|
||||
onChange(value, i, "disableTimestamps");
|
||||
}}
|
||||
className={Margins.top8}
|
||||
hideBorder={true}
|
||||
style={{ marginBottom: "0" }}
|
||||
>
|
||||
Hide timestamps
|
||||
</Switch>
|
||||
</>
|
||||
}
|
||||
</Card>
|
||||
|
|
|
@ -15,7 +15,7 @@ import { ReplaceSettings, ReplaceTutorial } from "./ReplaceSettings";
|
|||
|
||||
const APP_IDS_KEY = "ReplaceActivityType_appids";
|
||||
export type AppIdSetting = {
|
||||
appName: string;
|
||||
disableTimestamps: boolean;
|
||||
appId: string;
|
||||
enabled: boolean;
|
||||
newActivityType: ActivityType;
|
||||
|
@ -64,7 +64,6 @@ export const enum ActivityType {
|
|||
}
|
||||
|
||||
export const makeEmptyAppId: () => AppIdSetting = () => ({
|
||||
appName: "Unknown",
|
||||
appId: "",
|
||||
enabled: true,
|
||||
newActivityType: ActivityType.PLAYING,
|
||||
|
@ -76,6 +75,7 @@ export const makeEmptyAppId: () => AppIdSetting = () => ({
|
|||
newSmallImageUrl: "",
|
||||
newSmallImageText: "",
|
||||
newStreamUrl: "",
|
||||
disableTimestamps: false
|
||||
});
|
||||
|
||||
let appIds = [makeEmptyAppId()];
|
||||
|
@ -121,7 +121,6 @@ export default definePlugin({
|
|||
|
||||
patchActivity(activity: Activity) {
|
||||
if (!activity) return;
|
||||
console.log(activity);
|
||||
appIds.forEach(app => {
|
||||
if (app.enabled && app.appId === activity.application_id) {
|
||||
activity.type = app.newActivityType;
|
||||
|
|
Loading…
Reference in a new issue