From 983207ae48296f63212be5d64929bef4edf46da3 Mon Sep 17 00:00:00 2001 From: "berwyn (Jamison)" Date: Fri, 19 Apr 2019 07:00:44 -0400 Subject: [PATCH] Add Workspace Exclusion Regex Support (#220) --- package.json | 10 +++++++++- src/extension.ts | 16 +++++++++++++++- tsconfig.json | 5 ++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 642299d..253b854 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,15 @@ "type": "boolean", "default": false, "description": "Decides whether to display elapsed time for a workspace or a single file" - } + }, + "discord.workspaceExcludePatterns": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Patterns of workspaces to ignore" + } } } ] diff --git a/src/extension.ts b/src/extension.ts index 949744c..bd7a43d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,21 @@ const rpc = new RPCClient(config.get('clientID')!, statusBarIcon); export async function activate(context: ExtensionContext) { Logger.log('Discord Presence activated!'); - if (config.get('enabled')) { + let isWorkspaceExcluded = false; + const excludePatterns = config.get('workspaceExcludePatterns'); + if (excludePatterns && excludePatterns.length > 0) { + for (const pattern of excludePatterns) { + const regex = new RegExp(pattern); + const folders = workspace.workspaceFolders; + if (!folders) break; + if (folders.some((folder) => regex.test(folder.uri.fsPath))) { + isWorkspaceExcluded = true; + break; + } + } + } + + if (!isWorkspaceExcluded && config.get('enabled')) { statusBarIcon.show(); try { await rpc.login(); diff --git a/tsconfig.json b/tsconfig.json index c0860e9..8dbf839 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,10 @@ "declaration": true, "sourceMap": true, "removeComments": false, - "experimentalDecorators": true + "experimentalDecorators": true, + "typeRoots": [ + "node_modules/@types" + ] }, "include": [ "./src"