parent
eca4af829f
commit
ebe10d3fad
2 changed files with 40 additions and 57 deletions
|
@ -33,12 +33,11 @@ export function SettingTextComponent({ option, pluginSettings, definedSettings,
|
||||||
const isValid = option.isValid?.call(definedSettings, newValue) ?? true;
|
const isValid = option.isValid?.call(definedSettings, newValue) ?? true;
|
||||||
if (typeof isValid === "string") setError(isValid);
|
if (typeof isValid === "string") setError(isValid);
|
||||||
else if (!isValid) setError("Invalid input provided.");
|
else if (!isValid) setError("Invalid input provided.");
|
||||||
else {
|
else setError(null);
|
||||||
setError(null);
|
|
||||||
setState(newValue);
|
setState(newValue);
|
||||||
onChange(newValue);
|
onChange(newValue);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Forms.FormSection>
|
<Forms.FormSection>
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings, Settings } from "@api/Settings";
|
||||||
import { Link } from "@components/Link";
|
import { Link } from "@components/Link";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { isTruthy } from "@utils/guards";
|
import { isTruthy } from "@utils/guards";
|
||||||
|
@ -86,8 +86,7 @@ const settings = definePluginSettings({
|
||||||
appID: {
|
appID: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Application ID (required)",
|
description: "Application ID (required)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (!value) return "Application ID is required.";
|
if (!value) return "Application ID is required.";
|
||||||
if (value && !/^\d+$/.test(value)) return "Application ID must be a number.";
|
if (value && !/^\d+$/.test(value)) return "Application ID must be a number.";
|
||||||
|
@ -97,8 +96,7 @@ const settings = definePluginSettings({
|
||||||
appName: {
|
appName: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Application name (required)",
|
description: "Application name (required)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (!value) return "Application name is required.";
|
if (!value) return "Application name is required.";
|
||||||
if (value.length > 128) return "Application name must be not longer than 128 characters.";
|
if (value.length > 128) return "Application name must be not longer than 128 characters.";
|
||||||
|
@ -108,8 +106,7 @@ const settings = definePluginSettings({
|
||||||
details: {
|
details: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Details (line 1)",
|
description: "Details (line 1)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 128) return "Details (line 1) must be not longer than 128 characters.";
|
if (value && value.length > 128) return "Details (line 1) must be not longer than 128 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -118,8 +115,7 @@ const settings = definePluginSettings({
|
||||||
state: {
|
state: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "State (line 2)",
|
description: "State (line 2)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 128) return "State (line 2) must be not longer than 128 characters.";
|
if (value && value.length > 128) return "State (line 2) must be not longer than 128 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -128,8 +124,7 @@ const settings = definePluginSettings({
|
||||||
type: {
|
type: {
|
||||||
type: OptionType.SELECT,
|
type: OptionType.SELECT,
|
||||||
description: "Activity type",
|
description: "Activity type",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
label: "Playing",
|
label: "Playing",
|
||||||
|
@ -157,16 +152,14 @@ const settings = definePluginSettings({
|
||||||
streamLink: {
|
streamLink: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Twitch.tv or Youtube.com link (only for Streaming activity type)",
|
description: "Twitch.tv or Youtube.com link (only for Streaming activity type)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
disabled: isStreamLinkDisabled,
|
||||||
isDisabled: isStreamLinkDisabled,
|
|
||||||
isValid: isStreamLinkValid
|
isValid: isStreamLinkValid
|
||||||
},
|
},
|
||||||
timestampMode: {
|
timestampMode: {
|
||||||
type: OptionType.SELECT,
|
type: OptionType.SELECT,
|
||||||
description: "Timestamp mode",
|
description: "Timestamp mode",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
label: "None",
|
label: "None",
|
||||||
|
@ -190,9 +183,8 @@ const settings = definePluginSettings({
|
||||||
startTime: {
|
startTime: {
|
||||||
type: OptionType.NUMBER,
|
type: OptionType.NUMBER,
|
||||||
description: "Start timestamp (only for custom timestamp mode)",
|
description: "Start timestamp (only for custom timestamp mode)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
disabled: isTimestampDisabled,
|
||||||
isDisabled: isTimestampDisabled,
|
|
||||||
isValid: (value: number) => {
|
isValid: (value: number) => {
|
||||||
if (value && value < 0) return "Start timestamp must be greater than 0.";
|
if (value && value < 0) return "Start timestamp must be greater than 0.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -201,9 +193,8 @@ const settings = definePluginSettings({
|
||||||
endTime: {
|
endTime: {
|
||||||
type: OptionType.NUMBER,
|
type: OptionType.NUMBER,
|
||||||
description: "End timestamp (only for custom timestamp mode)",
|
description: "End timestamp (only for custom timestamp mode)",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
disabled: isTimestampDisabled,
|
||||||
isDisabled: isTimestampDisabled,
|
|
||||||
isValid: (value: number) => {
|
isValid: (value: number) => {
|
||||||
if (value && value < 0) return "End timestamp must be greater than 0.";
|
if (value && value < 0) return "End timestamp must be greater than 0.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -211,16 +202,14 @@ const settings = definePluginSettings({
|
||||||
},
|
},
|
||||||
imageBig: {
|
imageBig: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Big image key",
|
description: "Big image key/link",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: isImageKeyValid
|
isValid: isImageKeyValid
|
||||||
},
|
},
|
||||||
imageBigTooltip: {
|
imageBigTooltip: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Big image tooltip",
|
description: "Big image tooltip",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 128) return "Big image tooltip must be not longer than 128 characters.";
|
if (value && value.length > 128) return "Big image tooltip must be not longer than 128 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -228,16 +217,14 @@ const settings = definePluginSettings({
|
||||||
},
|
},
|
||||||
imageSmall: {
|
imageSmall: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Small image key",
|
description: "Small image key/link",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: isImageKeyValid
|
isValid: isImageKeyValid
|
||||||
},
|
},
|
||||||
imageSmallTooltip: {
|
imageSmallTooltip: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Small image tooltip",
|
description: "Small image tooltip",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 128) return "Small image tooltip must be not longer than 128 characters.";
|
if (value && value.length > 128) return "Small image tooltip must be not longer than 128 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -246,8 +233,7 @@ const settings = definePluginSettings({
|
||||||
buttonOneText: {
|
buttonOneText: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Button 1 text",
|
description: "Button 1 text",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 31) return "Button 1 text must be not longer than 31 characters.";
|
if (value && value.length > 31) return "Button 1 text must be not longer than 31 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -256,14 +242,12 @@ const settings = definePluginSettings({
|
||||||
buttonOneURL: {
|
buttonOneURL: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Button 1 URL",
|
description: "Button 1 URL",
|
||||||
restartNeeded: true,
|
onChange: onChange
|
||||||
onChange: setRpc
|
|
||||||
},
|
},
|
||||||
buttonTwoText: {
|
buttonTwoText: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Button 2 text",
|
description: "Button 2 text",
|
||||||
restartNeeded: true,
|
onChange: onChange,
|
||||||
onChange: setRpc,
|
|
||||||
isValid: (value: string) => {
|
isValid: (value: string) => {
|
||||||
if (value && value.length > 31) return "Button 2 text must be not longer than 31 characters.";
|
if (value && value.length > 31) return "Button 2 text must be not longer than 31 characters.";
|
||||||
return true;
|
return true;
|
||||||
|
@ -272,26 +256,29 @@ const settings = definePluginSettings({
|
||||||
buttonTwoURL: {
|
buttonTwoURL: {
|
||||||
type: OptionType.STRING,
|
type: OptionType.STRING,
|
||||||
description: "Button 2 URL",
|
description: "Button 2 URL",
|
||||||
restartNeeded: true,
|
onChange: onChange
|
||||||
onChange: setRpc
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function isStreamLinkDisabled(): boolean {
|
function onChange() {
|
||||||
|
setRpc(true);
|
||||||
|
if (Settings.plugins.CustomRPC.enabled) setRpc();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isStreamLinkDisabled() {
|
||||||
return settings.store.type !== ActivityType.STREAMING;
|
return settings.store.type !== ActivityType.STREAMING;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isStreamLinkValid(): boolean | string {
|
function isStreamLinkValid(value: string) {
|
||||||
if (settings.store.type === ActivityType.STREAMING && settings.store.streamLink && !/(https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+)/.test(settings.store.streamLink)) return "Streaming link must be a valid URL.";
|
if (!isStreamLinkDisabled() && !/https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+/.test(value)) return "Streaming link must be a valid URL.";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTimestampDisabled(): boolean {
|
function isTimestampDisabled() {
|
||||||
return settings.store.timestampMode !== TimestampMode.CUSTOM;
|
return settings.store.timestampMode !== TimestampMode.CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isImageKeyValid(value: string) {
|
function isImageKeyValid(value: string) {
|
||||||
if (!/https?:\/\//.test(value)) return true;
|
|
||||||
if (/https?:\/\/(?!i\.)?imgur\.com\//.test(value)) return "Imgur link must be a direct link to the image. (e.g. https://i.imgur.com/...)";
|
if (/https?:\/\/(?!i\.)?imgur\.com\//.test(value)) return "Imgur link must be a direct link to the image. (e.g. https://i.imgur.com/...)";
|
||||||
if (/https?:\/\/(?!media\.)?tenor\.com\//.test(value)) return "Tenor link must be a direct link to the image. (e.g. https://media.tenor.com/...)";
|
if (/https?:\/\/(?!media\.)?tenor\.com\//.test(value)) return "Tenor link must be a direct link to the image. (e.g. https://media.tenor.com/...)";
|
||||||
return true;
|
return true;
|
||||||
|
@ -342,13 +329,10 @@ async function createActivity(): Promise<Activity | undefined> {
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case TimestampMode.CUSTOM:
|
case TimestampMode.CUSTOM:
|
||||||
if (startTime) {
|
if (startTime || endTime) {
|
||||||
activity.timestamps = {
|
activity.timestamps = {};
|
||||||
start: startTime,
|
if (startTime) activity.timestamps.start = startTime;
|
||||||
};
|
if (endTime) activity.timestamps.end = endTime;
|
||||||
if (endTime) {
|
|
||||||
activity.timestamps.end = endTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TimestampMode.NONE:
|
case TimestampMode.NONE:
|
||||||
|
|
Loading…
Reference in a new issue