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",
"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"
}
}
}

View file

@ -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,9 +91,21 @@ export async function activity(previous: ActivityPayload = {}) {
CONFIG_KEYS.LowerDetailsEditing,
CONFIG_KEYS.LowerDetailsDebugging,
),
};
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)) {

View file

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

View file

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