diff --git a/go/pikapi/controller/common.go b/go/pikapi/controller/common.go index b3c7d1f..0c79fd2 100644 --- a/go/pikapi/controller/common.go +++ b/go/pikapi/controller/common.go @@ -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 { @@ -23,6 +26,7 @@ func onEvent(function string, content string) { } } +// 发送下载的事件 func downloadComicEventSend(comicDownload *comic_center.ComicDownload) { buff, err := json.Marshal(comicDownload) if err == nil { @@ -32,6 +36,7 @@ func downloadComicEventSend(comicDownload *comic_center.ComicDownload) { } } +// 发送导出的事件 func notifyExport(str string) { onEvent("EXPORT", str) } diff --git a/go/pikapi/controller/export.go b/go/pikapi/controller/export.go index ca88117..21c9415 100644 --- a/go/pikapi/controller/export.go +++ b/go/pikapi/controller/export.go @@ -18,6 +18,8 @@ import ( "time" ) +// 通过局域网导出 + var exportingListener net.Listener var exportingConn net.Conn diff --git a/lib/screens/DownloadListScreen.dart b/lib/screens/DownloadListScreen.dart index b4f262e..6fb9a66 100644 --- a/lib/screens/DownloadListScreen.dart +++ b/lib/screens/DownloadListScreen.dart @@ -23,7 +23,7 @@ class _DownloadListScreenState extends State { late bool _downloadRunning = false; late Future> _f = method.allDownloads(); - void _onMessageChange(String event){ + void _onMessageChange(String event) { print("EVENT"); print(event); if (event is String) { @@ -59,117 +59,9 @@ class _DownloadListScreenState extends State { 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( @@ -241,4 +133,116 @@ class _DownloadListScreenState extends State { ), ); } + + 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()), + ], + )); + } }