Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Oct 20, 2021
1 parent 4e838a2 commit afda9cc
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 112 deletions.
5 changes: 5 additions & 0 deletions go/pikapi/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"pgo/pikapi/database/comic_center"
)

// EventNotify EventChannel 总线
var EventNotify func(message string)

// 所有的EventChannel都是从这里发出, 格式为json, function代表了是什么事件, content是消息的内容
// 消息传到前端后由前端调度分发
func onEvent(function string, content string) {
event := EventNotify
if event != nil {
Expand All @@ -23,6 +26,7 @@ func onEvent(function string, content string) {
}
}

// 发送下载的事件
func downloadComicEventSend(comicDownload *comic_center.ComicDownload) {
buff, err := json.Marshal(comicDownload)
if err == nil {
Expand All @@ -32,6 +36,7 @@ func downloadComicEventSend(comicDownload *comic_center.ComicDownload) {
}
}

// 发送导出的事件
func notifyExport(str string) {
onEvent("EXPORT", str)
}
Expand Down
2 changes: 2 additions & 0 deletions go/pikapi/controller/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"time"
)

// 通过局域网导出

var exportingListener net.Listener
var exportingConn net.Conn

Expand Down
228 changes: 116 additions & 112 deletions lib/screens/DownloadListScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _DownloadListScreenState extends State<DownloadListScreen> {
late bool _downloadRunning = false;
late Future<List<DownloadComic>> _f = method.allDownloads();

void _onMessageChange(String event){
void _onMessageChange(String event) {
print("EVENT");
print(event);
if (event is String) {
Expand Down Expand Up @@ -59,117 +59,9 @@ class _DownloadListScreenState extends State<DownloadListScreen> {
appBar: AppBar(
title: Text('下载列表'),
actions: [
...(Platform.isWindows ||
Platform.isMacOS ||
Platform.isLinux ||
Platform.isAndroid ||
Platform.isIOS)
? [
MaterialButton(
minWidth: 0,
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DownloadImportScreen(),
),
);
setState(() {
_f = method.allDownloads();
});
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
Icons.label_important,
size: 18,
color: Colors.white,
),
Text(
'导入',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
)),
]
: [],
MaterialButton(
minWidth: 0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('下载任务'),
content: Text(
_downloadRunning ? "暂停下载吗?" : "启动下载吗?",
),
actions: [
MaterialButton(
onPressed: () async {
Navigator.pop(context);
},
child: Text('取消'),
),
MaterialButton(
onPressed: () async {
Navigator.pop(context);
var to = !_downloadRunning;
await method.setDownloadRunning(to);
setState(() {
_downloadRunning = to;
});
},
child: Text('确认'),
),
],
);
},
);
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
_downloadRunning
? Icons.compare_arrows_sharp
: Icons.schedule_send,
size: 18,
color: Colors.white,
),
Text(
_downloadRunning ? '下载中' : '暂停中',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
)),
MaterialButton(
minWidth: 0,
onPressed: () async {
await method.resetFailed();
setState(() {
_f = method.allDownloads();
});
defaultToast(context, "所有失败的下载已经恢复");
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
Icons.sync_problem,
size: 18,
color: Colors.white,
),
Text(
'恢复',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
)),
importButton(),
pauseButton(),
resetFailedButton(),
],
),
body: FutureBuilder(
Expand Down Expand Up @@ -241,4 +133,116 @@ class _DownloadListScreenState extends State<DownloadListScreen> {
),
);
}

Widget importButton() {
return MaterialButton(
minWidth: 0,
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DownloadImportScreen(),
),
);
setState(() {
_f = method.allDownloads();
});
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
Icons.label_important,
size: 18,
color: Colors.white,
),
Text(
'导入',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
));
}

Widget pauseButton() {
return MaterialButton(
minWidth: 0,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('下载任务'),
content: Text(
_downloadRunning ? "暂停下载吗?" : "启动下载吗?",
),
actions: [
MaterialButton(
onPressed: () async {
Navigator.pop(context);
},
child: Text('取消'),
),
MaterialButton(
onPressed: () async {
Navigator.pop(context);
var to = !_downloadRunning;
await method.setDownloadRunning(to);
setState(() {
_downloadRunning = to;
});
},
child: Text('确认'),
),
],
);
},
);
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
_downloadRunning
? Icons.compare_arrows_sharp
: Icons.schedule_send,
size: 18,
color: Colors.white,
),
Text(
_downloadRunning ? '下载中' : '暂停中',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
));
}

Widget resetFailedButton() {
return MaterialButton(
minWidth: 0,
onPressed: () async {
await method.resetFailed();
setState(() {
_f = method.allDownloads();
});
defaultToast(context, "所有失败的下载已经恢复");
},
child: Column(
children: [
Expanded(child: Container()),
Icon(
Icons.sync_problem,
size: 18,
color: Colors.white,
),
Text(
'恢复',
style: TextStyle(fontSize: 14, color: Colors.white),
),
Expanded(child: Container()),
],
));
}
}

0 comments on commit afda9cc

Please sign in to comment.