grammarly + new settings structure

This commit is contained in:
nin0dev 2024-06-11 06:46:17 -04:00
parent c9ebab41ba
commit a298057a84
2 changed files with 58 additions and 65 deletions

View file

@ -62,7 +62,7 @@ export function ReplaceTutorial() {
<pre style={{ fontFamily: "monospace" }}> <pre style={{ fontFamily: "monospace" }}>
:name:, :details:, :state: :name:, :details:, :state:
<br /> <br />
:large_image::large_text:, :small_image:, :small_text: :large_image:, :large_text:, :small_image:, :small_text:
</pre> </pre>
</Forms.FormText> </Forms.FormText>
</> </>
@ -93,16 +93,19 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
{ {
appIds.map((setting, i) => appIds.map((setting, i) =>
<Card style={{ padding: "1em 1em 0" }}> <Card style={{ padding: "1em 1em 0" }}>
<Switch {
value={setting.enabled} setting.appName !== "Unknown" ?
onChange={value => { <Switch
onChange(value, i, "enabled"); value={setting.enabled}
}} onChange={value => {
className={Margins.bottom16} onChange(value, i, "enabled");
hideBorder={true} }}
> className={Margins.bottom8}
Enable editing of {setting.appName} hideBorder={true}
</Switch> >
Edit the {setting.appName} app
</Switch> : <Forms.FormTitle tag="h3" className={Margins.bottom8}>Add new application</Forms.FormTitle>
}
<Forms.FormTitle>Application ID</Forms.FormTitle> <Forms.FormTitle>Application ID</Forms.FormTitle>
<CheckedTextInput <CheckedTextInput
value={setting.appId} value={setting.appId}
@ -113,43 +116,27 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
!v || isValidSnowflake(v) || "Invalid application ID" !v || isValidSnowflake(v) || "Invalid application ID"
} }
/> />
{setting.activityType === ActivityType.STREAMING && {
<> setting.appName !== "Unknown" ?
<Forms.FormTitle>Stream URL</Forms.FormTitle> <>
<CheckedTextInput <Forms.FormTitle className={Margins.top8}>New activity type</Forms.FormTitle>
value={setting.streamUrl} <Select
onChange={async v => { options={[
onChange(v, i, "streamUrl"); { label: "Playing", value: ActivityType.PLAYING },
}} { label: "Watching", value: ActivityType.WATCHING },
validate={st => !/https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+/.test(st) && "Only Twitch and Youtube URLs will work." || true} { label: "Listening", value: ActivityType.LISTENING },
/> { label: "Competing", value: ActivityType.COMPETING },
</>} { label: "Streaming", value: ActivityType.STREAMING }
<Forms.FormTitle>New activity type</Forms.FormTitle> ]}
<Select select={value => {
options={[ onChange(value, i, "activityType");
{ label: "Playing", value: ActivityType.PLAYING }, }}
{ label: "Watching", value: ActivityType.WATCHING }, className={Margins.top8}
{ label: "Listening", value: ActivityType.LISTENING }, isSelected={value => setting.newActivityType === value}
{ label: "Competing", value: ActivityType.COMPETING }, serialize={identity}
{ label: "Streaming", value: ActivityType.STREAMING } />
]} </> : null
select={value => { }
onChange(value, i, "activityType");
}}
className={Margins.bottom16}
isSelected={value => setting.activityType === value}
serialize={identity}
/>
<Switch
value={setting.swapNameAndDetails}
onChange={value => {
onChange(value, i, "swapNameAndDetails");
}}
className={Margins.bottom16}
hideBorder={true}
>
Swap presence name and details
</Switch>
</Card> </Card>
) )
} }

View file

@ -17,10 +17,16 @@ const APP_IDS_KEY = "ReplaceActivityType_appids";
export type AppIdSetting = { export type AppIdSetting = {
appName: string; appName: string;
appId: string; appId: string;
swapNameAndDetails: boolean;
activityType: ActivityType;
streamUrl: string;
enabled: boolean; enabled: boolean;
newActivityType: ActivityType;
newName: string,
newDetails: string,
newState: string,
newLargeImageUrl: string,
newLargeImageText: string,
newSmallImageUrl: string,
newSmallImageText: string;
newStreamUrl: string;
}; };
export interface Activity { export interface Activity {
@ -58,12 +64,18 @@ export const enum ActivityType {
} }
export const makeEmptyAppId: () => AppIdSetting = () => ({ export const makeEmptyAppId: () => AppIdSetting = () => ({
appId: "",
appName: "Unknown", appName: "Unknown",
streamUrl: "", appId: "",
swapNameAndDetails: false, enabled: true,
activityType: ActivityType.PLAYING, newActivityType: ActivityType.PLAYING,
enabled: true newName: "",
newDetails: "",
newState: "",
newLargeImageUrl: "",
newLargeImageText: "",
newSmallImageUrl: "",
newSmallImageText: "",
newStreamUrl: "",
}); });
let appIds = [makeEmptyAppId()]; let appIds = [makeEmptyAppId()];
@ -112,16 +124,10 @@ export default definePlugin({
console.log(activity); 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.activityType; activity.type = app.newActivityType;
if (app.activityType === ActivityType.STREAMING && app.streamUrl) { if (app.newActivityType === ActivityType.STREAMING && app.newStreamUrl) {
activity.url = app.streamUrl; activity.url = app.newStreamUrl;
}
if (app.swapNameAndDetails) {
const media = activity.details;
activity.details = activity.name;
activity.name = media;
} }
} }