Stack Overflown asked in this question:
On every repo, GitHub has a button that is labelled "Clone in Desktop" (example: https://github.com/github/developer.github.com). If you have GitHub for Mac installed, the href is something like "github-mac://openRepo/https://github.com/github/developer.github.com". This opens GitHub for Mac and offers to clone the repo. If you don't, the href is "http://mac.github.io". This is a download page for GitHub for Mac. I would like to do something similar on my website: open my app if installed and redirect to download if not. How can this be best accomplished?
The answer was about Github Conduit, but, as far as I know, Github Conduit is only for Github for Mac.
I have the same question, only for Windows operating systems. How does GitHub know whether GitHub is installed on a computer, or not?
As deepcurious said in their answer, we need to use the following code that checks if a protocol is registered:
$("a[href*='github-windows://']").click(function(e) {
var el = $(this);
setTimeout(function() {
window.location = el.data("data-href-alt");
}, 200);
// once you do the custom-uri, it should properly execute the handler, otherwise, the settimeout that you set before will kick in
window.location = el.data("href");
e.preventDefault();
});
and I have the following HTML link:
<a href="github-windows://openRepo/https://github.com/jquery/api.jqueryui.com" data-href-alt="https://www.example.com/app-not-installed">Clone in Desktop</a>
If the app is installed, Google Chrome gives me an External Protocol Request (below), so I assume it should work (although it does nothing on my computer). But, if the app is not installed, it does not go to the data-href-alt
page.
For example, if I change github-windows://
to some-uninstalled-app://
in all instances in the code, the link does nothing.
It's true, GitHub Conduit is only for GitHub for Mac. So how does the GitHub website determine if GitHub for Windows is installed?
Well, GitHub for Windows is apparently much-less sophisticated in this regard. The "Clone in Desktop" will only work once you have installed GitHub for Windows and authenticated your account using the "Add account" button under options.
Once you have done this, so long as you are logged into the GitHub account you added to GitHub for Windows, the "Clone in Desktop" link will have the github-windows://
protocol, rather than the https://windows.github.com/
link.
But what happens if you login to GitHub on a computer that does not have GitHub for Windows installed and click the button? It has the same link, which will not work for obvious reasons.
Yep, GitHub apparently blindly assumes that when your are using your account on a Windows computer, you must have GitHub for Windows installed.
You can try the cross-browser custom protocol detection library which is written in JavaScript: https://github.com/ismailhabib/custom-protocol-detection
...or do something hacky like modifying browser's user agent during installation of your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With