diff --git a/extension.js b/extension.js index ecfc178..2f1c20c 100644 --- a/extension.js +++ b/extension.js @@ -2,15 +2,19 @@ const { mob } = require("./src/git/commands"); const { setupGitMob } = require("./src/setup-git-mob"); const { GitExt } = require("./src/vscode-git-extension/git-ext"); const { installPrompt } = require("./src/install-prompt"); +const { waitForRepos } = require("./src/wait-for-repos"); function activate(context) { - if (mob.gitMobLatest() === 1) { - installPrompt(() => { - setupGitMob(context, new GitExt()); - }); - } else { - setupGitMob(context, new GitExt()); - } + const gitExt = new GitExt(); + waitForRepos(gitExt, () => { + if (mob.gitMobLatest() === 1) { + installPrompt(() => { + setupGitMob(context, gitExt); + }); + } else { + setupGitMob(context, gitExt); + } + }); } exports.activate = activate; diff --git a/src/setup-git-mob.js b/src/setup-git-mob.js index a94cf0e..b9959c9 100644 --- a/src/setup-git-mob.js +++ b/src/setup-git-mob.js @@ -21,26 +21,11 @@ const { const { soloAfterCommit } = require("./ext-config/solo-after-commit"); const { searchGithubAuthors } = require("./commands/github-authors"); -const MAX_RETRIES = 5; - function setupGitMob(context, gitExt) { gitExt.gitApi.onDidOpenRepository(function () { bootGitMob(context, gitExt); }); - - waitForRepos(gitExt, MAX_RETRIES, () => { - bootGitMob(context, gitExt); - }); -} - -function waitForRepos(gitExt, retries, bootFn) { - if (gitExt.hasRepositories) { - bootFn(); - } else { - if (retries > 0) { - setTimeout(() => waitForRepos(hasRepo, retries - 1, bootFn), 1000); - } - } + bootGitMob(context, gitExt); } function bootGitMob(context, gitExt) { diff --git a/src/wait-for-repos.js b/src/wait-for-repos.js new file mode 100644 index 0000000..2805b2e --- /dev/null +++ b/src/wait-for-repos.js @@ -0,0 +1,11 @@ +function waitForRepos(gitExt, bootFn, retries = 5) { + if (gitExt.hasRepositories) { + bootFn(); + } else { + if (retries > 0) { + setTimeout(() => waitForRepos(gitExt, bootFn, retries - 1), 1000); + } + } +} + +exports.waitForRepos = waitForRepos;