mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 22:33:42 +00:00
feat: auto get create url from clipboard (#193)
This commit is contained in:
1 file changed
+29
-4
@@ -30,6 +30,8 @@ class CreateView extends GetView<CreateController> {
|
|||||||
final _httpRefererController = TextEditingController();
|
final _httpRefererController = TextEditingController();
|
||||||
final _btTrackerController = TextEditingController();
|
final _btTrackerController = TextEditingController();
|
||||||
|
|
||||||
|
final _availableSchemes = ["http:", "https:", "magnet:"];
|
||||||
|
|
||||||
CreateView({Key? key}) : super(key: key);
|
CreateView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -37,8 +39,24 @@ class CreateView extends GetView<CreateController> {
|
|||||||
final String? filePath = Get.rootDelegate.arguments();
|
final String? filePath = Get.rootDelegate.arguments();
|
||||||
if (_urlController.text.isEmpty && filePath != null) {
|
if (_urlController.text.isEmpty && filePath != null) {
|
||||||
_urlController.text = filePath;
|
_urlController.text = filePath;
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
_urlController.selection = TextSelection.fromPosition(
|
||||||
await _doResolve();
|
TextPosition(offset: _urlController.text.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no file path, read from clipboard
|
||||||
|
if (filePath?.isEmpty ?? true) {
|
||||||
|
Clipboard.getData('text/plain').then((value) {
|
||||||
|
if (value?.text?.isNotEmpty ?? false) {
|
||||||
|
if (_availableSchemes
|
||||||
|
.where((e) =>
|
||||||
|
value!.text!.startsWith(e) ||
|
||||||
|
value.text!.startsWith(e.toUpperCase()))
|
||||||
|
.isNotEmpty) {
|
||||||
|
_urlController.text = value!.text!;
|
||||||
|
_urlController.selection = TextSelection.fromPosition(
|
||||||
|
TextPosition(offset: _urlController.text.length));
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +78,11 @@ class CreateView extends GetView<CreateController> {
|
|||||||
final bytes = await details.files[0].readAsBytes();
|
final bytes = await details.files[0].readAsBytes();
|
||||||
controller.setFileDataUri(bytes);
|
controller.setFileDataUri(bytes);
|
||||||
},
|
},
|
||||||
|
child: GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding:
|
||||||
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
|
||||||
@@ -182,8 +205,9 @@ class CreateView extends GetView<CreateController> {
|
|||||||
controller.showAdvanced.value =
|
controller.showAdvanced.value =
|
||||||
!controller.showAdvanced.value;
|
!controller.showAdvanced.value;
|
||||||
},
|
},
|
||||||
child:
|
child: Row(
|
||||||
Row(mainAxisSize: MainAxisSize.min, children: [
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
Obx(() => Checkbox(
|
Obx(() => Checkbox(
|
||||||
value: controller.showAdvanced.value,
|
value: controller.showAdvanced.value,
|
||||||
onChanged: (bool? value) {
|
onChanged: (bool? value) {
|
||||||
@@ -209,6 +233,7 @@ class CreateView extends GetView<CreateController> {
|
|||||||
)),
|
)),
|
||||||
]))),
|
]))),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user