hubilder热更新

复制代码
  <script type="text/javascript">
    
        function plusReady(){
            plus.key.addEventListener('backbutton',function(){
                if(confirm('确认退出?')){
                    plus.runtime.quit();
                }
            },false);
            
            var checkUrl="http://xxxxxx/version.txt";
            plus.runtime.getProperty(plus.runtime.appid,function(inf){
                var wgtVer = inf.version;
                console.log("当前应用版本:"+wgtVer); 
                var xhr=new XMLHttpRequest();
                xhr.onreadystatechange=function(){
                    switch(xhr.readyState){
                        case 4:
                            plus.nativeUI.closeWaiting();
                            if(xhr.status==200){
                                var newVer=xhr.responseText;
                                console.log("检测更新成功:"+newVer);
                                if(newVer.toString().substr(0,5) == wgtVer.toString().substr(0,5)){
                                    console.log("无新版本可更新!")
//                                    plus.nativeUI.alert("无新版本可更新!");
                                }else{
                                    downWgt();    // 下载升级包
                                    console.log("正在更新")
                                }
                            }else{
                                console.log("检测更新失败!");
                                plus.nativeUI.alert("检测更新失败!");
                            }
                        break;
                        default:  
                        break; 
                    }
                }
                xhr.open('GET',checkUrl);
                xhr.send();
            });
            
        }
        
        if(window.plus){
            plusReady();
        }else{
            document.addEventListener('plusready',plusReady,false);
        }
        
        // 下载wgt文件
        var wgtUrl="http://xxxxxx/update.wgt";
        function downWgt(){
            plus.nativeUI.showWaiting("下载wgt文件...");
            plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
                if ( status == 200 ) { 
                    console.log("下载wgt成功:"+d.filename);
                    installWgt(d.filename);    // 安装wgt包
                } else {
                    console.log("下载wgt失败!");
                    plus.nativeUI.alert("下载wgt失败!"); 
                }
                plus.nativeUI.closeWaiting();
            }).start();
        }
        // 更新应用资源
        function installWgt(path){
            plus.nativeUI.showWaiting("安装wgt文件...");
            plus.runtime.install(path,{},function(){
                plus.nativeUI.closeWaiting();
                console.log("安装wgt文件成功!");
                plus.nativeUI.alert("应用资源更新完成!",function(){
                    plus.runtime.restart();
                });
            },function(e){
                plus.nativeUI.closeWaiting();
                console.log("安装wgt文件失败["+e.code+"]:"+e.message);
                plus.nativeUI.alert("安装wgt文件失败["+e.code+"]:"+e.message);
            });
        }

    </script>
复制代码

 

posted @   realwds  阅读(188)  评论(0编辑  收藏  举报
编辑推荐:
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
阅读排行:
· dotnet 源代码生成器分析器入门
· 官方的 MCP C# SDK:csharp-sdk
· 一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
· 一步一步教你部署ktransformers,大内存单显卡用上Deepseek-R1
· 一次Java后端服务间歇性响应慢的问题排查记录
点击右上角即可分享
微信分享提示