fix: git extension
This commit is contained in:
parent
ef71c60fc5
commit
8af1c12dc4
4 changed files with 46 additions and 21 deletions
|
@ -13,7 +13,7 @@ export default class RPCClient implements Disposable {
|
|||
|
||||
public config = workspace.getConfiguration('discord');
|
||||
|
||||
public git!: API;
|
||||
public git?: API;
|
||||
|
||||
private _rpc: any;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import Logger from './structures/Logger';
|
|||
import { GitExtension } from './git';
|
||||
const { register } = require('discord-rpc'); // eslint-disable-line
|
||||
|
||||
const sleep = (wait: number) => new Promise(resolve => setTimeout(resolve, wait));
|
||||
let loginTimeout: NodeJS.Timer;
|
||||
|
||||
const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignment.Left);
|
||||
|
@ -15,18 +14,6 @@ register(config.get<string>('clientID')!);
|
|||
const rpc = new RPCClient(config.get<string>('clientID')!, statusBarIcon);
|
||||
|
||||
export async function activate(context: ExtensionContext) {
|
||||
try {
|
||||
const ext = extensions.getExtension<GitExtension>('vscode.git')!;
|
||||
await ext.activate();
|
||||
rpc.git = ext.exports.getAPI(1);
|
||||
} catch {
|
||||
// We loaded before the git extension, give it a bit to load
|
||||
// In a perfect world this shouldn't happen
|
||||
await sleep(2000);
|
||||
const ext = extensions.getExtension<GitExtension>('vscode.git')!;
|
||||
await ext.activate();
|
||||
rpc.git = ext.exports.getAPI(1);
|
||||
}
|
||||
Logger.log('Discord Presence activated!');
|
||||
|
||||
let isWorkspaceExcluded = false;
|
||||
|
@ -105,6 +92,17 @@ export async function activate(context: ExtensionContext) {
|
|||
disableJoinRequests,
|
||||
);
|
||||
|
||||
const gitExtension = extensions.getExtension<GitExtension>('vscode.git');
|
||||
if (gitExtension) {
|
||||
if (!gitExtension.exports.enabled) {
|
||||
gitExtension.exports.onDidChangeEnablement(e => {
|
||||
if (e) {
|
||||
rpc.git = gitExtension.exports.getAPI(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!isWorkspaceExcluded && config.get<boolean>('enabled')) {
|
||||
statusBarIcon.show();
|
||||
try {
|
||||
|
|
33
src/git.d.ts
vendored
33
src/git.d.ts
vendored
|
@ -3,7 +3,8 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*/
|
||||
|
||||
import { Uri, Event } from 'vscode';
|
||||
// eslint-disable-next-line
|
||||
import { Uri, SourceControlInputBox, Event, CancellationToken } from 'vscode';
|
||||
|
||||
export interface Git {
|
||||
readonly path: string;
|
||||
|
@ -41,6 +42,7 @@ export interface Commit {
|
|||
readonly hash: string;
|
||||
readonly message: string;
|
||||
readonly parents: string[];
|
||||
readonly authorEmail?: string | undefined;
|
||||
}
|
||||
|
||||
export interface Submodule {
|
||||
|
@ -67,6 +69,7 @@ export const enum Status {
|
|||
DELETED,
|
||||
UNTRACKED,
|
||||
IGNORED,
|
||||
INTENT_TO_ADD,
|
||||
|
||||
ADDED_BY_US,
|
||||
ADDED_BY_THEM,
|
||||
|
@ -108,6 +111,14 @@ export interface RepositoryUIState {
|
|||
readonly onDidChange: Event<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log options.
|
||||
*/
|
||||
export interface LogOptions {
|
||||
/** Max number of log entries to retrieve. If not specified, the default is 32. */
|
||||
readonly maxEntries?: number;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
|
@ -117,6 +128,7 @@ export interface Repository {
|
|||
getConfigs(): Promise<{ key: string; value: string }[]>;
|
||||
getConfig(key: string): Promise<string>;
|
||||
setConfig(key: string, value: string): Promise<string>;
|
||||
getGlobalConfig(key: string): Promise<string>;
|
||||
|
||||
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>;
|
||||
detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }>;
|
||||
|
@ -128,11 +140,16 @@ export interface Repository {
|
|||
|
||||
apply(patch: string, reverse?: boolean): Promise<void>;
|
||||
diff(cached?: boolean): Promise<string>;
|
||||
diffWithHEAD(): Promise<Change[]>;
|
||||
diffWithHEAD(path: string): Promise<string>;
|
||||
diffWith(ref: string): Promise<Change[]>;
|
||||
diffWith(ref: string, path: string): Promise<string>;
|
||||
diffIndexWithHEAD(): Promise<Change[]>;
|
||||
diffIndexWithHEAD(path: string): Promise<string>;
|
||||
diffIndexWith(ref: string): Promise<Change[]>;
|
||||
diffIndexWith(ref: string, path: string): Promise<string>;
|
||||
diffBlobs(object1: string, object2: string): Promise<string>;
|
||||
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
|
||||
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
|
||||
|
||||
hashObject(data: string): Promise<string>;
|
||||
|
@ -150,12 +167,19 @@ export interface Repository {
|
|||
addRemote(name: string, url: string): Promise<void>;
|
||||
removeRemote(name: string): Promise<void>;
|
||||
|
||||
fetch(remote?: string, ref?: string): Promise<void>;
|
||||
pull(): Promise<void>;
|
||||
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
|
||||
pull(unshallow?: boolean): Promise<void>;
|
||||
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
|
||||
|
||||
blame(path: string): Promise<string>;
|
||||
log(options?: LogOptions): Promise<Commit[]>;
|
||||
}
|
||||
|
||||
export type APIState = 'uninitialized' | 'initialized';
|
||||
|
||||
export interface API {
|
||||
readonly state: APIState;
|
||||
readonly onDidChangeState: Event<APIState>;
|
||||
readonly git: Git;
|
||||
readonly repositories: Repository[];
|
||||
readonly onDidOpenRepository: Event<Repository>;
|
||||
|
@ -211,4 +235,7 @@ export const enum GitErrorCodes {
|
|||
WrongCase = 'WrongCase',
|
||||
CantLockRef = 'CantLockRef',
|
||||
CantRebaseMultipleBranches = 'CantRebaseMultipleBranches',
|
||||
PatchDoesNotApply = 'PatchDoesNotApply',
|
||||
NoPathFound = 'NoPathFound',
|
||||
UnknownPath = 'UnknownPath',
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ export default class Activity implements Disposable {
|
|||
}
|
||||
|
||||
if (str.includes('{gitbranch}')) {
|
||||
if (this.client.git.repositories.length) {
|
||||
if (this.client.git?.repositories.length) {
|
||||
fileDetail.gitbranch = this.client.git.repositories.find(repo => repo.ui.selected)!.state.HEAD!.name;
|
||||
} else {
|
||||
fileDetail.gitbranch = 'Unknown';
|
||||
|
@ -345,7 +345,7 @@ export default class Activity implements Disposable {
|
|||
}
|
||||
|
||||
if (str.includes('{gitreponame}')) {
|
||||
if (this.client.git.repositories.length) {
|
||||
if (this.client.git?.repositories.length) {
|
||||
fileDetail.gitreponame = this.client.git.repositories
|
||||
.find(repo => repo.ui.selected)!
|
||||
.state.remotes[0].fetchUrl!.split('/')[1]
|
||||
|
|
Loading…
Reference in a new issue