From 2282ce88813a8e77c0252f9654bbacc700ad899d Mon Sep 17 00:00:00 2001 From: andrewlu Date: Tue, 2 Feb 2021 11:26:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=83=AD=E6=9B=B4=E6=8F=92?= =?UTF-8?q?=E4=BB=B6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Bundle2/UI2.prefab | 4 +-- assets/Scene/main.fire | 6 ++-- packages/update-manager/.settings.conf | 9 ++--- packages/update-manager/js/FileUploader.js | 40 +++++++++++++++++++--- packages/update-manager/main.js | 21 ++++++++++-- packages/update-manager/panel/index.html | 31 +++++++++-------- 6 files changed, 81 insertions(+), 30 deletions(-) diff --git a/assets/Bundle2/UI2.prefab b/assets/Bundle2/UI2.prefab index 11a1104..46a1bc9 100644 --- a/assets/Bundle2/UI2.prefab +++ b/assets/Bundle2/UI2.prefab @@ -156,8 +156,8 @@ ], "_srcBlendFactor": 770, "_dstBlendFactor": 771, - "_string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V3", - "_N$string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V3", + "_string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V4", + "_N$string": "这是Bundle2,修改此bundle 并上传更新包,然后运行查看效果.\n当前版本V4", "_fontSize": 60, "_lineHeight": 60, "_enableWrapText": true, diff --git a/assets/Scene/main.fire b/assets/Scene/main.fire index 350aa23..c616b5c 100644 --- a/assets/Scene/main.fire +++ b/assets/Scene/main.fire @@ -180,7 +180,7 @@ "array": [ 0, 0, - 533.7828766106993, + 535.5690540060046, 0, 0, 0, @@ -795,8 +795,8 @@ ], "_srcBlendFactor": 770, "_dstBlendFactor": 771, - "_string": "当前为新版本:V3", - "_N$string": "当前为新版本:V3", + "_string": "当前为新版本:V4", + "_N$string": "当前为新版本:V4", "_fontSize": 40, "_lineHeight": 40, "_enableWrapText": true, diff --git a/packages/update-manager/.settings.conf b/packages/update-manager/.settings.conf index 63cc01b..a334e99 100644 --- a/packages/update-manager/.settings.conf +++ b/packages/update-manager/.settings.conf @@ -1,9 +1,9 @@ { "versionCfg": { - "versionCode": "3", - "versionName": "1.0.2", + "versionCode": "4", + "versionName": "1.0.3", "versionType": "dev", - "versionLog": "adfadsfdsfdsfsdf", + "versionLog": "测试V4发布版本", "baseUrl": "https://cdn-awdxc.8zy.com/" }, "ftpCfg": { @@ -12,6 +12,7 @@ "user": "cos1", "password": "dkJrWrVy11", "rootPath": "temp001/", - "keepalive": 100000 + "keepalive": 100000, + "maxThread": "10" } } \ No newline at end of file diff --git a/packages/update-manager/js/FileUploader.js b/packages/update-manager/js/FileUploader.js index 27d1b8e..b9ce1cd 100644 --- a/packages/update-manager/js/FileUploader.js +++ b/packages/update-manager/js/FileUploader.js @@ -8,12 +8,23 @@ class FileUploader { maxClients = 3; options = {}; queue = []; + idleCallback = null; + loopId = 0; + lastIdleState = true; + + constructor() { + this.loopId = setInterval(this.loop.bind(this), 200); + } setOption(options, maxThread) { this.options = options; this.maxClients = maxThread || 1; } + setStateListener(callback) { + this.idleCallback = callback; + } + prepare() { const currLen = Object.keys(this.ftps).length; logger.info('准备创建上传线程:', this.maxClients, currLen); @@ -30,6 +41,28 @@ class FileUploader { this.ftps[id].destroy(); delete this.ftps[id]; } + if (this.loopId) { + clearInterval(this.loopId) + this.loopId = 0; + } + } + + // event loop. + loop() { + const curState = this.checkState(); + if (curState != this.lastIdleState) { + this.lastIdleState = curState; + this.idleCallback && this.idleCallback(curState); + } + } + + checkState() { + let idleState = true; + for (let i in this.ftps) { + idleState = idleState && this.ftps[i].idleState; + if (!idleState) break; + } + return idleState; } /** @@ -71,6 +104,7 @@ class UploadThread { ready = false; stopped = false; options = null; + idleState = true; constructor(options) { this.options = options; @@ -89,19 +123,15 @@ class UploadThread { this.ready = false; const ftp = new Client(); ftp.on('ready', () => { - logger.log('ftp ready'); this.ready = true; }); ftp.on('close', () => { - logger.log('ftp client has close'); this.ready = false; }); ftp.on('end', () => { - logger.log('ftp client has end'); this.ready = false; }); ftp.on('error', (err) => { - logger.log('ftp client has an error : ', JSON.stringify(err)); this.ready = false; }); ftp.connect(this.options); @@ -123,8 +153,10 @@ class UploadThread { while (!this.stopped) { if (!this.ready || this.queue.length <= 0) { await this.sleep(500); + this.idleState = true; continue; } + this.idleState = false; const once = this.queue[0]; const err = await this.uploadOnce(this.ftp, once); if (!err) { diff --git a/packages/update-manager/main.js b/packages/update-manager/main.js index 58e909f..bf7b3e6 100644 --- a/packages/update-manager/main.js +++ b/packages/update-manager/main.js @@ -63,10 +63,25 @@ module.exports = { fs.writeFileSync( Editor.url('packages://update-manager/.settings.conf'), JSON.stringify({}, null, 2), 'utf-8'); } + if (!this.ftp) { + this.ftp = FileUpload(); + } + this.ftp.setStateListener(this.onUploadStateChange.bind(this)); + }, + + onUploadStateChange(state) { + if (!state) { + Editor.info('开始上传更新包'); + } else { + Editor.success('所有文件上传完成!'); + } }, unload() { Editor.Builder.removeListener('build-finished', doMakeUpdatePackage); + if (this.ftp) { + this.ftp.destroy(); + } }, messages: { 'open'() { @@ -74,12 +89,12 @@ module.exports = { }, 'upload'(event, dir, dst, options) { logger.info('upload....'); - if (!this.ftp) { - this.ftp = FileUpload(); - } this.ftp.setOption(options, options.maxThread); this.ftp.upload(dir, dst); }, + 'getProjectPath'(event) { + event.reply(Editor.Project.path); + }, 'uploadStop'() { if (this.ftp) { this.ftp.destroy(); diff --git a/packages/update-manager/panel/index.html b/packages/update-manager/panel/index.html index bb179b4..895f5d9 100644 --- a/packages/update-manager/panel/index.html +++ b/packages/update-manager/panel/index.html @@ -56,11 +56,11 @@ - + - - - + - + @@ -68,16 +68,16 @@ - + - - + - - + @@ -85,7 +85,7 @@ - + @@ -114,7 +114,8 @@ + description="开始构建版本,构建完成后会在构建目录中生成remote文件夹以及update-dev.json更新描述文件 + 注:不需要设置Bundle为远程包,插件将自动调整远程包设置"> @@ -142,6 +143,7 @@ \ No newline at end of file