mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-07 06:01:28 +03:00
add local/remote file manager
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/pages/chat_page.dart';
|
||||
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
@@ -55,21 +54,11 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
getSearchBarUI(),
|
||||
Container(height: 12),
|
||||
getPeers(),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => FileManagerPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text("File")),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
toggleChatOverlay();
|
||||
},
|
||||
child: Text("Chat"))
|
||||
// ElevatedButton(
|
||||
// onPressed: () {
|
||||
// toggleChatOverlay();
|
||||
// },
|
||||
// child: Text("Chat Debug"))
|
||||
]),
|
||||
);
|
||||
}
|
||||
@@ -79,15 +68,24 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
connect(id);
|
||||
}
|
||||
|
||||
void connect(String id) {
|
||||
void connect(String id,{bool isFileTransfer = false}) {
|
||||
if (id == '') return;
|
||||
id = id.replaceAll(' ', '');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => RemotePage(id: id),
|
||||
),
|
||||
);
|
||||
if (isFileTransfer) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => FileManagerPage(id: id),
|
||||
),
|
||||
);
|
||||
}else{
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => RemotePage(id: id),
|
||||
),
|
||||
);
|
||||
}
|
||||
FocusScopeNode currentFocus = FocusScope.of(context);
|
||||
if (!currentFocus.hasPrimaryFocus) {
|
||||
currentFocus.unfocus();
|
||||
@@ -262,6 +260,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
items: [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Remove')), value: 'remove'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('File transfer')), value: 'file'),
|
||||
],
|
||||
elevation: 8,
|
||||
);
|
||||
@@ -270,6 +270,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
|
||||
() async {
|
||||
removePreference(id);
|
||||
}();
|
||||
}else if (value == 'file') {
|
||||
connect(id,isFileTransfer: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,145 @@
|
||||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
import 'package:file_manager/file_manager.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final FileManagerController controller = FileManagerController();
|
||||
import '../common.dart';
|
||||
import '../models/model.dart';
|
||||
import '../widgets/dialog.dart';
|
||||
|
||||
class FileManagerPage extends StatefulWidget {
|
||||
FileManagerPage({Key? key, required this.id}) : super(key: key);
|
||||
final String id;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _FileManagerPageState();
|
||||
}
|
||||
|
||||
class _FileManagerPageState extends State<FileManagerPage> {
|
||||
final _localFileModel = FileManagerController();
|
||||
final _remoteFileModel = FFI.remoteFileModel;
|
||||
Timer? _interval;
|
||||
Timer? _timer;
|
||||
var _reconnects = 1;
|
||||
var _isLocal = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
showLoading(translate('Connecting...'));
|
||||
FFI.connect(widget.id, isFileTransfer: true);
|
||||
_interval = Timer.periodic(Duration(milliseconds: 30),
|
||||
(timer) => FFI.ffiModel.update(widget.id, context, handleMsgBox));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_localFileModel.dispose();
|
||||
_remoteFileModel.dispose();
|
||||
_interval?.cancel();
|
||||
FFI.close();
|
||||
EasyLoading.dismiss();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
class FileManagerPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: FileManager(
|
||||
controller: controller,
|
||||
builder: (context, snapshot) {
|
||||
final List<FileSystemEntity> entities = snapshot;
|
||||
return ListView.builder(
|
||||
itemCount: entities.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: FileManager.isFile(entities[index])
|
||||
? Icon(Icons.feed_outlined)
|
||||
: Icon(Icons.folder),
|
||||
title: Text(FileManager.basename(entities[index])),
|
||||
onTap: () {
|
||||
if (FileManager.isDirectory(entities[index])) {
|
||||
controller.openDirectory(entities[index]); // open directory
|
||||
} else {
|
||||
// Perform file-related tasks.
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
));
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _remoteFileModel,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: Row(children: [
|
||||
IconButton(icon: Icon(Icons.arrow_back), onPressed: goBack),
|
||||
IconButton(icon: Icon(Icons.close), onPressed: clientClose),
|
||||
]),
|
||||
leadingWidth: 200,
|
||||
centerTitle: true,
|
||||
title: Text(translate(_isLocal ? "Local" : "Remote")),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.change_circle),
|
||||
onPressed: () => setState(() {
|
||||
_isLocal = !_isLocal;
|
||||
})),
|
||||
],
|
||||
),
|
||||
body:
|
||||
Consumer<RemoteFileModel>(builder: (context, remoteModel, child) {
|
||||
return FileManager(
|
||||
controller: _localFileModel,
|
||||
builder: (context, localSnapshot) {
|
||||
final snapshot = _isLocal
|
||||
? localSnapshot
|
||||
: remoteModel.currentRemoteDir.entries;
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: FileManager.isFile(snapshot[index])
|
||||
? Icon(Icons.feed_outlined)
|
||||
: Icon(Icons.folder),
|
||||
title: Text(FileManager.basename(snapshot[index])),
|
||||
onTap: () {
|
||||
if (FileManager.isDirectory(snapshot[index])) {
|
||||
_isLocal
|
||||
? _localFileModel
|
||||
.openDirectory(snapshot[index])
|
||||
: readRemoteDir(
|
||||
snapshot[index].path); // open directory
|
||||
} else {
|
||||
// Perform file-related tasks.
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
goBack() {
|
||||
if (_isLocal) {
|
||||
_localFileModel.goToParentDirectory();
|
||||
} else {
|
||||
_remoteFileModel.goToParentDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
void readRemoteDir(String path) {
|
||||
FFI.setByName("read_remote_dir", path);
|
||||
}
|
||||
|
||||
void handleMsgBox(Map<String, dynamic> evt, String id) {
|
||||
var type = evt['type'];
|
||||
var title = evt['title'];
|
||||
var text = evt['text'];
|
||||
if (type == 're-input-password') {
|
||||
wrongPasswordDialog(id);
|
||||
} else if (type == 'input-password') {
|
||||
enterPasswordDialog(id);
|
||||
} else {
|
||||
var hasRetry = evt['hasRetry'] == 'true';
|
||||
print(evt);
|
||||
showMsgBox(type, title, text, hasRetry);
|
||||
}
|
||||
}
|
||||
|
||||
void showMsgBox(String type, String title, String text, bool hasRetry) {
|
||||
msgBox(type, title, text);
|
||||
if (hasRetry) {
|
||||
_timer?.cancel();
|
||||
_timer = Timer(Duration(seconds: _reconnects), () {
|
||||
FFI.reconnect();
|
||||
showLoading(translate('Connecting...'));
|
||||
});
|
||||
_reconnects *= 2;
|
||||
} else {
|
||||
_reconnects = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/main.dart';
|
||||
import 'package:flutter_hbb/widgets/gesture_help.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -11,6 +10,7 @@ import 'package:wakelock/wakelock.dart';
|
||||
import '../common.dart';
|
||||
import '../gestures.dart';
|
||||
import '../models/model.dart';
|
||||
import '../widgets/dialog.dart';
|
||||
import 'chat_page.dart';
|
||||
|
||||
final initText = '\1' * 1024;
|
||||
@@ -228,7 +228,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
final showActionButton = !_showBar || hideKeyboard;
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
close();
|
||||
clientClose();
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
@@ -279,7 +279,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
close();
|
||||
clientClose();
|
||||
},
|
||||
)
|
||||
] +
|
||||
@@ -585,10 +585,6 @@ class _RemotePageState extends State<RemotePage> {
|
||||
}));
|
||||
}
|
||||
|
||||
void close() {
|
||||
msgBox('', 'Close', 'Are you sure to close the connection?');
|
||||
}
|
||||
|
||||
Widget getHelpTools() {
|
||||
final keyboard = isKeyboardShown();
|
||||
if (!keyboard) {
|
||||
@@ -783,74 +779,7 @@ class ImagePainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
void enterPasswordDialog(String id) {
|
||||
final controller = TextEditingController();
|
||||
var remember = FFI.getByName('remember', id) == 'true';
|
||||
if (globalKey.currentContext == null) return;
|
||||
showAlertDialog((setState) => Tuple3(
|
||||
Text(translate('Password Required')),
|
||||
Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
PasswordWidget(controller: controller),
|
||||
CheckboxListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
dense: true,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
title: Text(
|
||||
translate('Remember password'),
|
||||
),
|
||||
value: remember,
|
||||
onChanged: (v) {
|
||||
if (v != null) {
|
||||
setState(() => remember = v);
|
||||
}
|
||||
},
|
||||
),
|
||||
]),
|
||||
[
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
DialogManager.reset();
|
||||
Navigator.pop(globalKey.currentContext!);
|
||||
},
|
||||
child: Text(translate('Cancel')),
|
||||
),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
var text = controller.text.trim();
|
||||
if (text == '') return;
|
||||
FFI.login(text, remember);
|
||||
DialogManager.reset();
|
||||
showLoading(translate('Logging in...'));
|
||||
},
|
||||
child: Text(translate('OK')),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
void wrongPasswordDialog(String id) {
|
||||
if (globalKey.currentContext == null) return;
|
||||
showAlertDialog((_) => Tuple3(Text(translate('Wrong Password')),
|
||||
Text(translate('Do you want to enter again?')), [
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
DialogManager.reset();
|
||||
Navigator.pop(globalKey.currentContext!);
|
||||
},
|
||||
child: Text(translate('Cancel')),
|
||||
),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
enterPasswordDialog(id);
|
||||
},
|
||||
child: Text(translate('Retry')),
|
||||
),
|
||||
]));
|
||||
}
|
||||
|
||||
CheckboxListTile getToggle(
|
||||
void Function(void Function()) setState, option, name) {
|
||||
|
||||
Reference in New Issue
Block a user