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" }}>
{
setting.appName !== "Unknown" ?
<Switch <Switch
value={setting.enabled} value={setting.enabled}
onChange={value => { onChange={value => {
onChange(value, i, "enabled"); onChange(value, i, "enabled");
}} }}
className={Margins.bottom16} className={Margins.bottom8}
hideBorder={true} hideBorder={true}
> >
Enable editing of {setting.appName} Edit the {setting.appName} app
</Switch> </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,18 +116,10 @@ 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> <Forms.FormTitle className={Margins.top8}>New activity type</Forms.FormTitle>
<CheckedTextInput
value={setting.streamUrl}
onChange={async v => {
onChange(v, i, "streamUrl");
}}
validate={st => !/https?:\/\/(www\.)?(twitch\.tv|youtube\.com)\/\w+/.test(st) && "Only Twitch and Youtube URLs will work." || true}
/>
</>}
<Forms.FormTitle>New activity type</Forms.FormTitle>
<Select <Select
options={[ options={[
{ label: "Playing", value: ActivityType.PLAYING }, { label: "Playing", value: ActivityType.PLAYING },
@ -136,20 +131,12 @@ export function ReplaceSettings({ appIds, update, save }: SettingsProps) {
select={value => { select={value => {
onChange(value, i, "activityType"); onChange(value, i, "activityType");
}} }}
className={Margins.bottom16} className={Margins.top8}
isSelected={value => setting.activityType === value} isSelected={value => setting.newActivityType === value}
serialize={identity} serialize={identity}
/> />
<Switch </> : null
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;
} }
} }