feat: swap big and small

This commit is contained in:
iCrawl 2021-02-10 18:32:13 +01:00
parent b0af2f23a6
commit e83d913b69
No known key found for this signature in database
GPG key ID: 1AB888B16355FBB2
4 changed files with 38 additions and 6 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "discord-vscode", "name": "discord-vscode",
"displayName": "Discord Presence", "displayName": "Discord Presence",
"version": "5.0.0", "version": "5.1.0",
"description": "Update your discord status with a rich presence.", "description": "Update your discord status with a rich presence.",
"private": true, "private": true,
"author": { "author": {
@ -124,6 +124,11 @@
}, },
"default": [], "default": [],
"description": "Patterns of workspaces to ignore" "description": "Patterns of workspaces to ignore"
},
"discord.swapBigAndSmallImage": {
"type": "boolean",
"default": false,
"description": "Swaps the big and small image on the rich presence"
} }
} }
} }

View file

@ -36,6 +36,7 @@ interface ActivityPayload {
export async function activity(previous: ActivityPayload = {}) { export async function activity(previous: ActivityPayload = {}) {
const config = getConfig(); const config = getConfig();
const swapBigAndSmallImage = config[CONFIG_KEYS.SwapBigAndSmallImage];
const appName = env.appName; const appName = env.appName;
const defaultSmallImageKey = debug.activeDebugSession const defaultSmallImageKey = debug.activeDebugSession
@ -43,6 +44,8 @@ export async function activity(previous: ActivityPayload = {}) {
: appName.includes('Insiders') : appName.includes('Insiders')
? VSCODE_INSIDERS_IMAGE_KEY ? VSCODE_INSIDERS_IMAGE_KEY
: VSCODE_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 = { let state: ActivityPayload = {
details: await details(CONFIG_KEYS.DetailsIdling, CONFIG_KEYS.DetailsEditing, CONFIG_KEYS.DetailsDebugging), 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(), startTimestamp: previous.startTimestamp ?? Date.now(),
largeImageKey: IDLE_IMAGE_KEY, largeImageKey: IDLE_IMAGE_KEY,
largeImageText: config[CONFIG_KEYS.LargeImageIdling], largeImageText: defaultLargeImageText,
smallImageKey: defaultSmallImageKey, 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) {
if (window.activeTextEditor.document.languageId === 'Log') { if (window.activeTextEditor.document.languageId === 'Log') {
return state; return state;
@ -78,10 +91,22 @@ export async function activity(previous: ActivityPayload = {}) {
CONFIG_KEYS.LowerDetailsEditing, CONFIG_KEYS.LowerDetailsEditing,
CONFIG_KEYS.LowerDetailsDebugging, 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}`); 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); const git = gitExtension?.exports.getAPI(1);
if (raw.includes(REPLACE_KEYS.TotalLines)) { 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)) { if (raw.includes(REPLACE_KEYS.CurrentLine)) {

View file

@ -50,4 +50,5 @@ export const enum CONFIG_KEYS {
SmallImage = 'smallImage', SmallImage = 'smallImage',
SuppressNotifications = 'suppressNotifications', SuppressNotifications = 'suppressNotifications',
WorkspaceExcludePatterns = 'workspaceExcludePatterns', WorkspaceExcludePatterns = 'workspaceExcludePatterns',
SwapBigAndSmallImage = 'swapBigAndSmallImage',
} }

View file

@ -17,6 +17,7 @@ type WorkspaceExtensionConfigurationuration = WorkspaceConfiguration & {
smallImage: string; smallImage: string;
suppressNotifications: boolean; suppressNotifications: boolean;
workspaceExcludePatterns: string[]; workspaceExcludePatterns: string[];
swapBigAndSmallImage: boolean;
}; };
export function getConfig() { export function getConfig() {