Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST]如何支持web client app Protocol #266

Closed
andywu188 opened this issue Jun 8, 2022 · 6 comments
Closed

[REQUEST]如何支持web client app Protocol #266

andywu188 opened this issue Jun 8, 2022 · 6 comments

Comments

@andywu188
Copy link

andywu188 commented Jun 8, 2022

如何实现通过NanUI浏览器访问以下网址时,打开指定的应用程序,实现和chrome浏览器一样的效果

search://
skype://
vscode://schemas/settings/user
vscode://vscode.git/clone?url=git%40github.com%3AMicrosoft%2Fvscode-vsce.git
vscode://open?url=file://%file&line=%line

除此之外,只要是系统中已安装的软件并支持web client app Protocol的软件,都能在NanUI调用

以下为示例页面:
http://www.gridreport.cn/demos/html5/General/ViewReport-WebApp.htm?report=1b&data=Customer
通过chrome或edge浏览器打开以上网址后,点击“打印预览”,会调用已安装的客户端程序,如果没安装,则需要安装。

@527395632
Copy link

    public static void RegisterOpenEvent(this RegistryKey source, string scheme, string appPath)
    {
        var index = scheme.IndexOf(":");
        if (index == 0) throw new ArgumentException("无效的'scheme'", "scheme");
        var key = index < 0 ? scheme : scheme.Substring(0, index);
        var rootPath = source.CreateSubKey(key);
        rootPath.SetValue(string.Empty, $"{ key }Protocol");
        rootPath.SetValue("URL Protocol", appPath);
        rootPath.CreateSubKey("DefaultIcon").SetValue(string.Empty, $"{ appPath },1");
        var command = rootPath.CreateSubKey("shell").CreateSubKey("open").CreateSubKey("command");
        command.SetValue(string.Empty, $"{ appPath } %1");
    }

    public static void UnRegisterOpenEvent(this RegistryKey source, string scheme)
    {
        var index = scheme.IndexOf(":");
        if (index == 0) throw new ArgumentException("无效的'scheme'", "scheme");
        var key = index < 0 ? scheme : scheme.Substring(0, index);
        source.DeleteSubKeyTree(key, false);
    }

@andywu188
Copy link
Author

andywu188 commented Jun 14, 2022

大哥,你没理解问题含义呢,你的代码是“在注册表中注册URL Protocol协议”,而我说的问题是,如何在NanUI中,点击链接,并自动调用。这是两个问题,注册,根本不需要我自己写代码注册,因为一般客户端安装程序,本来就会自动注册,哪需要我自己注册呢?你注意看我上面说的一段话:“只要是系统中已安装的软件并支持web client app Protocol的软件,都能在NanUI调用”,问题是如何在NanUI调用

@527395632
Copy link

自定义的URL Protocol需要在注册表中注册, 这个是肯定的。至于这个工作是由哪里来做, 这个可以视情况而定。既然NanUI没有实现, 那么我们自己实现下也可以, 或者在制作安装包的时候把这块注册表添加上也可以。调用可以直接用a标签的href写, 如href="abc://123"

@andywu188
Copy link
Author

andywu188 commented Jun 14, 2022

还是没说到重点啊,HTML链接代码<a href="search://">打开APP</a>,不用说,谁都会写的,问题是,点击后,NanUI如何处理这个事件,如何调用URL协议

@XuanchenLin
Copy link
Owner

CEF 的模型中在很多个环节上都提供了 CefRequest 对象,例如 BeforeBrowse 事件、GetResourceRequestHandler事件等等,那么捕获到浏览器的 Request,其中包括了请求的 URL 也就包含了目标的 Scheme,根据目标 Scheme 那么就可以开发相应的功能逻辑,要么交给系统(正如楼主的需求一样),要么自行处理。

@XuanchenLin
Copy link
Owner

image

写了段代码说明一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants