mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
update dialog,use flutter_smart_dialog
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:path/path.dart' as Path;
|
||||
|
||||
import 'model.dart';
|
||||
@@ -176,8 +176,7 @@ class FileModel extends ChangeNotifier {
|
||||
}
|
||||
|
||||
onClose() {
|
||||
DialogManager.reset();
|
||||
EasyLoading.dismiss();
|
||||
SmartDialog.dismiss();
|
||||
|
||||
// save config
|
||||
Map<String, String> msg = Map();
|
||||
@@ -289,7 +288,7 @@ class FileModel extends ChangeNotifier {
|
||||
fd.path = item.path;
|
||||
}
|
||||
fd.format(isWindows);
|
||||
EasyLoading.dismiss();
|
||||
SmartDialog.dismiss();
|
||||
if (fd.entries.isEmpty) {
|
||||
final confirm = await showRemoveDialog(
|
||||
translate(
|
||||
@@ -346,49 +345,50 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
Future<bool?> showRemoveDialog(
|
||||
String title, String content, bool showCheckbox) async {
|
||||
return await DialogManager.show<bool>((setState, Function(bool v) close) =>
|
||||
CustomAlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.red),
|
||||
SizedBox(width: 20),
|
||||
Text(title)
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(content),
|
||||
SizedBox(height: 5),
|
||||
Text(translate("This is irreversible!"),
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
showCheckbox
|
||||
? CheckboxListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
dense: true,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
title: Text(
|
||||
translate("Do this for all conflicts"),
|
||||
),
|
||||
value: removeCheckboxRemember,
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
setState(() => removeCheckboxRemember = v);
|
||||
},
|
||||
)
|
||||
: SizedBox.shrink()
|
||||
return await DialogManager.show<bool>(
|
||||
(setState, Function(bool v) close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: Colors.red),
|
||||
SizedBox(width: 20),
|
||||
Text(title)
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(content),
|
||||
SizedBox(height: 5),
|
||||
Text(translate("This is irreversible!"),
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
showCheckbox
|
||||
? CheckboxListTile(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
dense: true,
|
||||
controlAffinity: ListTileControlAffinity.leading,
|
||||
title: Text(
|
||||
translate("Do this for all conflicts"),
|
||||
),
|
||||
value: removeCheckboxRemember,
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
setState(() => removeCheckboxRemember = v);
|
||||
},
|
||||
)
|
||||
: SizedBox.shrink()
|
||||
]),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () => close(false),
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () => close(true),
|
||||
child: Text(translate("OK"))),
|
||||
]),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () => close(false),
|
||||
child: Text(translate("Cancel"))),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () => close(true),
|
||||
child: Text(translate("OK"))),
|
||||
]));
|
||||
useAnimation: false);
|
||||
}
|
||||
|
||||
sendRemoveFile(String path, int fileNum, bool isLocal) {
|
||||
@@ -526,7 +526,7 @@ class FileFetcher {
|
||||
final fd = FileDirectory.fromJson(jsonDecode(msg));
|
||||
if (fd.id > 0) {
|
||||
// fd.id > 0 is result for read recursive
|
||||
// TODO later,will be better if every fetch use ID,so that there will only one task map for read and recursive read
|
||||
// to-do later,will be better if every fetch use ID,so that there will only one task map for read and recursive read
|
||||
tasks = readRecursiveTasks;
|
||||
final completer = tasks.remove(fd.id);
|
||||
completer?.complete(fd);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/models/chat_model.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'dart:math';
|
||||
import 'dart:convert';
|
||||
@@ -159,7 +159,7 @@ class FfiModel with ChangeNotifier {
|
||||
if (rgba != null) {
|
||||
if (_waitForImage) {
|
||||
_waitForImage = false;
|
||||
EasyLoading.dismiss();
|
||||
SmartDialog.dismiss();
|
||||
}
|
||||
_decoding = true;
|
||||
final pid = FFI.id;
|
||||
@@ -221,8 +221,7 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
void handlePeerInfo(Map<String, dynamic> evt) {
|
||||
EasyLoading.dismiss();
|
||||
DialogManager.reset();
|
||||
SmartDialog.dismiss();
|
||||
_pi.version = evt['version'];
|
||||
_pi.username = evt['username'];
|
||||
_pi.hostname = evt['hostname'];
|
||||
@@ -484,16 +483,11 @@ class CursorModel with ChangeNotifier {
|
||||
void updatePan(double dx, double dy, bool touchMode) {
|
||||
if (FFI.imageModel.image == null) return;
|
||||
if (touchMode) {
|
||||
if (true) {
|
||||
final scale = FFI.canvasModel.scale;
|
||||
_x += dx / scale;
|
||||
_y += dy / scale;
|
||||
FFI.moveMouse(_x, _y);
|
||||
notifyListeners();
|
||||
} else {
|
||||
FFI.canvasModel.panX(dx);
|
||||
FFI.canvasModel.panY(dy);
|
||||
}
|
||||
final scale = FFI.canvasModel.scale;
|
||||
_x += dx / scale;
|
||||
_y += dy / scale;
|
||||
FFI.moveMouse(_x, _y);
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
final scale = FFI.canvasModel.scale;
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../common.dart';
|
||||
import '../pages/server_page.dart';
|
||||
import 'model.dart';
|
||||
|
||||
const loginDialogTag = "LOGIN";
|
||||
final _emptyIdShow = translate("Generating ...");
|
||||
|
||||
class ServerModel with ChangeNotifier {
|
||||
@@ -306,70 +307,89 @@ class ServerModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
loginRequest(Map<String, dynamic> evt) {
|
||||
void loginRequest(Map<String, dynamic> evt) {
|
||||
try {
|
||||
final client = Client.fromJson(jsonDecode(evt["client"]));
|
||||
final Map<String, dynamic> response = Map();
|
||||
response["id"] = client.id;
|
||||
DialogManager.show(
|
||||
(setState, close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(translate(client.isFileTransfer
|
||||
? "File Connection"
|
||||
: "Screen Connection")),
|
||||
IconButton(onPressed: close, icon: Icon(Icons.close))
|
||||
]),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("Do you accept?")),
|
||||
clientInfo(client),
|
||||
Text(
|
||||
translate("android_new_connection_tip"),
|
||||
style: TextStyle(color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(translate("Dismiss")),
|
||||
onPressed: () {
|
||||
response["res"] = false;
|
||||
FFI.setByName("login_res", jsonEncode(response));
|
||||
FFI.invokeMethod("cancel_notification", client.id);
|
||||
close();
|
||||
}),
|
||||
ElevatedButton(
|
||||
child: Text(translate("Accept")),
|
||||
onPressed: () async {
|
||||
response["res"] = true;
|
||||
FFI.setByName("login_res", jsonEncode(response));
|
||||
if (!client.isFileTransfer) {
|
||||
FFI.invokeMethod("start_capture");
|
||||
}
|
||||
FFI.invokeMethod("cancel_notification", client.id);
|
||||
_clients[client.id] = client;
|
||||
notifyListeners();
|
||||
close();
|
||||
}),
|
||||
],
|
||||
onWillPop: () async => true,
|
||||
),
|
||||
barrierDismissible: true);
|
||||
if (_clients.containsKey(client.id)) {
|
||||
return;
|
||||
}
|
||||
_clients[client.id] = client;
|
||||
notifyListeners();
|
||||
showLoginDialog(client);
|
||||
} catch (e) {
|
||||
debugPrint("loginRequest failed,error:$e");
|
||||
debugPrint("Failed to call loginRequest,error:$e");
|
||||
}
|
||||
}
|
||||
|
||||
void showLoginDialog(Client client) {
|
||||
DialogManager.show(
|
||||
(setState, close) => CustomAlertDialog(
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(translate(client.isFileTransfer
|
||||
? "File Connection"
|
||||
: "Screen Connection")),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
close();
|
||||
},
|
||||
icon: Icon(Icons.close))
|
||||
]),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("Do you accept?")),
|
||||
clientInfo(client),
|
||||
Text(
|
||||
translate("android_new_connection_tip"),
|
||||
style: TextStyle(color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(translate("Dismiss")),
|
||||
onPressed: () {
|
||||
sendLoginResponse(client, false);
|
||||
close();
|
||||
}),
|
||||
ElevatedButton(
|
||||
child: Text(translate("Accept")),
|
||||
onPressed: () {
|
||||
sendLoginResponse(client, true);
|
||||
close();
|
||||
}),
|
||||
],
|
||||
),
|
||||
tag: getLoginDialogTag(client.id));
|
||||
}
|
||||
|
||||
void sendLoginResponse(Client client, bool res) {
|
||||
final Map<String, dynamic> response = Map();
|
||||
response["id"] = client.id;
|
||||
response["res"] = res;
|
||||
if (res) {
|
||||
FFI.setByName("login_res", jsonEncode(response));
|
||||
if (!client.isFileTransfer) {
|
||||
FFI.invokeMethod("start_capture");
|
||||
}
|
||||
FFI.invokeMethod("cancel_notification", client.id);
|
||||
_clients[client.id]?.authorized = true;
|
||||
notifyListeners();
|
||||
} else {
|
||||
FFI.setByName("login_res", jsonEncode(response));
|
||||
FFI.invokeMethod("cancel_notification", client.id);
|
||||
_clients.remove(client.id);
|
||||
}
|
||||
}
|
||||
|
||||
void onClientAuthorized(Map<String, dynamic> evt) {
|
||||
try {
|
||||
final client = Client.fromJson(jsonDecode(evt['client']));
|
||||
// reset the login dialog, to-do,it will close any showing dialog
|
||||
DialogManager.reset();
|
||||
DialogManager.dismissByTag(getLoginDialogTag(client.id));
|
||||
_clients[client.id] = client;
|
||||
notifyListeners();
|
||||
} catch (e) {}
|
||||
@@ -380,9 +400,7 @@ class ServerModel with ChangeNotifier {
|
||||
final id = int.parse(evt['id'] as String);
|
||||
if (_clients.containsKey(id)) {
|
||||
_clients.remove(id);
|
||||
} else {
|
||||
// reset the login dialog, to-do,it will close any showing dialog
|
||||
DialogManager.reset();
|
||||
DialogManager.dismissByTag(getLoginDialogTag(id));
|
||||
FFI.invokeMethod("cancel_notification", id);
|
||||
}
|
||||
notifyListeners();
|
||||
@@ -442,39 +460,31 @@ class Client {
|
||||
}
|
||||
}
|
||||
|
||||
showInputWarnAlert() async {
|
||||
if (globalKey.currentContext == null) return;
|
||||
DialogManager.reset();
|
||||
await showDialog<bool>(
|
||||
context: globalKey.currentContext!,
|
||||
builder: (alertContext) {
|
||||
DialogManager.register(alertContext);
|
||||
return AlertDialog(
|
||||
title: Text(translate("How to get Android input permission?")),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(translate(translate("android_input_permission_tip1"))),
|
||||
SizedBox(height: 10),
|
||||
Text(translate(translate("android_input_permission_tip2"))),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text(translate("Cancel")),
|
||||
onPressed: () {
|
||||
DialogManager.reset();
|
||||
}),
|
||||
ElevatedButton(
|
||||
child: Text(translate("Open System Setting")),
|
||||
onPressed: () {
|
||||
FFI.serverModel.initInput();
|
||||
DialogManager.reset();
|
||||
}),
|
||||
String getLoginDialogTag(int id) {
|
||||
return loginDialogTag + id.toString();
|
||||
}
|
||||
|
||||
showInputWarnAlert() {
|
||||
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||
title: Text(translate("How to get Android input permission?")),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(translate(translate("android_input_permission_tip1"))),
|
||||
SizedBox(height: 10),
|
||||
Text(translate(translate("android_input_permission_tip2"))),
|
||||
],
|
||||
);
|
||||
});
|
||||
DialogManager.drop();
|
||||
),
|
||||
actions: [
|
||||
TextButton(child: Text(translate("Cancel")), onPressed: close),
|
||||
ElevatedButton(
|
||||
child: Text(translate("Open System Setting")),
|
||||
onPressed: () {
|
||||
FFI.serverModel.initInput();
|
||||
close();
|
||||
}),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
class PermissionManager {
|
||||
|
||||
Reference in New Issue
Block a user