From e83d913b6989d0ff52baf0a891dc89dad0bc60e9 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Wed, 10 Feb 2021 18:32:13 +0100 Subject: [PATCH] feat: swap big and small --- package.json | 7 ++++++- src/activity.ts | 35 ++++++++++++++++++++++++++++++----- src/constants.ts | 1 + src/util.ts | 1 + 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 218bf25..c79ad86 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "discord-vscode", "displayName": "Discord Presence", - "version": "5.0.0", + "version": "5.1.0", "description": "Update your discord status with a rich presence.", "private": true, "author": { @@ -124,6 +124,11 @@ }, "default": [], "description": "Patterns of workspaces to ignore" + }, + "discord.swapBigAndSmallImage": { + "type": "boolean", + "default": false, + "description": "Swaps the big and small image on the rich presence" } } } diff --git a/src/activity.ts b/src/activity.ts index 8ec193c..a34c85e 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -36,6 +36,7 @@ interface ActivityPayload { export async function activity(previous: ActivityPayload = {}) { const config = getConfig(); + const swapBigAndSmallImage = config[CONFIG_KEYS.SwapBigAndSmallImage]; const appName = env.appName; const defaultSmallImageKey = debug.activeDebugSession @@ -43,6 +44,8 @@ export async function activity(previous: ActivityPayload = {}) { : appName.includes('Insiders') ? VSCODE_INSIDERS_IMAGE_KEY : VSCODE_IMAGE_KEY; + const defaultSmallImageText = config[CONFIG_KEYS.SmallImage].replace(REPLACE_KEYS.AppName, appName); + const defaultLargeImageText = config[CONFIG_KEYS.LargeImageIdling]; let state: ActivityPayload = { details: await details(CONFIG_KEYS.DetailsIdling, CONFIG_KEYS.DetailsEditing, CONFIG_KEYS.DetailsDebugging), @@ -53,11 +56,21 @@ export async function activity(previous: ActivityPayload = {}) { ), startTimestamp: previous.startTimestamp ?? Date.now(), largeImageKey: IDLE_IMAGE_KEY, - largeImageText: config[CONFIG_KEYS.LargeImageIdling], + largeImageText: defaultLargeImageText, smallImageKey: defaultSmallImageKey, - smallImageText: config[CONFIG_KEYS.SmallImage].replace(REPLACE_KEYS.AppName, appName), + smallImageText: defaultSmallImageText, }; + if (swapBigAndSmallImage) { + state = { + ...state, + largeImageKey: defaultSmallImageKey, + largeImageText: defaultSmallImageText, + smallImageKey: IDLE_IMAGE_KEY, + smallImageText: defaultLargeImageText, + }; + } + if (window.activeTextEditor) { if (window.activeTextEditor.document.languageId === 'Log') { return state; @@ -78,10 +91,22 @@ export async function activity(previous: ActivityPayload = {}) { CONFIG_KEYS.LowerDetailsEditing, CONFIG_KEYS.LowerDetailsDebugging, ), - largeImageKey, - largeImageText, }; + if (swapBigAndSmallImage) { + state = { + ...state, + smallImageKey: largeImageKey, + smallImageText: largeImageText, + }; + } else { + state = { + ...state, + largeImageKey, + largeImageText, + }; + } + log(LogLevel.Trace, `VSCode language id: ${window.activeTextEditor.document.languageId}`); } @@ -142,7 +167,7 @@ async function fileDetails(_raw: string, document: TextDocument, selection: Sele const git = gitExtension?.exports.getAPI(1); if (raw.includes(REPLACE_KEYS.TotalLines)) { - raw = raw.replace(REPLACE_KEYS.TotalLines, document.toLocaleString()); + raw = raw.replace(REPLACE_KEYS.TotalLines, document.lineCount.toLocaleString()); } if (raw.includes(REPLACE_KEYS.CurrentLine)) { diff --git a/src/constants.ts b/src/constants.ts index 592b0d8..51452a2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -50,4 +50,5 @@ export const enum CONFIG_KEYS { SmallImage = 'smallImage', SuppressNotifications = 'suppressNotifications', WorkspaceExcludePatterns = 'workspaceExcludePatterns', + SwapBigAndSmallImage = 'swapBigAndSmallImage', } diff --git a/src/util.ts b/src/util.ts index 1cf0f0a..8da5a8a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -17,6 +17,7 @@ type WorkspaceExtensionConfigurationuration = WorkspaceConfiguration & { smallImage: string; suppressNotifications: boolean; workspaceExcludePatterns: string[]; + swapBigAndSmallImage: boolean; }; export function getConfig() {