Code Hot Update
Official Hot Update Service
What Is Hot Update
- Hot update updates critical code without reinstalling the app
- EC hot update mainly updates packaged automation test scripts
- Note: keep
update.jsonversion in sync with the server response version, or abnormal behavior may occur
How EC Hot Update Works
- Open
update.jsonin the project:
EC Loads New Package
Client Request
- After configuration, packaged app auto-sends GET to
update_urlwith parameters; e.g.http://baidu.com/update?version=100— server can compare versions; client also compares locally
Server Response
- Server response format:
- Normal update
- Hot update applies to compiled
.iecfiles - If no update needed, return empty string — not JSON
{ "download_url": "http://baidu.com/aaa.iec", "version": "101", "download_timeout": 120, "dialog": true, "msg": "优化部分问题", "force": false}- Strict mode with MD5 check to prevent failed updates
{ "download_url": "http://baidu.com/aaa.iec", "version": "101", "download_timeout": 120, "dialog": true, "msg": "优化部分问题", "force": false, "md5": "服务器自行校验的iec文件的md5值"}download_url: new package download URLdownload_timeout: IEC download timeoutversion: new package versionmd5: IEC file MD5 — if present, file integrity is strictly verified- EC downloads and loads the latest IEC package from this JSON
dialog: show dialog —true= dialog,false= no dialogmsg: message shown in dialogforce: in dialog mode, force update —true= cannot cancel,false= optional
UI Startup Update
- With correct configuration, the UI auto-updates on open
In-Script Hot Update
- Hot update during script execution requires code
hotupdater.updateReq — Request Update
- Request hot update endpoint.
falsemay also mean no update needed — usegetErrorMsgfor details - Version: EC standalone 3.19.0+
- @param updateUrl Update URL — omit to use update.json config
- @param version Current version as integer, e.g. 1
- @param appendDeviceInfo Append device info — true or false
- @param timeout Request timeout in milliseconds
- @return
{bool}true = update available, false = no update
function main() { // Get version from project update.json let version = JSON.parse(readIECFileAsString("update.json")).version // Or set version manually // let version = 7; // Request server for new version // Using update.json mode //let updateResult = hotupdater.updateReq("",version,true,9000); // Custom URL mode let updateResult = hotupdater.updateReq("http://baidu.com", version, true, 9000); logd("Update available: " + updateResult); if (!updateResult) { logw("Request failed: " + hotupdater.getErrorMsg()); } else { logd("Response data: " + hotupdater.getUpdateResp()); // Download new version if update available let path = hotupdater.updateDownload(); logd("Download path: " + path); if (!path) { logw("IEC download error: " + hotupdater.getErrorMsg()); } else { restartScript(path, true, 3) return; } } sleep(1000); for (var i = 0; i < 10; i++) { logd(time() + " " + version); sleep(5000) }}
main();hotupdater.updateDownload — Download IEC
- Download IEC file from hot update request
- Version: EC standalone 3.19.0+
- @return
{string}path to downloaded hot update file; empty may mean no update - See example
hotupdater.getUpdateResp — Get Request Result
- Get hot update request result
- Version: EC standalone 3.19.0+
- @return
{string}string - See example
hotupdater.getErrorMsg — Get Error Message
- Get hot update error message
- Version: EC standalone 3.19.0+
- @return
{string}string - See example