From db4003ad4fb66af01b14f8fb92301b5872892af0 Mon Sep 17 00:00:00 2001 From: Li Wei Date: Fri, 16 Dec 2022 14:53:07 +0800 Subject: [PATCH] fix: speed calculate (#63) --- pkg/download/downloader.go | 11 +++-------- pkg/download/model.go | 2 +- ui/flutter/lib/pages/setting/setting_view.dart | 18 ++++++++---------- ui/flutter/pubspec.yaml | 2 +- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index ee7289da..2293e8c9 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -102,14 +102,9 @@ func (d *Downloader) Setup() error { current := task.fetcher.Progress().TotalDownloaded() task.Progress.Used = task.timer.Used() - downloaded := current - task.Progress.Downloaded - usedTime := float64(d.refreshInterval) / 1000 - if downloaded == 0 { - task.Progress.Speed = int64(float64(task.Progress.Speed) / (usedTime * 1.55)) - } else { - usedTime := float64(d.refreshInterval) / 1000 - task.Progress.Speed = int64(float64(current-task.Progress.Downloaded) / usedTime) - } + currUsedTime := float64(d.refreshInterval) / 1000 + currSpeed := int64(float64(current-task.Progress.Downloaded) / currUsedTime) + task.Progress.Speed = (task.Progress.Speed + currSpeed) / 2 task.Progress.Downloaded = current d.emit(EventKeyProgress, task) diff --git a/pkg/download/model.go b/pkg/download/model.go index e5c887d7..42315069 100644 --- a/pkg/download/model.go +++ b/pkg/download/model.go @@ -34,7 +34,7 @@ func (cfg *DownloaderConfig) Init() *DownloaderConfig { } if cfg.RefreshInterval == 0 { - cfg.RefreshInterval = 500 + cfg.RefreshInterval = 350 } return cfg } diff --git a/ui/flutter/lib/pages/setting/setting_view.dart b/ui/flutter/lib/pages/setting/setting_view.dart index c0919f78..f3cf0e0c 100644 --- a/ui/flutter/lib/pages/setting/setting_view.dart +++ b/ui/flutter/lib/pages/setting/setting_view.dart @@ -135,15 +135,12 @@ class SettingView extends GetView { controller: trackerUpdateController, child: Text('setting.update'.tr), ), - Flexible( - child: SizedBox( - width: 200, - child: SwitchListTile( - controlAffinity: ListTileControlAffinity.leading, - value: true, - onChanged: (bool value) {}, - title: Text('setting.updateDaily'.tr)), - ), + Expanded( + child: SwitchListTile( + controlAffinity: ListTileControlAffinity.leading, + value: true, + onChanged: (bool value) {}, + title: Text('setting.updateDaily'.tr)), ), ], ), @@ -234,7 +231,8 @@ class SettingView extends GetView { title: Text('setting.homepage'.tr), subtitle: const Text('https://github.com/monkeyWie/gopeed'), onTap: () { - launchUrl(Uri.parse('https://github.com/monkeyWie/gopeed')); + launchUrl(Uri.parse('https://github.com/monkeyWie/gopeed'), + mode: LaunchMode.externalApplication); }, ); buildVersion() => ListTile( diff --git a/ui/flutter/pubspec.yaml b/ui/flutter/pubspec.yaml index 8a7e9559..03989c60 100644 --- a/ui/flutter/pubspec.yaml +++ b/ui/flutter/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.0+1 +version: 1.2.2+1 environment: sdk: ">=2.17.6 <3.0.0"