feat: task detail view (#633)

This commit is contained in:
Levi authored and GitHub committed 2024-08-08 18:34:00 +08:00
1 parent 3fd3dd49d2
commit 4d60c47d39
22 files changed
+280 -105

No files matched your search

@@ -195,7 +195,8 @@ class AppController extends GetxController with WindowListener, TrayListener {
} else if (Util.isMacos()) {
await trayManager.setIcon('assets/tray_icon/icon_mac.png',
isTemplate: true);
} else if (Platform.environment.containsKey('FLATPAK_ID') || Platform.environment.containsKey('SNAP')) {
} else if (Platform.environment.containsKey('FLATPAK_ID') ||
Platform.environment.containsKey('SNAP')) {
await trayManager.setIcon('com.gopeed.Gopeed');
} else {
await trayManager.setIcon('assets/tray_icon/icon.png');
@@ -269,16 +270,12 @@ class AppController extends GetxController with WindowListener, TrayListener {
FlutterForegroundTask.init(
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'gopeed_service',
channelName: 'Gopeed Background Service',
channelImportance: NotificationChannelImportance.LOW,
showWhen: true,
priority: NotificationPriority.LOW,
iconData: const NotificationIconData(
resType: ResourceType.mipmap,
resPrefix: ResourcePrefix.ic,
name: 'launcher',
)),
channelId: 'gopeed_service',
channelName: 'Gopeed Background Service',
channelImportance: NotificationChannelImportance.LOW,
showWhen: true,
priority: NotificationPriority.LOW,
),
iosNotificationOptions: const IOSNotificationOptions(
showNotification: true,
playSound: false,
@@ -298,6 +295,11 @@ class AppController extends GetxController with WindowListener, TrayListener {
FlutterForegroundTask.startService(
notificationTitle: "serviceTitle".tr,
notificationText: "serviceText".tr,
notificationIcon: const NotificationIconData(
resType: ResourceType.mipmap,
resPrefix: ResourcePrefix.ic,
name: 'launcher',
),
);
}
}
@@ -3,8 +3,10 @@ import 'dart:io';
import 'package:badges/badges.dart' as badges;
import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:gopeed/app/views/copy_button.dart';
import 'package:intl/intl.dart';
import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -842,6 +844,32 @@ class SettingView extends GetView<SettingController> {
);
});
// advanced config log items start
buildLogsDir() {
return ListTile(
title: Text("日志目录"),
subtitle: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: TextField(
controller: TextEditingController(text: logsDir()),
enabled: false,
readOnly: true,
),
),
Util.isDesktop()
? IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () {
launchUrl(Uri.file(logsDir()));
},
)
: CopyButton(logsDir()),
],
));
}
return Obx(() {
return GestureDetector(
onTap: () {
@@ -953,6 +981,13 @@ class SettingView extends GetView<SettingController> {
: null,
]),
)),
const Text('开发者'),
Card(
child: Column(
children: _addDivider([
buildLogsDir(),
]),
)),
]),
))
],
@@ -1,5 +1,10 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:gopeed/api/model/task.dart';
class TaskController extends GetxController {
final tabIndex = 0.obs;
final scaffoldKey = GlobalKey<ScaffoldState>();
final selectTask = Rx<Task?>(null);
final copyUrlDone = false.obs;
}
@@ -104,7 +104,7 @@ class TaskFilesView extends GetView<TaskFilesController> {
}()
: [
IconButton(
icon: const Icon(Icons.play_circle),
icon: const Icon(Icons.open_in_new),
onPressed: () async {
await OpenFilex.open(filePath);
}),
@@ -1,6 +1,13 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:open_filex/open_filex.dart';
import 'package:path/path.dart' as path;
import '../../../../api/model/task.dart';
import '../../../../util/file_explorer.dart';
import '../../../../util/util.dart';
import '../../../routes/app_pages.dart';
import '../../../views/copy_button.dart';
import '../controllers/task_controller.dart';
import '../controllers/task_downloaded_controller.dart';
import '../controllers/task_downloading_controller.dart';
@@ -12,9 +19,12 @@ class TaskView extends GetView<TaskController> {
@override
Widget build(BuildContext context) {
final selectTask = controller.selectTask;
return DefaultTabController(
length: 2,
child: Scaffold(
key: controller.scaffoldKey,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(56),
child: AppBar(
@@ -54,7 +64,118 @@ class TaskView extends GetView<TaskController> {
TaskDownloadedView(),
],
),
endDrawer: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: Obx(() => ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: [
SizedBox(
height: MediaQuery.of(context).padding.top + 65,
child: DrawerHeader(
child: Text(
'taskDetail'.tr,
style: Theme.of(context).textTheme.titleLarge,
)),
),
ListTile(
title: Text('taskName'.tr),
subtitle:
buildTooltipSubtitle(selectTask.value?.showName)),
ListTile(
title: Text('taskUrl'.tr),
subtitle:
buildTooltipSubtitle(selectTask.value?.meta.req.url),
trailing: CopyButton(selectTask.value?.meta.req.url),
),
ListTile(
title: Text('downloadPath'.tr),
subtitle:
buildTooltipSubtitle(selectTask.value?.explorerUrl),
trailing: IconButton(
icon: const Icon(Icons.folder_open),
onPressed: () {
selectTask.value?.explorer();
},
),
),
],
)),
),
),
);
}
Widget buildTooltipSubtitle(String? text) {
final showText = text ?? "";
return Tooltip(
message: showText,
child: Text(
showText,
overflow: TextOverflow.ellipsis,
),
);
}
}
extension TaskEnhance on Task {
String get showName {
if (meta.opts.name.isNotEmpty) {
return meta.opts.name;
}
if (meta.res == null) {
final u = Uri.parse(meta.req.url);
if (u.scheme.startsWith("http")) {
return u.path.isNotEmpty
? u.path.substring(u.path.lastIndexOf("/") + 1)
: u.host;
} else {
final params = u.queryParameters;
if (params.containsKey("dn")) {
return params["dn"]!;
} else {
return params["xt"]!.split(":").last;
}
}
}
if (meta.res!.name.isNotEmpty) {
return meta.res!.name;
}
return meta.res!.files[0].name;
}
bool get isFolder {
return meta.res?.name.isNotEmpty ?? false;
}
String get explorerUrl {
if (isFolder) {
return path.join(Util.safeDir(meta.opts.path),
Util.safeDir(meta.res!.files[0].path), showName);
} else {
return path.join(Util.safeDir(meta.opts.path), Util.safeDir(showName));
}
}
Future<void> explorer() async {
if (Util.isDesktop()) {
await FileExplorer.openAndSelectFile(explorerUrl);
} else {
Get.rootDelegate.toNamed(Routes.TASK_FILES, parameters: {'id': id});
}
}
Future<void> open() async {
if (status != Status.done) {
return;
}
if (isFolder) {
await explorer();
} else {
await OpenFilex.open(explorerUrl);
}
}
}