diff --git a/package.json b/package.json index cfd5470..1f3c954 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,11 @@ "default": "Idling.", "description": "Custom string for the state section of the rich presence when idling" }, + "discord.workspaceNotFound": { + "type": "string", + "default": "No workspace.", + "description": "Custom string for the state section of the rich presence when no workspace is found" + }, "discord.largeImage": { "type": "string", "default": "", diff --git a/src/extension.ts b/src/extension.ts index f190bae..6fba01f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -126,14 +126,23 @@ function setActivity(): void { if (!rpc) return; if (window.activeTextEditor && window.activeTextEditor.document.fileName === lastKnownFileName) return; lastKnownFileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : null; + + const details = window.activeTextEditor + ? config.get('details').replace('{filename}', basename(window.activeTextEditor.document.fileName)) + : config.get('detailsIdle'); + const checkState = window.activeTextEditor + ? Boolean(workspace.getWorkspaceFolder(window.activeTextEditor.document.uri)) + : false; + const state = window.activeTextEditor + ? checkState + ? config.get('workspace').replace('{workspace}', workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name) + : config.get('workspaceNotFound') + : config.get('workspaceIdle'); + // Create a JSON Object with the user's activity information. const activity = { - details: window.activeTextEditor - ? config.get('details').replace('{filename}', basename(window.activeTextEditor.document.fileName)) - : config.get('detailsIdle'), - state: window.activeTextEditor - ? config.get('workspace').replace('{workspace}', workspace.getWorkspaceFolder(window.activeTextEditor.document.uri).name) - : config.get('workspaceIdle'), + details, + state, startTimestamp: new Date().getTime() / 1000, largeImageKey: window.activeTextEditor ? extname(basename(window.activeTextEditor.document.fileName)).substring(1)