feat: custom string support

This commit is contained in:
iCrawl 2017-11-24 13:53:47 +01:00
parent 04442116dc
commit 4318c325ac
No known key found for this signature in database
GPG key ID: E41A6DB922EC2CFE
3 changed files with 55 additions and 12 deletions

View file

@ -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. * Shows what you are editing in VSCode with no bullsh*t involved.
* Enable/Disable Rich Presence for individual workspaces (enabled by default). * 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! ## 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 ## Contributing

View file

@ -41,12 +41,52 @@
"discord.clientID": { "discord.clientID": {
"type": "string", "type": "string",
"default": "383226320970055681", "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": { "discord.enabled": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
"description": "Controls if Discord Presence is active" "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"
} }
} }
} }

View file

@ -93,8 +93,8 @@ function initRPC(clientID: string): void {
// Log in to the RPC Client, and check whether or not it errors. // Log in to the RPC Client, and check whether or not it errors.
rpc.login(clientID).catch(error => { rpc.login(clientID).catch(error => {
if (reconnect) { if (reconnect) {
// Destroy and dispose of everything after 20 reconnect attempts // Destroy and dispose of everything after a default of 20 reconnect attempts
if (reconnectCounter >= 20) destroyRPC(); if (reconnectCounter >= config.get('reconnectThreshold')) destroyRPC();
else return; else return;
} }
if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!'); if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!');
@ -126,15 +126,14 @@ function setActivity(): void {
if (!rpc) return; if (!rpc) return;
if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return; if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return;
lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null; lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null;
// Create a JSON Object with the user's activity information. // Create a JSON Object with the user's activity information.
const activity = { const activity = {
details: window.activeTextEditor details: window.activeTextEditor
? `Editing ${basename(window.activeTextEditor.document.fileName)}` ? config.get('details').replace('{filename}', basename(window.activeTextEditor.document.fileName))
: 'Idle.', : config.get('detailsIdle'),
state: window.activeTextEditor state: window.activeTextEditor
? `Workspace: ${workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name}` ? config.get('workspace').replace('{workspace}', workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name)
: 'Idling.', : config.get('workspaceIdle'),
startTimestamp: new Date().getTime() / 1000, startTimestamp: new Date().getTime() / 1000,
largeImageKey: window.activeTextEditor largeImageKey: window.activeTextEditor
? extname(basename(window.activeTextEditor.document.fileName)).substring(1) ? extname(basename(window.activeTextEditor.document.fileName)).substring(1)
@ -142,10 +141,10 @@ function setActivity(): void {
|| 'file' || 'file'
: 'vscode-big', : 'vscode-big',
largeImageText: window.activeTextEditor largeImageText: window.activeTextEditor
? window.activeTextEditor.document.languageId ? config.get('largeImage') || window.activeTextEditor.document.languageId
: 'Idling', : config.get('largeImageIdle'),
smallImageKey: 'vscode', smallImageKey: 'vscode',
smallImageText: 'Visual Studio Code', smallImageText: config.get('smallImage'),
instance: false instance: false
}; };