mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 06:43:42 +00:00
feat: support drag torrent file (#42)
This commit is contained in:
1 parent
77e59f7376
commit
e9442edd94
9 files changed
+122
-79
No files matched your search
@@ -6,6 +6,10 @@ Locale toLocale(String key) {
|
|||||||
return Locale(arr[0], arr[1]);
|
return Locale(arr[0], arr[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getLocaleKey(Locale locale) {
|
||||||
|
return '${locale.languageCode}_${locale.countryCode}';
|
||||||
|
}
|
||||||
|
|
||||||
final messages = _Messages();
|
final messages = _Messages();
|
||||||
const fallbackLocale = Locale('en', 'US');
|
const fallbackLocale = Locale('en', 'US');
|
||||||
|
|
||||||
@@ -21,7 +25,8 @@ class _Messages extends Translations {
|
|||||||
'create.title': '创建任务',
|
'create.title': '创建任务',
|
||||||
'create.downloadLink': '下载链接',
|
'create.downloadLink': '下载链接',
|
||||||
'create.downloadLinkValid': '请输入下载链接',
|
'create.downloadLinkValid': '请输入下载链接',
|
||||||
'create.downloadLinkHit': '请输入下载链接,支持 HTTP/HTTPS/MAGNET',
|
'create.downloadLinkHit': '请输入下载链接,支持 HTTP/HTTPS/MAGNET@append',
|
||||||
|
'create.downloadLinkHitDesktop': ',也可以直接拖拽种子文件到此处',
|
||||||
'create.download': '下载',
|
'create.download': '下载',
|
||||||
'create.error.noStoragePermission': '需要开启存储权限',
|
'create.error.noStoragePermission': '需要开启存储权限',
|
||||||
'create.selectDir': '选择目录',
|
'create.selectDir': '选择目录',
|
||||||
@@ -51,7 +56,9 @@ class _Messages extends Translations {
|
|||||||
'create.downloadLink': 'Download Link',
|
'create.downloadLink': 'Download Link',
|
||||||
'create.downloadLinkValid': 'Please enter the download link',
|
'create.downloadLinkValid': 'Please enter the download link',
|
||||||
'create.downloadLinkHit':
|
'create.downloadLinkHit':
|
||||||
'Please enter the download link, HTTP/HTTPS/MAGNET supported',
|
'Please enter the download link, HTTP/HTTPS/MAGNET supported@append',
|
||||||
|
'create.downloadLinkHitDesktop':
|
||||||
|
', or drag the torrent file here directly',
|
||||||
'create.download': 'Download',
|
'create.download': 'Download',
|
||||||
'create.error.noStoragePermission': 'Storage permission required',
|
'create.error.noStoragePermission': 'Storage permission required',
|
||||||
'create.selectDir': 'Select Directory',
|
'create.selectDir': 'Select Directory',
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void main() async {
|
|||||||
darkTheme: GopeedTheme.dark,
|
darkTheme: GopeedTheme.dark,
|
||||||
themeMode: Setting.instance.themeMode,
|
themeMode: Setting.instance.themeMode,
|
||||||
translations: messages,
|
translations: messages,
|
||||||
locale: Setting.instance.locale,
|
locale: toLocale(Setting.instance.locale),
|
||||||
fallbackLocale: fallbackLocale,
|
fallbackLocale: fallbackLocale,
|
||||||
getPages: Routes.routes,
|
getPages: Routes.routes,
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class CreateController extends GetxController {
|
class CreateController extends GetxController {}
|
||||||
var currentIndex = 0.obs;
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:desktop_drop/desktop_drop.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import '../../api/api.dart';
|
import '../../api/api.dart';
|
||||||
@@ -32,65 +33,75 @@ class CreateView extends GetView<CreateController> {
|
|||||||
actions: [Container()],
|
actions: [Container()],
|
||||||
title: Text('create.title'.tr),
|
title: Text('create.title'.tr),
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: DropTarget(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
onDragDone: (details) {
|
||||||
child: Form(
|
_urlController.text = details.files[0].path;
|
||||||
key: _resolveFormKey,
|
},
|
||||||
autovalidateMode: AutovalidateMode.always,
|
child: Padding(
|
||||||
child: Column(
|
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||||
children: [
|
child: Form(
|
||||||
TextFormField(
|
key: _resolveFormKey,
|
||||||
autofocus: true,
|
autovalidateMode: AutovalidateMode.always,
|
||||||
controller: _urlController,
|
child: Column(
|
||||||
minLines: 1,
|
children: [
|
||||||
maxLines: 15,
|
TextFormField(
|
||||||
decoration: InputDecoration(
|
autofocus: true,
|
||||||
hintText: 'create.downloadLinkHit'.tr,
|
controller: _urlController,
|
||||||
labelText: 'create.downloadLink'.tr,
|
minLines: 1,
|
||||||
icon: const Icon(Icons.link)),
|
maxLines: 15,
|
||||||
validator: (v) {
|
decoration: InputDecoration(
|
||||||
return v!.trim().isNotEmpty
|
hintText: _hitText(),
|
||||||
? null
|
labelText: 'create.downloadLink'.tr,
|
||||||
: 'create.downloadLinkValid'.tr;
|
icon: const Icon(Icons.link)),
|
||||||
}),
|
validator: (v) {
|
||||||
// 登录按钮
|
return v!.trim().isNotEmpty
|
||||||
Center(
|
? null
|
||||||
child: Padding(
|
: 'create.downloadLinkValid'.tr;
|
||||||
padding: const EdgeInsets.all(15.0),
|
}),
|
||||||
child: ConstrainedBox(
|
Center(
|
||||||
constraints: const BoxConstraints.tightFor(
|
child: Padding(
|
||||||
width: 150,
|
padding: const EdgeInsets.all(15.0),
|
||||||
height: 40,
|
child: ConstrainedBox(
|
||||||
),
|
constraints: const BoxConstraints.tightFor(
|
||||||
child: RoundedLoadingButton(
|
width: 150,
|
||||||
color: Get.theme.colorScheme.secondary,
|
height: 40,
|
||||||
onPressed: () async {
|
),
|
||||||
if (_resolveFormKey.currentState!.validate()) {
|
child: RoundedLoadingButton(
|
||||||
_confirmController.start();
|
color: Get.theme.colorScheme.secondary,
|
||||||
try {
|
onPressed: () async {
|
||||||
final res = await resolve(Request(
|
if (_resolveFormKey.currentState!.validate()) {
|
||||||
url: _urlController.text,
|
_confirmController.start();
|
||||||
));
|
try {
|
||||||
await _showResolveDialog(res);
|
final res = await resolve(Request(
|
||||||
} catch (e) {
|
url: _urlController.text,
|
||||||
Get.snackbar('error'.tr, e.toString());
|
));
|
||||||
} finally {
|
await _showResolveDialog(res);
|
||||||
_confirmController.reset();
|
} catch (e) {
|
||||||
|
Get.snackbar('error'.tr, e.toString());
|
||||||
|
} finally {
|
||||||
|
_confirmController.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
controller: _confirmController,
|
||||||
controller: _confirmController,
|
child: Text('confirm'.tr),
|
||||||
child: Text('confirm'.tr),
|
),
|
||||||
),
|
)),
|
||||||
)),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _hitText() {
|
||||||
|
return 'create.downloadLinkHit'.trParams({
|
||||||
|
'append': Util.isDesktop() ? 'create.downloadLinkHitDesktop'.tr : '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _showResolveDialog(Resource res) async {
|
Future<void> _showResolveDialog(Resource res) async {
|
||||||
final createFormKey = GlobalKey<FormState>();
|
final createFormKey = GlobalKey<FormState>();
|
||||||
final pathController =
|
final pathController =
|
||||||
|
|||||||
@@ -16,8 +16,15 @@ class SettingView extends GetView<SettingController> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
debounceSave() {
|
debounceSave() {
|
||||||
|
var completer = Completer<void>();
|
||||||
timer?.cancel();
|
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(
|
return Scaffold(
|
||||||
@@ -39,12 +46,12 @@ class SettingView extends GetView<SettingController> {
|
|||||||
() => DropdownButton<ThemeMode>(
|
() => DropdownButton<ThemeMode>(
|
||||||
value: controller.setting.value.themeMode,
|
value: controller.setting.value.themeMode,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
onChanged: (value) {
|
onChanged: (value) async {
|
||||||
controller.setting.value.themeMode = value!;
|
controller.setting.value.themeMode = value!;
|
||||||
controller.clearTapStatus();
|
controller.clearTapStatus();
|
||||||
Get.changeThemeMode(value);
|
Get.changeThemeMode(value);
|
||||||
|
|
||||||
debounceSave();
|
await debounceSave();
|
||||||
},
|
},
|
||||||
items: ThemeMode.values
|
items: ThemeMode.values
|
||||||
.map((e) => DropdownMenuItem<ThemeMode>(
|
.map((e) => DropdownMenuItem<ThemeMode>(
|
||||||
@@ -57,14 +64,14 @@ class SettingView extends GetView<SettingController> {
|
|||||||
() => controller.setting.value.downloadDir, () {
|
() => controller.setting.value.downloadDir, () {
|
||||||
final downloadDirController = TextEditingController(
|
final downloadDirController = TextEditingController(
|
||||||
text: controller.setting.value.downloadDir);
|
text: controller.setting.value.downloadDir);
|
||||||
downloadDirController.addListener(() {
|
downloadDirController.addListener(() async {
|
||||||
if (downloadDirController.text !=
|
if (downloadDirController.text !=
|
||||||
controller.setting.value.downloadDir) {
|
controller.setting.value.downloadDir) {
|
||||||
controller.setting.value.downloadDir =
|
controller.setting.value.downloadDir =
|
||||||
downloadDirController.text;
|
downloadDirController.text;
|
||||||
controller.clearTapStatus();
|
controller.clearTapStatus();
|
||||||
|
|
||||||
debounceSave();
|
await debounceSave();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return DirectorySelector(
|
return DirectorySelector(
|
||||||
@@ -77,14 +84,14 @@ class SettingView extends GetView<SettingController> {
|
|||||||
() {
|
() {
|
||||||
final connectionsController = TextEditingController(
|
final connectionsController = TextEditingController(
|
||||||
text: controller.setting.value.connections.toString());
|
text: controller.setting.value.connections.toString());
|
||||||
connectionsController.addListener(() {
|
connectionsController.addListener(() async {
|
||||||
if (connectionsController.text.isNotEmpty &&
|
if (connectionsController.text.isNotEmpty &&
|
||||||
connectionsController.text !=
|
connectionsController.text !=
|
||||||
controller.setting.value.connections.toString()) {
|
controller.setting.value.connections.toString()) {
|
||||||
controller.setting.value.connections =
|
controller.setting.value.connections =
|
||||||
int.parse(connectionsController.text);
|
int.parse(connectionsController.text);
|
||||||
|
|
||||||
debounceSave();
|
await debounceSave();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -100,20 +107,20 @@ class SettingView extends GetView<SettingController> {
|
|||||||
_ConfigItem(
|
_ConfigItem(
|
||||||
'setting.locale'.tr,
|
'setting.locale'.tr,
|
||||||
() => _getLocaleName(controller.setting.value.locale),
|
() => _getLocaleName(controller.setting.value.locale),
|
||||||
() => DropdownButton<Locale>(
|
() => DropdownButton<String>(
|
||||||
value: controller.setting.value.locale,
|
value: controller.setting.value.locale,
|
||||||
isDense: true,
|
isDense: true,
|
||||||
onChanged: (value) {
|
onChanged: (value) async {
|
||||||
controller.setting.value.locale = value!;
|
controller.setting.value.locale = value!;
|
||||||
controller.clearTapStatus();
|
controller.clearTapStatus();
|
||||||
Get.updateLocale(value);
|
Get.updateLocale(toLocale(value));
|
||||||
|
|
||||||
debounceSave();
|
await debounceSave();
|
||||||
},
|
},
|
||||||
items: _getLocales()
|
items: _getLocales()
|
||||||
.map((e) => DropdownMenuItem<Locale>(
|
.map((e) => DropdownMenuItem<String>(
|
||||||
value: toLocale(e
|
value:
|
||||||
.substring(_settingLocaleKey.length)),
|
e.substring(_settingLocaleKey.length),
|
||||||
child: Text(e.tr),
|
child: Text(e.tr),
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
@@ -164,14 +171,18 @@ class SettingView extends GetView<SettingController> {
|
|||||||
final _settingLocaleKey = 'setting.locale.';
|
final _settingLocaleKey = 'setting.locale.';
|
||||||
|
|
||||||
List<String> _getLocales() {
|
List<String> _getLocales() {
|
||||||
return messages.keys[fallbackLocale.toString()]!.entries
|
return messages.keys[getLocaleKey(fallbackLocale)]!.entries
|
||||||
.where((e) => e.key.startsWith(_settingLocaleKey))
|
.where((e) => e.key.startsWith(_settingLocaleKey))
|
||||||
.map((e) => e.key)
|
.map((e) => e.key)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getLocaleName(Locale locale) {
|
String _getLocaleName(String locale) {
|
||||||
return '$_settingLocaleKey${locale.toString()}'.tr;
|
final localeKey = '$_settingLocaleKey${locale.toString()}';
|
||||||
|
if (messages.keys[locale]?.containsKey(localeKey) ?? false) {
|
||||||
|
return localeKey.tr;
|
||||||
|
}
|
||||||
|
return '$_settingLocaleKey$locale'.tr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,16 @@ class Setting {
|
|||||||
int port = 0;
|
int port = 0;
|
||||||
int connections = 0;
|
int connections = 0;
|
||||||
String downloadDir = "";
|
String downloadDir = "";
|
||||||
ThemeMode themeMode = ThemeMode.system;
|
late ThemeMode themeMode;
|
||||||
Locale locale = ui.window.locale;
|
late String locale;
|
||||||
|
|
||||||
// singleton pattern
|
// singleton pattern
|
||||||
static Setting? _instance;
|
static Setting? _instance;
|
||||||
|
|
||||||
static Setting get instance {
|
static Setting get instance {
|
||||||
_instance ??= Setting._internal();
|
_instance ??= Setting._internal();
|
||||||
|
_instance!.themeMode = ThemeMode.system;
|
||||||
|
_instance!.locale = getLocaleKey(ui.window.locale);
|
||||||
return _instance!;
|
return _instance!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ class Setting {
|
|||||||
}
|
}
|
||||||
final locale = config.extra?['locale'];
|
final locale = config.extra?['locale'];
|
||||||
if (locale != null) {
|
if (locale != null) {
|
||||||
this.locale = toLocale(locale);
|
this.locale = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util.isWeb()) {
|
if (Util.isWeb()) {
|
||||||
@@ -67,7 +69,7 @@ class Setting {
|
|||||||
downloadDir: downloadDir,
|
downloadDir: downloadDir,
|
||||||
extra: {
|
extra: {
|
||||||
'themeMode': themeMode.name,
|
'themeMode': themeMode.name,
|
||||||
'locale': locale.toString(),
|
'locale': locale,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await putConfig(config);
|
await putConfig(config);
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
PODS:
|
PODS:
|
||||||
|
- desktop_drop (0.0.1):
|
||||||
|
- FlutterMacOS
|
||||||
- file_selector_macos (0.0.1):
|
- file_selector_macos (0.0.1):
|
||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
- FlutterMacOS (1.0.0)
|
- FlutterMacOS (1.0.0)
|
||||||
@@ -12,6 +14,7 @@ PODS:
|
|||||||
- FlutterMacOS
|
- FlutterMacOS
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
|
- desktop_drop (from `Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos`)
|
||||||
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
|
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
|
||||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||||
- macos_secure_bookmarks (from `Flutter/ephemeral/.symlinks/plugins/macos_secure_bookmarks/macos`)
|
- macos_secure_bookmarks (from `Flutter/ephemeral/.symlinks/plugins/macos_secure_bookmarks/macos`)
|
||||||
@@ -20,6 +23,8 @@ DEPENDENCIES:
|
|||||||
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
|
desktop_drop:
|
||||||
|
:path: Flutter/ephemeral/.symlinks/plugins/desktop_drop/macos
|
||||||
file_selector_macos:
|
file_selector_macos:
|
||||||
:path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos
|
||||||
FlutterMacOS:
|
FlutterMacOS:
|
||||||
@@ -34,6 +39,7 @@ EXTERNAL SOURCES:
|
|||||||
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
|
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
|
desktop_drop: 69eeff437544aa619c8db7f4481b3a65f7696898
|
||||||
file_selector_macos: f1b08a781e66103e3ba279fd5d4024a2478b3af6
|
file_selector_macos: f1b08a781e66103e3ba279fd5d4024a2478b3af6
|
||||||
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
||||||
macos_secure_bookmarks: cff041c4b377fa00941bb901aaec4d27fac5edf2
|
macos_secure_bookmarks: cff041c4b377fa00941bb901aaec4d27fac5edf2
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.4"
|
version: "2.2.4"
|
||||||
|
desktop_drop:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: desktop_drop
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.3.3"
|
||||||
dio:
|
dio:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ dependencies:
|
|||||||
permission_handler: ^10.1.0
|
permission_handler: ^10.1.0
|
||||||
external_path: ^1.0.3
|
external_path: ^1.0.3
|
||||||
logger: ^1.1.0
|
logger: ^1.1.0
|
||||||
|
desktop_drop: ^0.3.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in new issue
Block a user