feat: support drag torrent file (#42)

This commit is contained in:
monkeyWie authored and GitHub committed 2022-11-07 14:12:12 +08:00
1 parent 77e59f7376
commit e9442edd94
9 files changed
+122 -79

No files matched your search

@@ -1,5 +1,3 @@
import 'package:get/get.dart';
class CreateController extends GetxController {
var currentIndex = 0.obs;
}
class CreateController extends GetxController {}
+63 -52
View File
@@ -1,3 +1,4 @@
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../api/api.dart';
@@ -32,65 +33,75 @@ class CreateView extends GetView<CreateController> {
actions: [Container()],
title: Text('create.title'.tr),
),
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Form(
key: _resolveFormKey,
autovalidateMode: AutovalidateMode.always,
child: Column(
children: [
TextFormField(
autofocus: true,
controller: _urlController,
minLines: 1,
maxLines: 15,
decoration: InputDecoration(
hintText: 'create.downloadLinkHit'.tr,
labelText: 'create.downloadLink'.tr,
icon: const Icon(Icons.link)),
validator: (v) {
return v!.trim().isNotEmpty
? null
: 'create.downloadLinkValid'.tr;
}),
// 登录按钮
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ConstrainedBox(
constraints: const BoxConstraints.tightFor(
width: 150,
height: 40,
),
child: RoundedLoadingButton(
color: Get.theme.colorScheme.secondary,
onPressed: () async {
if (_resolveFormKey.currentState!.validate()) {
_confirmController.start();
try {
final res = await resolve(Request(
url: _urlController.text,
));
await _showResolveDialog(res);
} catch (e) {
Get.snackbar('error'.tr, e.toString());
} finally {
_confirmController.reset();
body: DropTarget(
onDragDone: (details) {
_urlController.text = details.files[0].path;
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Form(
key: _resolveFormKey,
autovalidateMode: AutovalidateMode.always,
child: Column(
children: [
TextFormField(
autofocus: true,
controller: _urlController,
minLines: 1,
maxLines: 15,
decoration: InputDecoration(
hintText: _hitText(),
labelText: 'create.downloadLink'.tr,
icon: const Icon(Icons.link)),
validator: (v) {
return v!.trim().isNotEmpty
? null
: 'create.downloadLinkValid'.tr;
}),
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: ConstrainedBox(
constraints: const BoxConstraints.tightFor(
width: 150,
height: 40,
),
child: RoundedLoadingButton(
color: Get.theme.colorScheme.secondary,
onPressed: () async {
if (_resolveFormKey.currentState!.validate()) {
_confirmController.start();
try {
final res = await resolve(Request(
url: _urlController.text,
));
await _showResolveDialog(res);
} catch (e) {
Get.snackbar('error'.tr, e.toString());
} finally {
_confirmController.reset();
}
}
}
},
controller: _confirmController,
child: Text('confirm'.tr),
),
)),
),
],
},
controller: _confirmController,
child: Text('confirm'.tr),
),
)),
),
],
),
),
),
),
);
}
String _hitText() {
return 'create.downloadLinkHit'.trParams({
'append': Util.isDesktop() ? 'create.downloadLinkHitDesktop'.tr : '',
});
}
Future<void> _showResolveDialog(Resource res) async {
final createFormKey = GlobalKey<FormState>();
final pathController =
+28 -17
View File
@@ -16,8 +16,15 @@ class SettingView extends GetView<SettingController> {
Widget build(BuildContext context) {
Timer? timer;
debounceSave() {
var completer = Completer<void>();
timer?.cancel();
timer = Timer(const Duration(milliseconds: 500), Setting.instance.save);
timer = Timer(const Duration(milliseconds: 500), () {
Setting.instance
.save()
.then(completer.complete)
.onError(completer.completeError);
});
return completer.future;
}
return Scaffold(
@@ -39,12 +46,12 @@ class SettingView extends GetView<SettingController> {
() => DropdownButton<ThemeMode>(
value: controller.setting.value.themeMode,
isDense: true,
onChanged: (value) {
onChanged: (value) async {
controller.setting.value.themeMode = value!;
controller.clearTapStatus();
Get.changeThemeMode(value);
debounceSave();
await debounceSave();
},
items: ThemeMode.values
.map((e) => DropdownMenuItem<ThemeMode>(
@@ -57,14 +64,14 @@ class SettingView extends GetView<SettingController> {
() => controller.setting.value.downloadDir, () {
final downloadDirController = TextEditingController(
text: controller.setting.value.downloadDir);
downloadDirController.addListener(() {
downloadDirController.addListener(() async {
if (downloadDirController.text !=
controller.setting.value.downloadDir) {
controller.setting.value.downloadDir =
downloadDirController.text;
controller.clearTapStatus();
debounceSave();
await debounceSave();
}
});
return DirectorySelector(
@@ -77,14 +84,14 @@ class SettingView extends GetView<SettingController> {
() {
final connectionsController = TextEditingController(
text: controller.setting.value.connections.toString());
connectionsController.addListener(() {
connectionsController.addListener(() async {
if (connectionsController.text.isNotEmpty &&
connectionsController.text !=
controller.setting.value.connections.toString()) {
controller.setting.value.connections =
int.parse(connectionsController.text);
debounceSave();
await debounceSave();
}
});
@@ -100,20 +107,20 @@ class SettingView extends GetView<SettingController> {
_ConfigItem(
'setting.locale'.tr,
() => _getLocaleName(controller.setting.value.locale),
() => DropdownButton<Locale>(
() => DropdownButton<String>(
value: controller.setting.value.locale,
isDense: true,
onChanged: (value) {
onChanged: (value) async {
controller.setting.value.locale = value!;
controller.clearTapStatus();
Get.updateLocale(value);
Get.updateLocale(toLocale(value));
debounceSave();
await debounceSave();
},
items: _getLocales()
.map((e) => DropdownMenuItem<Locale>(
value: toLocale(e
.substring(_settingLocaleKey.length)),
.map((e) => DropdownMenuItem<String>(
value:
e.substring(_settingLocaleKey.length),
child: Text(e.tr),
))
.toList(),
@@ -164,14 +171,18 @@ class SettingView extends GetView<SettingController> {
final _settingLocaleKey = 'setting.locale.';
List<String> _getLocales() {
return messages.keys[fallbackLocale.toString()]!.entries
return messages.keys[getLocaleKey(fallbackLocale)]!.entries
.where((e) => e.key.startsWith(_settingLocaleKey))
.map((e) => e.key)
.toList();
}
String _getLocaleName(Locale locale) {
return '$_settingLocaleKey${locale.toString()}'.tr;
String _getLocaleName(String locale) {
final localeKey = '$_settingLocaleKey${locale.toString()}';
if (messages.keys[locale]?.containsKey(localeKey) ?? false) {
return localeKey.tr;
}
return '$_settingLocaleKey$locale'.tr;
}
}