diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..51c63e295e0232f7095a8ee8e03713837e37f419 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +*.tgz filter=lfs diff=lfs merge=lfs -text +*.trp filter=lfs diff=lfs merge=lfs -text +*.apk filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.mp4 filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.asm filter=lfs diff=lfs merge=lfs -text +*.8svn filter=lfs diff=lfs merge=lfs -text +*.9svn filter=lfs diff=lfs merge=lfs -text +*.dylib filter=lfs diff=lfs merge=lfs -text +*.exe filter=lfs diff=lfs merge=lfs -text +*.a filter=lfs diff=lfs merge=lfs -text +*.so filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.dll filter=lfs diff=lfs merge=lfs -text diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..4947287f7b5ccb5d1e8b7b2d3aa5d89f322c160d --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index c150a37f968b1c4bd17ca0f69b48e69a75cc2cdb..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# update_app - -#### Description -Update client | 升级客户端组件 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md old mode 100644 new mode 100755 index e5cb51b8e0eb99cb569c454478e4deae50274df3..23553f0170874ccc3f84a6b130f5fdf7c6fff897 --- a/README.md +++ b/README.md @@ -1,37 +1,47 @@ -# update_app +# Update App -#### 介绍 -Update client | 升级客户端组件 +- [Introduction](#section182mcpsimp) +- [Directory Structure](#section190mcpsimp) +- [Description](#section198mcpsimp) +- [Repositories Involved](#section206mcpsimp) -#### 软件架构 -软件架构说明 +## Introduction +The update app runs on the OHOS and provides an interactive GUI for users to perform version updates. -#### 安装教程 +It provides the following functions: -1. xxxx -2. xxxx -3. xxxx +1. Check for available update packages and display the check result. -#### 使用说明 +2. Download the update package and display the download progress. -1. xxxx -2. xxxx -3. xxxx +3. Trigger an update. -#### 参与贡献 +4. Obtain the version information after a version update. -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +## Directory Structure +``` +base/update/app # Update app code repository +├── entry # Access to the update app code +│ └── src # Update app code +└── gradle # Configuration files + └── wrapper # Gradle configuration files +``` -#### 特技 +## Description + +The update app is implemented by using JavaScript, and the service logic is implemented by using C++. The JavaScript app interacts with the service logic through NAPI. + +For details about the NAPI implementation, see the following: + +base/update/updateservice/client + +## Repositories Involved + +Update subsystem + +**update\_app** + +update\_updateservice -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README_zh.md b/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..56f9d3df199158906ee9ec8c7fb28330d24bfdcd --- /dev/null +++ b/README_zh.md @@ -0,0 +1,47 @@ +# 升级客户端应用 + +- [简介](#section182mcpsimp) +- [目录](#section190mcpsimp) +- [说明](#section198mcpsimp) +- [相关仓](#section206mcpsimp) + +## 简介 + +升级客户端应用运行于OHOS 上,提供与用户进行交互的界面,并进行升级操作。 + +主要功能包括: + +1、触发升级服务组件检查可用的升级包,显示升级包检查的结果 + +2、下载升级包,显示下载的进度和状态 + +3、触发升级 + +4、升级完成后,显示升级后版本信息 + +## 目录 + +``` +base/update/app # 升级客户端应用代码仓目录 +├── entry # 升级客户端应用代码目录 +│ └── src # 升级客户端源码目录 +└── gradle # 配置文件目录目录 + └── wrapper # gradle配置文件目录目录 +``` + +## 说明 + +升级客户端应用由JavaScript实现,业务逻辑由C++实现,JS应用与业务逻辑通过NAPI进行交互。 + +NAPI的实现,请参考 + +base/update/updateservice/client + +## 相关仓 + +升级子系统 + +**update\_app** + +update\_updateservice + diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..f5878c2c5316795f026a468669a3526af1e2ee40 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "com.runhe.ota.updateclient", + "vendor": "runhe", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4, + "releaseType": "Beta2" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.runhe.ota.updateclient", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home", + "flag.hw.home.intent.from.system" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.runhe.ota.updateclient.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "updateclient", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/js/default/app.js b/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..46045e2fcc35501680410adfbf00a7403482ab01 --- /dev/null +++ b/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info("Application onCreate"); + + }, + onDestroy() { + console.info("Application onDestroy"); + } +}; diff --git a/entry/src/main/js/default/common/background.png b/entry/src/main/js/default/common/background.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f880e4020704408af6861dc4b8e105cf0332d0 Binary files /dev/null and b/entry/src/main/js/default/common/background.png differ diff --git a/entry/src/main/js/default/common/load.png b/entry/src/main/js/default/common/load.png new file mode 100644 index 0000000000000000000000000000000000000000..5121c177a42946ddd6f6487ca758829b4dc67706 Binary files /dev/null and b/entry/src/main/js/default/common/load.png differ diff --git a/entry/src/main/js/default/pages/index/index.css b/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..107e1ae85a57ed1380c07906ae2c319404380354 --- /dev/null +++ b/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.container { + background-color: white; + flex-direction: column; + background-image: url("/common/background.png"); + background-size: 100% 85%; + background-repeat: no-repeat; + background-position: 0 100%; + font-family: HYQiHei-65S; +} +.percent{ + text-align: right; + font-weight: bolder; + position: absolute; + padding-left: 88%; + padding-top: 6%; +} + + +.sign{ + color: black; + padding-left: 20px; + font-size: 80px; +} + +.left{ + color: black; + font-size: 40px; + position: relative; +} + +.banner1{ + width: 88%; + height:9px; + background-color: #E6E6E6; + +} +.banner2{ + width: 0%; + height: 9px; + background-color: #0A9AFD; + position: relative; +} + +.loadImg { + margin-top: 330px; + width: 100px; + height: 100px; + margin-left: 300px; + object-fit:scale-down; + align-items: center; + justify-content: center; + animation-name: one2; + animation-duration: 2s; + animation-iteration-count: infinite; + animation-timing-function: linear; + margin-bottom: 50px; +} +@keyframes one2{ + from{ + transform: rotate(0deg) ; + } + to{ + transform: rotate(360deg); + } +} + +.title{ + color: black; + padding-top: 350px; + font-size: 60px; + text-align: center; + width: 100%; + padding-bottom: 30px; +/* text-color: black;*/ +} + +.title1{ + color: black; + padding-left: 95px; + font-size: 45px; +} + +.title1_1{ + padding-top: 200px; +} + +.allbutton { + width: 400px; + height: 80px; + margin-left: 160px; + margin-top: 30px; + border-radius: 50px; + background-color: #0A9AFD; +} + +.button3{ + width: 400px; + height: 80px; + text-align: center; + font-size: 50px; + color: white; +} + +.allbutton1 { + width: 240px; + height: 70px; + margin-left: 125px; + margin-top: 30px; + border-radius: 50px; + background-color: #0A9AFD; +} + +.button1{ + width: 240px; + height: 70px; + text-align: center; + font-size: 36px; + text-color: white; +} + +.allbutton2 { + width: 240px; + height: 70px; + font-size: 23px; + text-align: center; + margin-left: 40px; + margin-top: 30px; + border-radius: 50px; + background-color: #0A9AFD; + text-color: white; +} + +.button2{ + width: 240px; + height: 70px; + text-align: center; + font-size: 36px; +} + + diff --git a/entry/src/main/js/default/pages/index/index.hml b/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..d0d064d38ab4cfcf5b52ca169ccee183939bf064 --- /dev/null +++ b/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,76 @@ + +
+
+ + < + + + 升级客户端 + +
+
+
+
+
+ + {{width}} + + + 当前版本:{{versionName}} + + + {{title}} + + + {{title}} + + + {{upgradeInfo}} + + + + 版本号:{{versionName}} + + + 包大小:{{size}} + + + 更新日志:{{journal}} + + + 注意事项: {{matter}} + + + + +
+ + {{button}} + +
+
+
+ + 安装 + +
+
+ + 稍后安装 + +
+
+
\ No newline at end of file diff --git a/entry/src/main/js/default/pages/index/index.js b/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..0a3e4011dd02a856277ca74a9dae3d2e5b380d87 --- /dev/null +++ b/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import prompt from '@system.prompt' +import app from '@system.app'; +import client from '@ohos.update'; + +const page= { + data: { + title: "当前版本:10.2.1", + button: "查看更新", + pageType: "currVersion", + versionName: "10.2.0", + size: "20MB", + journal: "本次更新解决了一些BUG。", + matter: "请保持50%以上电量", + showLoad: "", + width: "5%", + showBanner: "", + showButton: "download", + upgradeInfo: "", + updater: undefined, + timer: undefined + }, + onInit() { + console.info("onInit "); + try { + page.data.updater = client.getUpdater('/data/updater/updater.zip', 'OTA'); + page.getCurrVersion(); + } catch(error) { + console.error(" Fail to get updater error: " + error); + } + console.info(`onInit finish `); + }, + + onClick: function() { + console.info("onClick " + this.pageType); + page.processClick(); + }, + + processClick() { + console.info("processClick " + page.data.pageType); + if (page.data.pageType == "currVersion") { // 检查更新版本 + console.info("start to check new version "); + page.data.pageType = "checkVersion"; + page.data.button = "取消查看"; + page.data.showLoad = "load"; + page.checkNewVersion(); + } else if (page.data.pageType == "newVersion") { // 当前需要下载最新的版本 + page.data.pageType = "downVersion"; + page.data.showLoad = "load"; + page.data.showBanner = 'banner'; + page.data.button = "取消下载"; + page.download(); + } else if ( this.pageType == "lastVersion") { // 已经是最新的版本了,单击后退出页面 + page.data.showLoad = ""; + app.terminate(); + } else if (page.data.pageType == "checkVersion") { // 检查中,取消检查 + page.data.showInfoDialog("是否要取消检查,取消会退出升级", (index)=>{ + page.data.pageType = "checkVersion"; + if (index == 1) { + app.terminate(); + } + }); + } else if (page.data.pageType == "downVersion") { // 下载中,取消下载 + this.showInfoDialog("是否要取消下载,取消则退出升级", (index)=>{ + page.data.pageType = "downVersion"; + if (index == 1) { + page.data.updater.Cancel(); + page.data.pageType="currVersion"; + page.data.showButton="download"; + } + }); + } else if (page.data.pageType == "errorPage") { // 出错,退出 + app.terminate(); + } + }, + + clickInstall: function() { + console.info("clickInstall " + page.data.pageType); + if (page.data.pageType == "downSuccess") { // 下载成功,开始升级 + console.info(`upgrade starting`); + page.upgrade(); + } + }, + + clickCancel: function() { + console.info("clickCancel " + page.data.pageType); + if (page.data.pageType == "downSuccess") { // 下载成功,取消升级 + page.showInfoDialog("确认是否取消升级", (index)=>{ + if (index == 1) { + app.terminate(); + } + }); + } + }, + + getCurrVersion() { + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "初始化出现错误,退出app"; + + if (page.data.updater == undefined) { + console.error("Can not import client"); + return; + } + console.info("getCurrVersion begin " + page.data.updater); + try { + // 获取版本信息 + page.data.updater.getNewVersionInfo(function(err, info) { + console.log("getNewVersionInfo success " + info.status); + console.log(`info versionName = ` + info.checkResults[0].versionName); + console.log(`info versionCode = ` + info.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + info.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + info.checkResults[0].descriptionId); + console.log(`info size = ` + info.checkResults[0].size); + if (info.status == 1) { // 已经最新 + page.data.title = "当前已经是最新版本"; + page.data.button = "确定"; + page.data.pageType = "lastVersion"; + page.data.versionName = info.checkResults[0].versionName; + } else if (info.status == 0) { + page.data.button = "查看更新"; + page.data.pageType = "currVersion"; + page.data.versionName = info.checkResults[0].versionName; + } else { + console.error(" getNewVersionInfo errMsg " + info.errMsg); + page.data.title = "获取新版本失败"; + } + }); + } catch(error) { + console.error(" getNewVersionInfo catch " + error); + page.data.title = "获取新版本失败"; + } + }, + + checkNewVersion: function() { + if (page.data.updater == undefined) { + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "初始化出现错误,退出app"; + return; + } + console.log('checkNewVersion begin '); + page.data.updater.checkNewVersion(function(err, info) { + page.data.showLoad = ""; + console.error('checkNewVersion info ' + info.status); + if (info.status == 1) { // 已经最新 + page.data.title = "当前已经是最新版本"; + page.data.button = "确定"; + page.data.pageType = "lastVersion"; + } else if (info.status == 0) { // 有新版本 + console.log(`info versionName = ` + info.checkResults[0].versionName); + console.log(`info versionCode = ` + info.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + info.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + info.checkResults[0].descriptionId); + console.log(`info content = ` + info.descriptionInfo[0].content); + console.log(`info size = ` + info.checkResults[0].size); + let size = info.checkResults[0].size / 1024 / 1024; + page.data.versionName = info.checkResults[0].versionName; + page.data.size = String(size.toFixed(2)) + "MB"; + if (info.descriptionInfo[0].content != undefined) { + page.data.journal = info.descriptionInfo[0].content; + }; + page.data.pageType = "newVersion"; + page.data.button = "下载更新包"; + } else { // 出错 + console.error(`CheckNewVersion errMsg = ` + info.errMsg); + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "检查新版本失败"; + if (info.errMsg) { + page.data.title = "检查新版本失败,失败原因:" + info.errMsg; + } + } + }); + }, + + download() { + if (page.data.updater == undefined) { + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "初始化出现错误,退出app"; + return; + } + page.data.updater.on("downloadProgress", progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + console.log(`downloadProgress pageType: ` + page.data.pageType); + if (page.data.pageType != "downVersion") { + return; + } + let percent = progress.percent; + if (progress.percent > 5) { + percent = progress.percent - 5; + } + page.data.width = percent + '%'; + if (progress.percent == 100) { + page.data.showLoad = ""; + page.data.showBanner = ''; + } + // 下载成功 UpdateState.UPDATE_STATE_DOWNLOAD_SUCCESS + if (progress.status == 24 || progress.status == 32) { + page.data.pageType = "downSuccess"; + page.data.showButton = "upgrade"; + page.data.upgradeInfo = page.data.versionName + "安装包下载完成,是否安装?"; + page.data.updater.off("downloadProgress"); + } else if (progress.status == 23 || progress.status == 31) { // 失败 + console.log("downloadProgress error" + progress.endReason); + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "下载失败"; + if (progress.endReason) { + page.data.title = "下载失败,失败原因:" + progress.endReason; + } + page.data.updater.off("downloadProgress"); + } + }); + page.data.updater.download(); + }, + + upgrade() { + if ( page.data.updater == undefined) { + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "初始化出现错误,退出app"; + return; + } + page.data.updater.on("upgradeProgress", progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + page.data.width = progress.percent + '%'; + if (progress.status == 3) { // 失败 + page.data.updater.off("upgradeProgress"); + page.data.showLoad = ""; + page.data.pageType = "errorPage"; + page.data.showButton = 'download'; + page.data.button = '退出'; + page.data.title = "升级失败,失败原因:" + progress.endReason ; + } + }); + page.data.updater.upgrade(); + }, + + showInfoDialog(info, func) { + console.error("showInfoDialog " + info); + prompt.showDialog({ + title:"提示", + message:info, + buttons:[{"text":"继续","color":" #1491FE"}, {"text":"取消","color":" #1491FE"}], + success: function(data) { + console.error('showDialog. index' + data.index); + func(data.index); + }, + cancel: function(data, code) { + console.error('showDialog cancel'); + }, + complete: function(data, code) { + console.error('showDialog complete'); + }, + }) + }, +} + +export default page; diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ