mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
pause and delete all
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -47,7 +47,38 @@ class _DownloadingPageState extends State<DownloadingPage> {
|
||||
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() {
|
||||
|
Reference in New Issue
Block a user