From 4318c325ac39c90c9a2630355ba67fbc84f7ea01 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Fri, 24 Nov 2017 13:53:47 +0100 Subject: [PATCH] feat: custom string support --- README.md | 6 +++++- package.json | 42 +++++++++++++++++++++++++++++++++++++++++- src/extension.ts | 19 +++++++++---------- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1b09121..03a6e43 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,13 @@ Give me a little bit of time and this will be resolved! 😉 * Shows what you are editing in VSCode with no bullsh*t involved. * Enable/Disable Rich Presence for individual workspaces (enabled by default). +* Automatic reconnect after losing internet or a discord restart/crash. (defaults to 20 reconnect attempts) +* Custom string support ## The rich presence won't show after my PC has been put to sleep / after I lost internet! -It will only attempt to reconnect 20 times. After it hit that threshold you will have to manually enable it again. Just open the command pallette and execute the enable command for the extension. +It will only attempt to reconnect 20 times. After it hit that threshold you will have to manually enable it again. +Just open the command pallette and execute the enable command for the extension. +You can also set the reconnectThreshold in the settings to something very high, for example 9999 or Infinity to never stop trying to reconnect. ## Contributing diff --git a/package.json b/package.json index afb6a46..7ec84d9 100644 --- a/package.json +++ b/package.json @@ -41,12 +41,52 @@ "discord.clientID": { "type": "string", "default": "383226320970055681", - "description": "Only modify this if you know what you are doing (most of you don't)." + "description": "Only modify this if you know what you are doing (most of you don't)" }, "discord.enabled": { "type": "boolean", "default": true, "description": "Controls if Discord Presence is active" + }, + "discord.reconnectThreshold": { + "type": "number", + "default": 20, + "description": "Decides how often a reconnect attempt should be made before stopping" + }, + "discord.details": { + "type": "string", + "default": "Editing {filename}", + "description": "Custom string for the details section of the rich presence" + }, + "discord.detailsIdle": { + "type": "string", + "default": "Idling.", + "description": "Custom string for the details section of the rich presence when idling" + }, + "discord.workspace": { + "type": "string", + "default": "Workspace: {workspace}", + "description": "Custom string for the state section of the rich presence" + }, + "discord.workspaceIdle": { + "type": "string", + "default": "Idling.", + "description": "Custom string for the state section of the rich presence when idling" + }, + "discord.largeImage": { + "type": "string", + "default": "", + "description": "Custom string for the largeImageText section of the rich presence" + }, + "discord.largeImageIdle": { + "type": "string", + "default": "Idling", + "description": "Custom string for the largeImageText section of the rich presence when idling" + }, + "discord.smallImage": { + "type": "string", + "default": "Visual Studio Code", + "description": "Custom string for the smallImageText section of the rich presence" } } } diff --git a/src/extension.ts b/src/extension.ts index 68b0b71..f190bae 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -93,8 +93,8 @@ function initRPC(clientID: string): void { // Log in to the RPC Client, and check whether or not it errors. rpc.login(clientID).catch(error => { if (reconnect) { - // Destroy and dispose of everything after 20 reconnect attempts - if (reconnectCounter >= 20) destroyRPC(); + // Destroy and dispose of everything after a default of 20 reconnect attempts + if (reconnectCounter >= config.get('reconnectThreshold')) destroyRPC(); else return; } if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!'); @@ -126,15 +126,14 @@ function setActivity(): void { if (!rpc) return; if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return; lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null; - // Create a JSON Object with the user's activity information. const activity = { details: window.activeTextEditor - ? `Editing ${basename(window.activeTextEditor.document.fileName)}` - : 'Idle.', + ? config.get('details').replace('{filename}', basename(window.activeTextEditor.document.fileName)) + : config.get('detailsIdle'), state: window.activeTextEditor - ? `Workspace: ${workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name}` - : 'Idling.', + ? config.get('workspace').replace('{workspace}', workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name) + : config.get('workspaceIdle'), startTimestamp: new Date().getTime() / 1000, largeImageKey: window.activeTextEditor ? extname(basename(window.activeTextEditor.document.fileName)).substring(1) @@ -142,10 +141,10 @@ function setActivity(): void { || 'file' : 'vscode-big', largeImageText: window.activeTextEditor - ? window.activeTextEditor.document.languageId - : 'Idling', + ? config.get('largeImage') || window.activeTextEditor.document.languageId + : config.get('largeImageIdle'), smallImageKey: 'vscode', - smallImageText: 'Visual Studio Code', + smallImageText: config.get('smallImage'), instance: false };