-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
540 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:dio/dio.dart'; | ||
|
||
class BTServerApi { | ||
static const baseApi = "http://localhost:3000"; | ||
static final dio = Dio(BaseOptions( | ||
baseUrl: baseApi, | ||
)); | ||
static Future<String> getVersion() async { | ||
return (await dio.get<String>("/version")).data!; | ||
} | ||
|
||
static Future<String> addTorrent(Uint8List torrent) async { | ||
return (await dio.post<Map<String, dynamic>>("/torrent", | ||
data: torrent, | ||
options: Options( | ||
headers: { | ||
"Content-Type": "application/x-bittorrent", | ||
"Content-Length": torrent.length, | ||
}, | ||
))) | ||
.data!["infoHash"]; | ||
} | ||
|
||
static Future<String> removeTorrent(String infoHash) async { | ||
return (await dio.delete<String>("/torrent/$infoHash")).data!; | ||
} | ||
|
||
static Future<List<String>> getFileList(String infoHash) async { | ||
final fileList = (await dio.get<Map<String, dynamic>>("/torrent/$infoHash")) | ||
.data!['files']; | ||
return List<String>.from(fileList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:miru_app/pages/main/controller.dart'; | ||
import 'package:miru_app/utils/bt_server.dart'; | ||
import 'package:miru_app/widgets/messenger.dart'; | ||
|
||
class BTDialogController extends GetxController { | ||
final isInstalled = false.obs; | ||
final isDownloading = false.obs; | ||
final progress = 0.0.obs; | ||
|
||
final _mainController = Get.find<MainController>(); | ||
late final isRuning = _mainController.btServerisRunning; | ||
late final version = _mainController.btServerVersion; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
SchedulerBinding.instance.addPostFrameCallback((_) async { | ||
isInstalled.value = await BTServerUtils.isInstalled(); | ||
}); | ||
} | ||
|
||
downloadOrUpgradeServer(BuildContext context) async { | ||
isDownloading.value = true; | ||
try { | ||
await BTServerUtils.downloadLatestBTServer( | ||
onReceiveProgress: (p0, p1) { | ||
progress.value = p0 / p1; | ||
print(progress.value); | ||
}, | ||
); | ||
} catch (e) { | ||
context.mounted && | ||
showPlatformSnackbar( | ||
context: context, | ||
content: e.toString(), | ||
); | ||
} finally { | ||
isDownloading.value = false; | ||
} | ||
isInstalled.value = await BTServerUtils.isInstalled(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:fluent_ui/fluent_ui.dart' as fluent; | ||
import 'package:get/get.dart'; | ||
import 'package:miru_app/pages/bt_dialog/controller.dart'; | ||
import 'package:miru_app/utils/bt_server.dart'; | ||
import 'package:miru_app/widgets/button.dart'; | ||
import 'package:miru_app/widgets/platform_widget.dart'; | ||
import 'package:miru_app/widgets/progress.dart'; | ||
|
||
class BTDialog extends StatefulWidget { | ||
const BTDialog({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<BTDialog> createState() => _BTDialogState(); | ||
} | ||
|
||
class _BTDialogState extends State<BTDialog> { | ||
final BTDialogController c = Get.put(BTDialogController()); | ||
|
||
Widget _buildContent(BuildContext context) { | ||
return Obx(() { | ||
if (!c.isInstalled.value) { | ||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
const Text("BT-Server is not installed"), | ||
const SizedBox(height: 16), | ||
if (c.isDownloading.value) | ||
SizedBox( | ||
width: double.infinity, | ||
child: ProgressBar(value: c.progress.value), | ||
) | ||
else | ||
PlatformFilledButton( | ||
child: const Text("Download"), | ||
onPressed: () { | ||
c.downloadOrUpgradeServer(context); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
return Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text("BT-Server is ${c.isRuning.value ? "running" : "stop"} "), | ||
const SizedBox(height: 16), | ||
if (c.isRuning.value) | ||
Text("Version: ${c.version.value}") | ||
else | ||
PlatformFilledButton( | ||
child: const Text("Start"), | ||
onPressed: () { | ||
BTServerUtils.startServer(); | ||
}, | ||
), | ||
], | ||
); | ||
}); | ||
} | ||
|
||
Widget _buildAndroid(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text("BT-Server"), | ||
content: _buildContent(context), | ||
actions: [ | ||
PlatformTextButton( | ||
child: const Text("Close"), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
Widget _buildDesktop(BuildContext context) { | ||
return fluent.ContentDialog( | ||
title: const Text("BT-Server"), | ||
content: _buildContent(context), | ||
actions: [ | ||
fluent.Button( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: const Text("Close"), | ||
), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PlatformBuildWidget( | ||
androidBuilder: _buildAndroid, | ||
desktopBuilder: _buildDesktop, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.