Skip to content

Commit

Permalink
refactor(drop): replace native_shell to desktop_drop
Browse files Browse the repository at this point in the history
  • Loading branch information
mengyanshou committed Dec 1, 2021
1 parent b6f82a0 commit 5e3a4e4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 64 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
## 1.2.8
- [修复] macOS 桌面端退出会无响应的bug
- [重构] 桌面端拖拽文件的方案由 native_shell 替换为 desktop_drop

## 1.2.7
- [优化]提升获取其他设备的图标速度
- [修复]图标未全部获取也能使用launcher
- [修复]修复图标错乱的bug
- [优化]支持获取小米10s/小米平板5类的设备名称
- [优化]减少server的体积

## 1.2.6
- [改动]切换adb二进制为自编译版本(因为ndk-adb这个库的adb首次启动很慢,并且不能支持`adb pair ip:port code`)
- [优化]死循环申请USB权限的问题
Expand Down
4 changes: 2 additions & 2 deletions lib/app/modules/developer_tool/developer_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class _DeveloperToolState extends State<DeveloperTool>
),
SizedBox(
height: 200.w,
child: DropTarget(
child: DropTargetContainer(
title: (GetPlatform.isDesktop ? '拖放到此或' : '') +
'点击按钮选择Apk进行安装',
onTap: () async {
Expand Down Expand Up @@ -444,7 +444,7 @@ class _DeveloperToolState extends State<DeveloperTool>
),
SizedBox(
height: 200.w,
child: DropTarget(
child: DropTargetContainer(
title: (GetPlatform.isDesktop ? '拖放到此或' : '') +
'点击按钮选择文件进行上传',
onTap: () async {
Expand Down
2 changes: 1 addition & 1 deletion lib/app/modules/developer_tool/dialog/install_apk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class _InstallApkDialogState extends State<InstallApkDialog> {
child: Material(
borderRadius: BorderRadius.circular(12.w),
child: SizedBox(
width: 300.w,
width: 400.w,
height: 64.w,
child: Padding(
padding: EdgeInsets.all(8.w),
Expand Down
3 changes: 2 additions & 1 deletion lib/app/modules/developer_tool/dialog/push_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ class _PushFileDialogState extends State<PushFileDialog> {
child: Material(
borderRadius: BorderRadius.circular(12.w),
child: SizedBox(
width: 300.w,
width: 400.w,
height: 64.w,
child: Padding(
padding: EdgeInsets.all(8.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'上传 $currentFile 中...',
Expand Down
87 changes: 28 additions & 59 deletions lib/app/modules/developer_tool/drag_drop.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:adb_tool/themes/app_colors.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/widgets.dart';
import 'package:global_repository/global_repository.dart';
import 'package:nativeshell/nativeshell.dart';
import 'package:path/path.dart' as p;

final customDragData = DragDataKey<Map>('custom-drag-data');
typedef PerformCall = void Function(List<String> paths);

class DropTarget extends StatefulWidget {
const DropTarget({
class DropTargetContainer extends StatefulWidget {
const DropTargetContainer({
Key key,
this.onPerform,
this.onTap,
Expand All @@ -21,49 +21,42 @@ class DropTarget extends StatefulWidget {
final String title;
@override
State<StatefulWidget> createState() {
return _DropTargetState();
return _DropTargetContainerState();
}
}

class _DropTargetState extends State<DropTarget> {
DragEffect pickEffect(Set<DragEffect> allowedEffects) {
if (allowedEffects.contains(DragEffect.Copy)) {
return DragEffect.Copy;
} else if (allowedEffects.contains(DragEffect.Link)) {
return DragEffect.Link;
} else {
return allowedEffects.isNotEmpty ? allowedEffects.first : DragEffect.None;
}
}

class _DropTargetContainerState extends State<DropTargetContainer> {
final List<XFile> _list = [];
@override
Widget build(BuildContext context) {
return DropRegion(
onDropOver: (event) async {
final res = pickEffect(event.info.allowedEffects);
final data = event.info.data;
_files = await data.get(DragData.files);
_uris = await data.get(DragData.uris);
_customData = await data.get(customDragData);

return res;
return DropTarget(
onDragDone: (detail) {
_list.addAll(detail.urls.map((e) => XFile(e.path)));
setState(() {});
final List<String> paths = [];
for (final XFile file in _list) {
paths.add(file.path);
}
Log.d('paths -> $paths');
widget.onPerform(paths);
_list.clear();
},
onDropExit: () {
onDragUpdated: (details) {
setState(() {
_files = null;
_uris = null;
_customData = null;
dropping = false;
// offset = details.localPosition;
});
},
onDropEnter: () {
onDragEntered: (detail) {
setState(() {
dropping = true;
// offset = detail.localPosition;
});
},
onPerformDrop: (e) {
widget.onPerform?.call(_files);
print('Performed drop!');
onDragExited: (detail) {
setState(() {
dropping = false;
// offset = null;
});
},
child: AnimatedContainer(
decoration: BoxDecoration(
Expand All @@ -85,7 +78,7 @@ class _DropTargetState extends State<DropTarget> {
color: AppColors.fontColor,
),
child: Text(
_describeDragData(),
'释放执行操作',
style: const TextStyle(
color: AppColors.accent,
fontWeight: FontWeight.bold,
Expand Down Expand Up @@ -133,29 +126,5 @@ class _DropTargetState extends State<DropTarget> {
);
}

String _describeDragData() {
final res = StringBuffer();

for (final String f in _files ?? []) {
res.writeln('${p.basename(f)},');
}
for (final uri in _uris ?? []) {
res.writeln('$uri');
}
final custom = _customData;
if (custom != null) {
if (res.isNotEmpty) {
res.writeln();
}
res.writeln('Custom Data:');
res.writeln('$custom');
}
return res.toString();
}

List<Uri> _uris;
List<String> _files;
Map _customData;

bool dropping = false;
}
2 changes: 1 addition & 1 deletion lib/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Config {
static String curDevicesSerial = '';
static String historyIp = '';
static bool conWhenScan = true;
static String version = '1.2.6';
static String version = '1.2.7';
// 224.0.0.1 这个组播ip可以实现手机热点电脑,电脑发送组播,手机接收到
// static InternetAddress multicastAddress = InternetAddress('224.0.0.1');
// flutter package名,因为这个会影响assets的路径
Expand Down

0 comments on commit 5e3a4e4

Please sign in to comment.