Launch app if installed or redirect to download - windows
Asked Answered
F

2

11

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

Forenoon answered 18/2, 2015 at 19:39 Comment(5)
I'm just guessing but knowing how custom protocol handlers work, maybe it just finds out if its custom protocol is handled. If yes, its app will start. If no, it redirects. So your question boils down to how to find if a given custom protocol has a handler installed for it. See #24779812Ejaculatory
#837277Forthright
I think this might belong in WebApps. you might get better luck there! :)Zoolatry
@sircapsalot WebApps is for users of apps, not for developers who write the webapps. His question belongs here.Ejaculatory
as far as I'm concerned, this question has to do with how "GitHub" knows whether a client is installed on the computer. not particularly related to a specific programming problem. although it's probably moot anyway since they have an open bounty for the questionZoolatry
T
1

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.

Tradition answered 23/2, 2015 at 17:1 Comment(2)
Thank you, this is very useful. But, is it possible to make such a scheme to work in Windows, like it does in Mac OS?Forenoon
@010000010110111001100100011100 I would expect you could. I don't know why GitHub chose to do it differently between Windows and Mac.Eadie
E
1

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.

Ehtelehud answered 21/6, 2015 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.