From 0a09616484641289b36882bfb2819eed263dab16 Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Mon, 13 Jan 2025 17:18:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E6=9A=82=E5=81=9C?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=EF=BC=8C=E7=8A=B6=E6=80=81=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- ohos/src/main/ets/components/FlutterDownloaderPlugin.ets | 6 +++++- ohos/src/main/ets/components/TaskDao.ets | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets b/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets index 19f0c70..93be1c3 100644 --- a/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets +++ b/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets @@ -430,6 +430,7 @@ export class FlutterDownloaderPlugin implements FlutterPlugin, MethodCallHandler private callback(taskId: string, filename: string, status: DownloadStatus, progress: request.agent.Progress, isResume?: number): void { const task = this.taskDao!.loadTask(taskId); + const syncTask = this.taskDao!.getSyncData(taskId); if (task != null) { let lastProgress = 0; if (status == DownloadStatus.COMPLETE) { @@ -438,7 +439,10 @@ export class FlutterDownloaderPlugin implements FlutterPlugin, MethodCallHandler lastProgress = -1; } else { lastProgress = Math.trunc(progress.processed * 100 / progress.sizes[0]); - + // 状态是异步获取的,不存在由PAUSED状态直接变为RUNNING状态的情况,只能是PAUSED-->Resume-->RUNNING + if (status === DownloadStatus.RUNNING && syncTask && syncTask[TaskEntry.COLUMN_NAME_STATUS] === DownloadStatus.PAUSED && isResume !== 0) { + status = DownloadStatus.PAUSED; + } const args: Map = new Map(); args["task_id"] = taskId args["status"] = status diff --git a/ohos/src/main/ets/components/TaskDao.ets b/ohos/src/main/ets/components/TaskDao.ets index 3696d6c..839caf6 100644 --- a/ohos/src/main/ets/components/TaskDao.ets +++ b/ohos/src/main/ets/components/TaskDao.ets @@ -42,6 +42,7 @@ export class TaskDao { TaskEntry.COLUMN_NAME_TIME_CREATED, TaskEntry.COLUMN_ALLOW_CELLULAR, ]; + private syncData: Map = new Map(); constructor(dbHelper: TaskDbHelper) { this.dbHelper = dbHelper; // 将 dbHelper 作为实例变量保存 @@ -134,6 +135,10 @@ export class TaskDao { return result; } + getSyncData(taskId: string) { + return this.syncData.get(taskId); + } + loadTask(taskId: string): DownloadTask | null { let db = this.dbHelper!.getRdbStore(); let result: DownloadTask | null = null; @@ -158,6 +163,7 @@ export class TaskDao { } async updateTask(taskId: string, values: ValuesBucket): Promise { + this.syncData.set(taskId, values); let db = this.dbHelper!.getRdbStore(); if (db == null) { return; @@ -178,6 +184,7 @@ export class TaskDao { } async deleteTask(taskId: string): Promise { + this.syncData.delete(taskId); let db = this.dbHelper!.getRdbStore(); if (db == null) { return; -- Gitee From d2318e961839161e4e182c32e8d5582c2f3a490a Mon Sep 17 00:00:00 2001 From: asklie <760956257@qq.com> Date: Tue, 14 Jan 2025 20:19:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A2=BC?= =?UTF-8?q?=E8=A6=8F=E7=AF=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: asklie <760956257@qq.com> --- ohos/src/main/ets/components/FlutterDownloaderPlugin.ets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets b/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets index 93be1c3..9f0382b 100644 --- a/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets +++ b/ohos/src/main/ets/components/FlutterDownloaderPlugin.ets @@ -440,7 +440,8 @@ export class FlutterDownloaderPlugin implements FlutterPlugin, MethodCallHandler } else { lastProgress = Math.trunc(progress.processed * 100 / progress.sizes[0]); // 状态是异步获取的,不存在由PAUSED状态直接变为RUNNING状态的情况,只能是PAUSED-->Resume-->RUNNING - if (status === DownloadStatus.RUNNING && syncTask && syncTask[TaskEntry.COLUMN_NAME_STATUS] === DownloadStatus.PAUSED && isResume !== 0) { + const isErrorRunning = status === DownloadStatus.RUNNING && syncTask && syncTask[TaskEntry.COLUMN_NAME_STATUS] === DownloadStatus.PAUSED && isResume !== 0 + if (isErrorRunning) { status = DownloadStatus.PAUSED; } const args: Map = new Map(); -- Gitee