From 2cb93a03e246518e2d92625b41667165d0a68a18 Mon Sep 17 00:00:00 2001 From: Levi Date: Sat, 21 Dec 2024 09:58:33 +0800 Subject: [PATCH] perf: extension onStart hook will block task create (#844) --- pkg/download/downloader.go | 3 +-- ui/flutter/lib/util/message.dart | 13 ++++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index d63322a7f..7165027e5 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -1018,8 +1018,6 @@ func (d *Downloader) doStart(task *Task) (err error) { return } isCreate = task.Status == base.DownloadStatusReady - - d.triggerOnStart(task) task.updateStatus(base.DownloadStatusRunning) return @@ -1036,6 +1034,7 @@ func (d *Downloader) doStart(task *Task) (err error) { task.lock.Lock() defer task.lock.Unlock() + d.triggerOnStart(task) if task.Meta.Res == nil { err := task.fetcher.Resolve(task.Meta.Req) if err != nil { diff --git a/ui/flutter/lib/util/message.dart b/ui/flutter/lib/util/message.dart index 713ef62c5..313caaf54 100644 --- a/ui/flutter/lib/util/message.dart +++ b/ui/flutter/lib/util/message.dart @@ -8,9 +8,16 @@ void showErrorMessage(msg) { Get.snackbar(title, msg.msg!); return; } - if (msg is Exception && (msg as dynamic).message is Result) { - Get.snackbar(title, ((msg as dynamic).message as Result).msg!); - return; + if (msg is Exception) { + final message = (msg as dynamic).message; + if (message is Result) { + Get.snackbar(title, ((msg as dynamic).message as Result).msg!); + return; + } + if (message is String) { + Get.snackbar(title, message); + return; + } } Get.snackbar(title, msg.toString()); }