diff --git a/assets/tr.json b/assets/tr.json index 5993965..08ee0bf 100644 --- a/assets/tr.json +++ b/assets/tr.json @@ -121,7 +121,11 @@ "Proxy": "代理", "Appearance": "外观", "Language": "语言", - "Theme": "主题" + "Theme": "主题", + "Pause": "暂停", + "Resume": "继续", + "Paused": "已暂停", + "Delete all": "删除全部" }, "zh_TW": { "Search": "搜索", @@ -245,6 +249,10 @@ "Proxy": "代理", "Appearance": "外觀", "Language": "語言", - "Theme": "主題" + "Theme": "主題", + "Pause": "暫停", + "Resume": "繼續", + "Paused": "已暫停", + "Delete all": "刪除全部" } } \ No newline at end of file diff --git a/lib/network/download.dart b/lib/network/download.dart index 9e1f1cb..c68f325 100644 --- a/lib/network/download.dart +++ b/lib/network/download.dart @@ -163,6 +163,10 @@ class DownloadingTask { _stop = false; _download(); } + + void pause() { + _stop = true; + } } class DownloadManager { @@ -276,8 +280,20 @@ class DownloadManager { int get maxConcurrentTasks => appdata.settings["maxParallels"]; + bool _paused = false; + + bool get paused => _paused; + + void pause() { + _paused = true; + for(var task in tasks) { + task.pause(); + } + } + void run() { _loop ??= Timer.periodic(const Duration(seconds: 1), (timer) { + if(_paused) return; _bytesPerSecond = _currentBytes; _currentBytes = 0; uiUpdateCallback?.call(); @@ -349,4 +365,8 @@ class DownloadManager { i++; } } + + void resume() { + _paused = false; + } } \ No newline at end of file diff --git a/lib/pages/downloading_page.dart b/lib/pages/downloading_page.dart index 3685c39..1e408a1 100644 --- a/lib/pages/downloading_page.dart +++ b/lib/pages/downloading_page.dart @@ -47,7 +47,38 @@ class _DownloadingPageState extends State { Widget buildTop() { int bytesPerSecond = DownloadManager().bytesPerSecond; - return SliverTitleBar(title: "${"Speed".tl}: ${bytesToText(bytesPerSecond)}/s"); + bool paused = DownloadManager().paused; + + return SliverTitleBar( + title: paused + ? "Paused".tl + :"${"Speed".tl}: ${bytesToText(bytesPerSecond)}/s", + action: SplitButton( + onInvoked: (){ + if(!paused) { + DownloadManager().pause(); + setState(() {}); + } else { + DownloadManager().resume(); + setState(() {}); + } + }, + flyout: MenuFlyout( + items: [ + MenuFlyoutItem(text: Text("Cancel All".tl), onPressed: (){ + var tasks = List.from(DownloadManager().tasks); + DownloadManager().tasks.clear(); + for(var task in tasks) { + task.cancel(); + } + setState(() {}); + }) + ], + ), + child: Text(paused ? "Resume".tl : "Pause".tl) + .toCenter().fixWidth(56).fixHeight(32), + ), + ); } Widget buildContent() {