add comment

This commit is contained in:
niuhuan 2021-10-20 10:54:23 +08:00
parent 4e838a2c45
commit afda9cc6d3
3 changed files with 123 additions and 112 deletions

View File

@ -5,8 +5,11 @@ import (
"pgo/pikapi/database/comic_center" "pgo/pikapi/database/comic_center"
) )
// EventNotify EventChannel 总线
var EventNotify func(message string) var EventNotify func(message string)
// 所有的EventChannel都是从这里发出, 格式为json, function代表了是什么事件, content是消息的内容
// 消息传到前端后由前端调度分发
func onEvent(function string, content string) { func onEvent(function string, content string) {
event := EventNotify event := EventNotify
if event != nil { if event != nil {
@ -23,6 +26,7 @@ func onEvent(function string, content string) {
} }
} }
// 发送下载的事件
func downloadComicEventSend(comicDownload *comic_center.ComicDownload) { func downloadComicEventSend(comicDownload *comic_center.ComicDownload) {
buff, err := json.Marshal(comicDownload) buff, err := json.Marshal(comicDownload)
if err == nil { if err == nil {
@ -32,6 +36,7 @@ func downloadComicEventSend(comicDownload *comic_center.ComicDownload) {
} }
} }
// 发送导出的事件
func notifyExport(str string) { func notifyExport(str string) {
onEvent("EXPORT", str) onEvent("EXPORT", str)
} }

View File

@ -18,6 +18,8 @@ import (
"time" "time"
) )
// 通过局域网导出
var exportingListener net.Listener var exportingListener net.Listener
var exportingConn net.Conn var exportingConn net.Conn

View File

@ -23,7 +23,7 @@ class _DownloadListScreenState extends State<DownloadListScreen> {
late bool _downloadRunning = false; late bool _downloadRunning = false;
late Future<List<DownloadComic>> _f = method.allDownloads(); late Future<List<DownloadComic>> _f = method.allDownloads();
void _onMessageChange(String event){ void _onMessageChange(String event) {
print("EVENT"); print("EVENT");
print(event); print(event);
if (event is String) { if (event is String) {
@ -59,117 +59,9 @@ class _DownloadListScreenState extends State<DownloadListScreen> {
appBar: AppBar( appBar: AppBar(
title: Text('下载列表'), title: Text('下载列表'),
actions: [ actions: [
...(Platform.isWindows || importButton(),
Platform.isMacOS || pauseButton(),
Platform.isLinux || resetFailedButton(),
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()),
],
)),
], ],
), ),
body: FutureBuilder( body: FutureBuilder(
@ -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()),
],
));
}
} }