mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-25 16:56:23 +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 { Margins } from "@utils/margins";
|
||||||
import { identity } from "@utils/misc";
|
import { identity } from "@utils/misc";
|
||||||
import { findByPropsLazy } from "@webpack";
|
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 ".";
|
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 */ })
|
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>
|
<Forms.FormText>
|
||||||
In all fields, you can put in variables that'll automatically be replaced by their content:
|
In all fields, you can put in variables that'll automatically be replaced by their content:
|
||||||
<pre style={{ fontFamily: "monospace" }}>
|
<pre style={{ fontFamily: "monospace" }}>
|
||||||
|
@ -47,6 +47,12 @@ export function ReplaceTutorial() {
|
||||||
:large_image:, :large_text:, :small_image:, :small_text:
|
:large_image:, :large_text:, :small_image:, :small_text:
|
||||||
</pre>
|
</pre>
|
||||||
</Forms.FormText>
|
</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;
|
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();
|
save();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -73,9 +72,9 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
||||||
<>
|
<>
|
||||||
{
|
{
|
||||||
appIds.map((setting, i) =>
|
appIds.map((setting, i) =>
|
||||||
<Card style={{ padding: "1em" }}>
|
<Card style={{ padding: "1em", opacity: !setting.enabled ? "60%" : "" }}>
|
||||||
{
|
{
|
||||||
setting.appId ?
|
isValidSnowflake(setting.appId) ?
|
||||||
<Switch
|
<Switch
|
||||||
value={setting.enabled}
|
value={setting.enabled}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
|
@ -84,10 +83,10 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
||||||
className={Margins.bottom8}
|
className={Margins.bottom8}
|
||||||
hideBorder={true}
|
hideBorder={true}
|
||||||
>
|
>
|
||||||
Edit the app
|
Apply edits to app
|
||||||
</Switch> : <Forms.FormTitle tag="h3">Add new application</Forms.FormTitle>
|
</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
|
<CheckedTextInput
|
||||||
value={setting.appId}
|
value={setting.appId}
|
||||||
onChange={async v => {
|
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>
|
<Forms.FormTitle className={Margins.top8}>New activity type</Forms.FormTitle>
|
||||||
<Select
|
<Select
|
||||||
options={[
|
options={[
|
||||||
|
@ -109,12 +108,102 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
|
||||||
{ label: "Streaming", value: ActivityType.STREAMING }
|
{ label: "Streaming", value: ActivityType.STREAMING }
|
||||||
]}
|
]}
|
||||||
select={value => {
|
select={value => {
|
||||||
onChange(value, i, "activityType");
|
onChange(value, i, "newActivityType");
|
||||||
}}
|
}}
|
||||||
className={Margins.top8}
|
className={Margins.top8}
|
||||||
isSelected={value => setting.newActivityType === value}
|
isSelected={value => setting.newActivityType === value}
|
||||||
serialize={identity}
|
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>
|
</Card>
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { ReplaceSettings, ReplaceTutorial } from "./ReplaceSettings";
|
||||||
|
|
||||||
const APP_IDS_KEY = "ReplaceActivityType_appids";
|
const APP_IDS_KEY = "ReplaceActivityType_appids";
|
||||||
export type AppIdSetting = {
|
export type AppIdSetting = {
|
||||||
appName: string;
|
disableTimestamps: boolean;
|
||||||
appId: string;
|
appId: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
newActivityType: ActivityType;
|
newActivityType: ActivityType;
|
||||||
|
@ -64,7 +64,6 @@ export const enum ActivityType {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const makeEmptyAppId: () => AppIdSetting = () => ({
|
export const makeEmptyAppId: () => AppIdSetting = () => ({
|
||||||
appName: "Unknown",
|
|
||||||
appId: "",
|
appId: "",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
newActivityType: ActivityType.PLAYING,
|
newActivityType: ActivityType.PLAYING,
|
||||||
|
@ -76,6 +75,7 @@ export const makeEmptyAppId: () => AppIdSetting = () => ({
|
||||||
newSmallImageUrl: "",
|
newSmallImageUrl: "",
|
||||||
newSmallImageText: "",
|
newSmallImageText: "",
|
||||||
newStreamUrl: "",
|
newStreamUrl: "",
|
||||||
|
disableTimestamps: false
|
||||||
});
|
});
|
||||||
|
|
||||||
let appIds = [makeEmptyAppId()];
|
let appIds = [makeEmptyAppId()];
|
||||||
|
@ -121,7 +121,6 @@ export default definePlugin({
|
||||||
|
|
||||||
patchActivity(activity: Activity) {
|
patchActivity(activity: Activity) {
|
||||||
if (!activity) return;
|
if (!activity) return;
|
||||||
console.log(activity);
|
|
||||||
appIds.forEach(app => {
|
appIds.forEach(app => {
|
||||||
if (app.enabled && app.appId === activity.application_id) {
|
if (app.enabled && app.appId === activity.application_id) {
|
||||||
activity.type = app.newActivityType;
|
activity.type = app.newActivityType;
|
||||||
|
|
Loading…
Reference in a new issue