From 9f6385e8fda89b91c41fa16f72cd71769abaae80 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Sun, 3 Nov 2019 04:40:53 +0100 Subject: [PATCH] fix: git api --- package.json | 8 ++++---- src/extension.ts | 16 +++++++--------- src/structures/Activity.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index db61395..525efbf 100644 --- a/package.json +++ b/package.json @@ -88,12 +88,12 @@ "discord.detailsEditing": { "type": "string", "default": "Editing {filename}", - "description": "Custom string for the details section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." + "description": "Custom string for the details section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{workspaceFolder}' will be replaced witht he currently access workspace folder, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." }, "discord.detailsDebugging": { "type": "string", "default": "Debugging {filename}", - "description": "Custom string for the details section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." + "description": "Custom string for the details section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{workspaceFolder}' will be replaced witht he currently access workspace folder, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." }, "discord.detailsIdle": { "type": "string", @@ -103,12 +103,12 @@ "discord.lowerDetailsEditing": { "type": "string", "default": "Workspace: {workspace}", - "description": "Custom string for the state section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." + "description": "Custom string for the state section of the rich presence\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name.\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{workspaceFolder}' will be replaced witht he currently access workspace folder, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." }, "discord.lowerDetailsDebugging": { "type": "string", "default": "Debugging: {workspace}", - "description": "Custom string for the state section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name..\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." + "description": "Custom string for the state section of the rich presence when debugging\n\t- '{null}' will be replaced with an empty space.\n\t- '{filename}' will be replaced with the current file name.\n\t- '{dirname}' will get replaced with the folder name that has the current file.\n\t- '{fulldirname}' will get replaced with the full directory name without the current file name..\n\t- '{workspace}' will be replaced with the current workspace name, if any.\n\t- '{workspaceFolder}' will be replaced witht he currently access workspace folder, if any.\n\t- '{currentcolumn}' will get replaced with the current column of the current line.\n\t- '{currentline}' will get replaced with the current line number.\n\t- '{totallines}' will get replaced with the total line number.\n\t- '{filesize}' will get replaced with the current file's size.\n\t- '{gitreponame}' will be replaced with the active Git repository name (from the git URL)\n\t- '{gitbranch}' will be replaced with the current active branch name." }, "discord.lowerDetailsIdle": { "type": "string", diff --git a/src/extension.ts b/src/extension.ts index 34ba302..58378bf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -92,16 +92,14 @@ export async function activate(context: ExtensionContext) { disableJoinRequests, ); - const gitExtension = extensions.getExtension('vscode.git'); - if (gitExtension) { - if (!gitExtension.exports.enabled) { - gitExtension.exports.onDidChangeEnablement(e => { - if (e) { - rpc.git = gitExtension.exports.getAPI(1); - } - }); + setTimeout(() => { + const gitExtension = extensions.getExtension('vscode.git'); + if (gitExtension) { + if (gitExtension.isActive) { + rpc.git = gitExtension.exports.getAPI(1); + } } - } + }, 5000); if (!isWorkspaceExcluded && config.get('enabled')) { statusBarIcon.show(); diff --git a/src/structures/Activity.ts b/src/structures/Activity.ts index daec1ce..6b82cfb 100644 --- a/src/structures/Activity.ts +++ b/src/structures/Activity.ts @@ -245,6 +245,7 @@ export default class Activity implements Disposable { let filename = null; let dirname = null; let checkState = false; + let workspaceName = null; let workspaceFolder = null; let fullDirname = null; if (window.activeTextEditor) { @@ -255,7 +256,7 @@ export default class Activity implements Disposable { dirname = split[split.length - 1]; checkState = Boolean(workspace.getWorkspaceFolder(window.activeTextEditor.document.uri)); - + workspaceName = workspace.name; workspaceFolder = checkState ? workspace.getWorkspaceFolder(window.activeTextEditor.document.uri) : null; if (workspaceFolder) { @@ -281,6 +282,14 @@ export default class Activity implements Disposable { .replace('{fulldirname}', fullDirname!) .replace( '{workspace}', + workspaceName + ? workspaceName + : checkState && workspaceFolder + ? workspaceFolder.name + : this.client.config.get('lowerDetailsNotFound')!.replace('{null}', empty), + ) + .replace( + '{workspaceFolder}', checkState && workspaceFolder ? workspaceFolder.name : this.client.config.get('lowerDetailsNotFound')!.replace('{null}', empty),