"use strict"; cc._RF.push(module, '06f09jToBBHzpwA4PntvL/K', 'cmp.launch.update'); // Scripts/mod/login/update/cmp.launch.update.js "use strict"; /****************************************************************** * * 版本更新 * ******************************************************************/ var WndLogin = require("scene.login"); cc.Class({ "extends": cc.Component, properties: { wndLogin: { "default": null, type: WndLogin }, progBar: { "default": null, type: cc.ProgressBar }, labTip: { "default": null, type: cc.Label }, labPercent: { "default": null, type: cc.Label }, manifestUrl: { "default": null, type: cc.Asset } }, // 开始检查 doCheck: function doCheck() { var _this = this; // UI nx.gui.setActive(this.progBar, "", false); this.labTip.string = nx.text.getKey("UpdateChecking"); this.labPercent.string = ""; // 实例化更新模块 if (!nx.bridge.updater) { nx.factory.createService("update.mod"); } // 检查更新 nx.bridge.updater.bindManifest(this.manifestUrl); nx.bridge.updater.checkUpdate(function (_ret, _data, _code) { // 失败 if (!_ret) { var msg = nx.text.format(_data, _code); nx.mbox(msg, ['quit', 'retry'], function (_key, _box) { _box.close(); if (_key == 'quit') { nx.appQuit(); } else { nx.restart(); } }, "UpdateCheck"); return; } // 需要更新 if (nx.dt.numPositive(_data, false)) { // 判断当前网络类型 var nt = cc.sys.getNetworkType(); if (nt != cc.sys.NetworkType.WWAN) { _this.doUpdate(); return; } // 流量提示 var size = nx.dt.formatBytes(_data); var txt = nx.text.format("UpdateAsk", size); nx.mbox(txt, ['no', 'yes'], function (_key, _box) { _box.close(); if (_key == 'no') { nx.appQuit(); return; } // 开始更新 _this.doUpdate(); }, "UpdateCheck"); return; } // 不需要更新 _this.wndLogin.changeSubPanel(1); }); }, // 开始更新 doUpdate: function doUpdate() { var _this2 = this; // UI nx.gui.setActive(this.progBar, "", true); this.labTip.string = nx.text.getKey("UpdateTip"); this.progBar.progress = 0; this.labPercent.string = ""; // 更新 nx.bridge.updater.doUpdate(function (_ret, _data, _code) { // 失败 if (!_ret) { var msg = nx.text.format(_data, _code); nx.mbox(msg, ['quit', 'retry'], function (_key, _box) { _box.close(); if (_key == 'quit') { nx.appQuit(); } else { nx.restart(); } }, "HotUpdate"); return; } // 进度更新 if (_data && _data.size) { var cur = nx.dt.formatBytes(_data.size.cur); var tol = nx.dt.formatBytes(_data.size.total); _this2.labPercent.string = cur + '/' + tol; _this2.progBar.progress = _data.size.percent; } }); } }); cc._RF.pop();