Example #1
0
            public override WebResourceResponse ShouldInterceptRequest(WebView p0, string url)
            {
                if (url.Contains("/static/"))
                {
                    var filePath      = url.Substring(url.LastIndexOf("/static/"), (url.Length - url.LastIndexOf("/static/")));
                    var extensionName = filePath.Substring(filePath.LastIndexOf(".") + 1, (filePath.Length - filePath.LastIndexOf(".") - 1));
                    if (!File.Exists(DeviceInfo.HtmlFolder + filePath))
                    {
                        Task.Run(() =>
                        {
                            new HtmlFileManage().DownloadFile(HybridCommon.Config.HtmlServerHost + filePath, DeviceInfo.HtmlFolder + filePath);
                        });
                    }
                    else
                    {
                        var fileStream = File.OpenRead(DeviceInfo.HtmlFolder + filePath);
                        var result     = new WebResourceResponse();
                        result.Encoding = "UTF-8";
                        result.MimeType = MimeHelper.GetMime(extensionName);
                        result.Data     = fileStream;
                        return(result);
                    }
                }
                else if (url.Contains("/index.html#/Empty/"))
                {
                    var filePath = "/index.html";
                    if (!File.Exists(DeviceInfo.HtmlFolder + filePath))
                    {
                        Task.Run(() =>
                        {
                            new HtmlFileManage().DownloadFile(HybridCommon.Config.HtmlServerHost + filePath,
                                                              DeviceInfo.HtmlFolder + filePath);
                        });
                    }
                    else
                    {
                        var fileStream = File.OpenRead(DeviceInfo.HtmlFolder + filePath);
                        var result     = new WebResourceResponse();
                        result.Encoding = "UTF-8";
                        result.MimeType = MimeHelper.GetMime("html");
                        result.Data     = fileStream;
                        return(result);
                    }
                }

                //if (url.Contains(DeviceInfo.HtmlFolder))
                //{

                //    url = url.Replace(DeviceInfo.HtmlFolder, "@");
                //    url = url.Substring(url.IndexOf("@")+1, url.Length - url.IndexOf("@")-1);
                //    url = HybridCommon.Config.HtmlServerHost + url;
                //}

                return(base.ShouldInterceptRequest(p0, url));
            }
Example #2
0
 public override void OnReceivedHttpError(WebView p0, IWebResourceRequest p1, WebResourceResponse p2)
 {
     base.OnReceivedHttpError(p0, p1, p2);
 }