Skip to content

Commit

Permalink
feat: new button config
Browse files Browse the repository at this point in the history
  • Loading branch information
nick22985 committed Mar 13, 2023
1 parent 31cc14d commit d689dfb
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 255 deletions.
233 changes: 41 additions & 192 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,199 +462,48 @@
},
{
"title": "Buttons",
"type": "object",
"properties": {
"vscord.status.buttons.button1.enabled": {
"type": "boolean",
"default": true,
"description": "Should the button1 be shown?",
"order": 0
},
"vscord.status.buttons.button1.active.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button1 be shown when active?",
"order": 1
},
"vscord.status.buttons.button1.active.label": {
"type": "string",
"default": "Active Label Button 1",
"description": "The label to use when button1 is active.",
"order": 2
},
"vscord.status.buttons.button1.active.url": {
"type": "string",
"default": "https://github.com/leonardssh/vscord/",
"description": "The button1 url to use when active.",
"order": 3
},
"vscord.status.buttons.button1.git.active.enabled": {
"type": "boolean",
"default": true,
"description": "Should the button1 be shown when active?",
"order": 4
},
"vscord.status.buttons.button1.git.active.label": {
"type": "string",
"default": "View Repository",
"description": "The label to use when button1 is active.",
"order": 5
},
"vscord.status.buttons.button1.git.active.url": {
"type": "string",
"default": "{git_url}",
"description": "The button1 url to use when active.",
"order": 6
},
"vscord.status.buttons.button1.git.idle.enabled": {
"type": "boolean",
"default": true,
"description": "Should the button1 be shown when active?",
"order": 4
},
"vscord.status.buttons.button1.git.idle.label": {
"type": "string",
"default": "View Repository",
"description": "The label to use when button1 is active.",
"order": 8
},
"vscord.status.buttons.button1.git.idle.url": {
"type": "string",
"default": "{git_url}",
"description": "The button1 url to use when active.",
"order": 9
},
"vscord.status.buttons.button1.idle.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button1 be shown when idle?",
"order": 10
},
"vscord.status.buttons.button1.idle.label": {
"type": "string",
"default": "",
"description": "The label to use when button1 is idle.",
"order": 11
},
"vscord.status.buttons.button1.idle.url": {
"type": "string",
"default": "",
"description": "The button1 url to use idle.",
"order": 12
},
"vscord.status.buttons.button1.inactive.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button1 be shown when inactive?",
"order": 13
},
"vscord.status.buttons.button1.inactive.label": {
"type": "string",
"default": "",
"description": "The label to show when button1 is inactive.",
"order": 14
},
"vscord.status.buttons.button1.inactive.url": {
"type": "string",
"default": "",
"description": "The button1 url to use when inactive.",
"order": 15
},
"vscord.status.buttons.button2.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button2 be shown?",
"order": 16
},
"vscord.status.buttons.button2.active.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button2 be shown when active?",
"order": 17
},
"vscord.status.buttons.button2.active.label": {
"type": "string",
"default": "Active Label Button 2",
"description": "The label to use when button2 is active.",
"order": 18
},
"vscord.status.buttons.button2.active.url": {
"type": "string",
"default": "https://github.com/leonardssh/vscord/",
"description": "The button2 url to use when active.",
"order": 19
},
"vscord.status.buttons.button2.git.active.enabled": {
"type": "boolean",
"default": true,
"description": "Should the button2 be shown when active?",
"order": 20
},
"vscord.status.buttons.button2.git.active.label": {
"type": "string",
"default": "View Repository",
"description": "The label to use when button2 is active.",
"order": 21
},
"vscord.status.buttons.button2.git.active.url": {
"type": "string",
"default": "{git_url}",
"description": "The button2 url to use when active.",
"order": 22
},
"vscord.status.buttons.button2.git.idle.enabled": {
"type": "boolean",
"default": true,
"description": "Should the button2 be shown when active?",
"order": 23
},
"vscord.status.buttons.button2.git.idle.label": {
"type": "string",
"default": "View Repository",
"description": "The label to use when button2 is active.",
"order": 24
},
"vscord.status.buttons.button2.git.idle.url": {
"type": "string",
"default": "{git_url}",
"description": "The button2 url to use when active.",
"order": 25
},
"vscord.status.buttons.button2.idle.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button2 be shown when idle?",
"order": 26
},
"vscord.status.buttons.button2.idle.label": {
"type": "string",
"default": "",
"description": "The label to use when button2 is idle.",
"order": 27
},
"vscord.status.buttons.button2.idle.url": {
"type": "string",
"default": "",
"description": "The button2 url to use idle.",
"order": 28
},
"vscord.status.buttons.button2.inactive.enabled": {
"type": "boolean",
"default": false,
"description": "Should the button2 be shown when inactive?",
"order": 29
},
"vscord.status.buttons.button2.inactive.label": {
"type": "string",
"default": "",
"description": "The label to show when inactive.",
"order": 30
},
"vscord.status.buttons.button2.inactive.url": {
"type": "string",
"default": "",
"description": "The button2 url to use when inactive.",
"order": 31
"vscord.buttons": {
"type": "object",
"markdownDescription": "The buttons to show in the rich presence. You can have to buttons 1 & 2. The valid config for the buttons are active, inactive, idle. Git has its own idle and active buttons **Example**: \n```js\n\"vscord.buttons\": {\n \"button1\": {\n \"enabled\": true,\n \"active\": {\n \"enabled\": true,\n \"label\": \"Active Label Button 1\",\n \"url\": \"\" // The url to open when the button is clicked.\n },\n \"git\": {\n \"enabled\": true,\n \"active\": {\n \"enabled\": true,\n \"label\": \"View Repository\",\n \"url\": \"{git_url}\" // The url to open when the button is clicked.\n }\n }\n }...cont\n```",
"default": {
"button1": {
"enabled": true,
"active": {
"enabled": true,
"label": "Active Label Button 1",
"url": "https://github.com/leonardssh/vscord"
},
"inactive": {
"enabled": true,
"label": "Inactive Label Button 1",
"url": "https://github.com/leonardssh/vscord"
},
"idle": {
"enabled": true,
"label": "Idle Label Button 1",
"url": "https://github.com/leonardssh/vscord"
},
"git": {
"enabled": true,
"active": {
"enabled": true,
"label": "View Repository",
"url": "{git_url}"
},
"inactive": {
"enabled": true,
"label": "View Repository",
"url": "{git_url}"
},
"idle": {
"enabled": true,
"label": "View Repository",
"url": "{git_url}"
}
}
}
}
}
}
},
Expand Down
6 changes: 1 addition & 5 deletions src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,9 @@ function buttonValidation(
button: GatewayActivityButton | undefined;
validationError: string;
} {
let validationError = "";
if (!button) return { button: undefined, validationError: "" };
let validationError = "";
if (!button.label || !button.url) {
console.log("label", button.label);
console.log("url", button.url);
validationError += `Invalid ${!button.label ? `Label` : ""} ${!button.label && !button.url ? "and " : ""}${
!button.url ? "Url" : ""
} for ${state}.`;
Expand Down Expand Up @@ -329,7 +327,6 @@ export const getPresenceButtons = async (
let button2 = buttonValidation(await createButton(replaceAllText, state, isGit, "Button2"), "Button2");
if (button1.validationError || button2.validationError)
window.showErrorMessage(button1.validationError + " " + button2.validationError);

return [button1.button, button2.button].filter(Boolean) as GatewayActivityButton[];
};

Expand Down Expand Up @@ -408,7 +405,6 @@ export const replaceFileInfo = async (
): Promise<string> => {
const config = getConfig();
text = text.slice();

let workspaceFolderName =
dataClass.workspaceFolder?.name ?? config.get(CONFIG_KEYS.Status.Details.Text.NoWorkspaceText)!;
let workspaceName = dataClass.workspaceName ?? config.get(CONFIG_KEYS.Status.Details.Text.NoWorkspaceText)!;
Expand Down
50 changes: 24 additions & 26 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ import { type filesize } from "filesize";
export type FileSizeConfig = Parameters<typeof filesize>["1"];
export type FileSizeStandard = "iec" | "jedec";

interface buttonStatus {
enabled: boolean;
label: string;
url: string;
}

interface button {
enabled: boolean;
active: buttonStatus;
idle: buttonStatus;
inactive: buttonStatus;
git: {
active: buttonStatus;
idle: buttonStatus;
inactive: buttonStatus;
};
}

interface buttons {
button1: button;
button2: button;
}

export interface ExtensionConfigurationType {
"app.id": string;
"app.name": "Code" | "Visual Studio Code" | "VSCodium" | "Custom";
Expand All @@ -28,32 +51,7 @@ export interface ExtensionConfigurationType {
"status.state.text.debugging": string;
"status.state.text.notInFile": string;
"status.state.text.noWorkspaceFound": string;
"status.buttons.button1.enabled": boolean;
"status.buttons.button1.active.enabled": boolean;
"status.buttons.button1.active.label": string;
"status.buttons.button1.active.url": string;
"status.buttons.button1.git.enabled": boolean;
"status.buttons.button1.git.label": string;
"status.buttons.button1.git.url": string;
"status.buttons.button1.idle.enabled": boolean;
"status.buttons.button1.idle.label": string;
"status.buttons.button1.idle.url": string;
"status.buttons.button1.inactive.enabled": boolean;
"status.buttons.button1.inactive.label": string;
"status.buttons.button1.inactive.url": string;
"status.buttons.button2.enabled": boolean;
"status.buttons.button2.active.enabled": boolean;
"status.buttons.button2.active.label": string;
"status.buttons.button2.active.url": string;
"status.buttons.button2.git.enabled": boolean;
"status.buttons.button2.git.label": string;
"status.buttons.button2.git.url": string;
"status.buttons.button2.idle.enabled": boolean;
"status.buttons.button2.idle.label": string;
"status.buttons.button2.idle.url": string;
"status.buttons.button2.inactive.enabled": boolean;
"status.buttons.button2.inactive.label": string;
"status.buttons.button2.inactive.url": string;
buttons: buttons;
"status.image.large.idle.key": string;
"status.image.large.idle.text": string;
"status.image.large.viewing.key": string;
Expand Down
Loading

0 comments on commit d689dfb

Please sign in to comment.