Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch app if installed or redirect to download - windows

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.

Google Chrome's External Protocol Request

like image 937
416E64726577 Avatar asked Feb 18 '15 19:02

416E64726577


2 Answers

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.

add account

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.

clone in desktop

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.

protocol no understood

Yep, GitHub apparently blindly assumes that when your are using your account on a Windows computer, you must have GitHub for Windows installed.

like image 183
Alexander O'Mara Avatar answered Sep 19 '22 22:09

Alexander O'Mara


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.

like image 40
habsq Avatar answered Sep 20 '22 22:09

habsq