Add Workspace Exclusion Regex Support (#220)

This commit is contained in:
berwyn (Jamison) 2019-04-19 07:00:44 -04:00 committed by Crawl
parent 4c01c27b09
commit 983207ae48
3 changed files with 28 additions and 3 deletions

View file

@ -138,6 +138,14 @@
"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"
}
}
}

View file

@ -20,7 +20,21 @@ const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon);
export async function activate(context: ExtensionContext) {
Logger.log('Discord Presence activated!');
if (config.get<boolean>('enabled')) {
let isWorkspaceExcluded = false;
const excludePatterns = config.get<string[]>('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<boolean>('enabled')) {
statusBarIcon.show();
try {
await rpc.login();

View file

@ -13,7 +13,10 @@
"declaration": true,
"sourceMap": true,
"removeComments": false,
"experimentalDecorators": true
"experimentalDecorators": true,
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"./src"