windows - 启动应用程序(如果已安装)或重定向以下载 - Windows

标签 windows macos github url-scheme github-for-windows

Stack Overflownthis 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?

答案大约是 Github Conduit ,但是,据我所知,Github Conduit 仅适用于 Github for Mac .

我有同样的问题,仅适用于 Windows 操作系统。 GitHub 如何知道计算机上是否安装了 GitHub?


作为deepcurioustheir answer 中说,我们需要使用以下代码来检查协议(protocol)是否已注册:

$("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();
});

我有以下 HTML 链接:

<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>

如果安装了该应用程序,谷歌浏览器会向我提供一个外部协议(protocol)请求(如下),因此我认为它应该可以正常工作(尽管它在我的计算机上没有任何作用)。但是,如果未安装该应用程序,它不会转到 data-href-alt 页面。

例如,如果我在代码的所有实例中将 github-windows:// 更改为 some-uninstalled-app://,则该链接不执行任何操作。

Google Chrome's External Protocol Request

最佳答案

的确,GitHub Conduit 仅适用于 GitHub for Mac。那么GitHub官网是如何判断是否安装了GitHub for Windows的呢?

嗯,GitHub for Windows 在这方面显然没有那么复杂。 “在桌面上克隆”只有在您安装了适用于 Windows 的 GitHub 并使用选项下的“添加帐户”按钮验证了您的帐户后才能使用。

add account

完成此操作后,只要登录到添加到 GitHub for Windows 的 GitHub 帐户,“在桌面上克隆”链接将具有 github-windows:// 协议(protocol),而不是 https://windows.github.com/ 链接。

clone in desktop

但是,如果您在未安装 GitHub for Windows 的计算机上登录 GitHub 并单击该按钮,会发生什么情况?它具有相同的链接,但由于显而易见的原因而无法使用。

protocol no understood

是的,GitHub 显然盲目地假设当您在 Windows 计算机上使用您的帐户时,您必须安装 GitHub for Windows。

关于windows - 启动应用程序(如果已安装)或重定向以下载 - Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28592409/

相关文章:

git - 已弃用的普通用户和密码

c++ - 用户锁定屏幕的 Windows 消息

java - java中如何检查光标类型?

c - 简单的 C 程序在 OS X 上编译但不在 Fedora 16 上编译,包含但未使用 math.h

linux - bash - 获取运行脚本的目录

templates - GitHub 拉取请求模板 : get current branch name

c++ - 工作站锁定时如何注销用户?

windows - 验证内存中的进程完整性?

c++ - 旧 C++ 代码中的目录查找导致 OS X Catalina 10.15 中的目录错误

linux - 无法更新适用于 Linux 的 Github 桌面(错误 : 429 Too Many Requests)