rustdesk/flutter/lib/models/server_model.dart

807 lines
23 KiB
Dart
Raw Normal View History

import 'dart:async';
2022-03-19 23:28:29 +08:00
import 'dart:convert';
2022-03-19 23:28:29 +08:00
import 'package:flutter/material.dart';
2023-02-27 23:41:09 +08:00
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/main.dart';
import 'package:flutter_hbb/models/chat_model.dart';
import 'package:flutter_hbb/models/platform_model.dart';
import 'package:get/get.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
2022-10-26 20:39:28 +08:00
import 'package:window_manager/window_manager.dart';
2022-03-19 23:28:29 +08:00
import '../common.dart';
import '../common/formatter/id_formatter.dart';
import '../desktop/pages/server_page.dart' as desktop;
import '../desktop/widgets/tabbar_widget.dart';
2022-05-24 23:33:00 +08:00
import '../mobile/pages/server_page.dart';
import 'model.dart';
2022-03-19 23:28:29 +08:00
2022-09-29 13:07:20 +08:00
const kLoginDialogTag = "LOGIN";
2022-07-29 18:34:25 +08:00
const kUseTemporaryPassword = "use-temporary-password";
const kUsePermanentPassword = "use-permanent-password";
const kUseBothPasswords = "use-both-passwords";
2022-03-19 23:28:29 +08:00
class ServerModel with ChangeNotifier {
2022-04-17 11:34:46 +08:00
bool _isStart = false; // Android MainService status
2022-03-19 23:28:29 +08:00
bool _mediaOk = false;
bool _inputOk = false;
bool _audioOk = false;
bool _fileOk = false;
bool _showElevation = false;
bool hideCm = false;
int _connectStatus = 0; // Rendezvous Server status
2022-07-29 18:34:25 +08:00
String _verificationMethod = "";
String _temporaryPasswordLength = "";
String _approveMode = "";
int _zeroClientLengthCounter = 0;
2022-04-17 11:34:46 +08:00
late String _emptyIdShow;
late final IDTextEditingController _serverId;
final _serverPasswd =
TextEditingController(text: translate("Generating ..."));
final tabController = DesktopTabController(tabType: DesktopTabType.cm);
final List<Client> _clients = [];
2022-03-19 23:28:29 +08:00
2022-10-26 20:39:28 +08:00
Timer? cmHiddenTimer;
bool get isStart => _isStart;
2022-03-19 23:28:29 +08:00
bool get mediaOk => _mediaOk;
bool get inputOk => _inputOk;
2022-03-22 21:47:42 +08:00
bool get audioOk => _audioOk;
bool get fileOk => _fileOk;
bool get showElevation => _showElevation;
int get connectStatus => _connectStatus;
String get verificationMethod {
final index = [
kUseTemporaryPassword,
kUsePermanentPassword,
kUseBothPasswords
].indexOf(_verificationMethod);
if (index < 0) {
return kUseBothPasswords;
}
return _verificationMethod;
}
String get approveMode => _approveMode;
setVerificationMethod(String method) async {
await bind.mainSetOption(key: "verification-method", value: method);
/*
if (method != kUsePermanentPassword) {
await bind.mainSetOption(
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
}
*/
}
String get temporaryPasswordLength {
final lengthIndex = ["6", "8", "10"].indexOf(_temporaryPasswordLength);
if (lengthIndex < 0) {
return "6";
}
return _temporaryPasswordLength;
}
setTemporaryPasswordLength(String length) async {
await bind.mainSetOption(key: "temporary-password-length", value: length);
}
2022-07-29 18:34:25 +08:00
setApproveMode(String mode) async {
await bind.mainSetOption(key: 'approve-mode', value: mode);
/*
if (mode != 'password') {
await bind.mainSetOption(
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
}
*/
}
TextEditingController get serverId => _serverId;
TextEditingController get serverPasswd => _serverPasswd;
List<Client> get clients => _clients;
2022-03-19 23:28:29 +08:00
final controller = ScrollController();
WeakReference<FFI> parent;
ServerModel(this.parent) {
_emptyIdShow = translate("Generating ...");
_serverId = IDTextEditingController(text: _emptyIdShow);
2022-04-17 11:34:46 +08:00
/*
// initital _hideCm at startup
final verificationMethod =
bind.mainGetOptionSync(key: "verification-method");
final approveMode = bind.mainGetOptionSync(key: 'approve-mode');
_hideCm = option2bool(
'allow-hide-cm', bind.mainGetOptionSync(key: 'allow-hide-cm'));
if (!(approveMode == 'password' &&
verificationMethod == kUsePermanentPassword)) {
_hideCm = false;
}
*/
timerCallback() async {
final connectionStatus =
jsonDecode(await bind.mainGetConnectStatus()) as Map<String, dynamic>;
final statusNum = connectionStatus['status_num'] as int;
if (statusNum != _connectStatus) {
_connectStatus = statusNum;
notifyListeners();
}
if (desktopType == DesktopType.cm) {
final res = await bind.cmCheckClientsLength(length: _clients.length);
if (res != null) {
debugPrint("clients not match!");
updateClientState(res);
} else {
if (_clients.isEmpty) {
hideCmWindow();
if (_zeroClientLengthCounter++ == 12) {
// 6 second
windowManager.close();
}
} else {
_zeroClientLengthCounter = 0;
if (!hideCm) showCmWindow();
}
}
}
2022-07-29 18:34:25 +08:00
2022-07-29 22:07:45 +08:00
updatePasswordModel();
}
if (!isTest) {
Future.delayed(Duration.zero, () async {
if (await bind.optionSynced()) {
await timerCallback();
}
});
Timer.periodic(Duration(milliseconds: 500), (timer) async {
await timerCallback();
});
}
2022-03-22 21:47:42 +08:00
}
/// 1. check android permission
/// 2. check config
/// audio true by default (if permission on) (false default < Android 10)
/// file true by default (if permission on)
checkAndroidPermission() async {
// audio
2023-02-27 23:41:09 +08:00
if (androidVersion < 30 ||
!await AndroidPermissionManager.check(kRecordAudio)) {
_audioOk = false;
bind.mainSetOption(key: "enable-audio", value: "N");
} else {
final audioOption = await bind.mainGetOption(key: 'enable-audio');
_audioOk = audioOption.isEmpty;
}
// file
2023-02-27 23:41:09 +08:00
if (!await AndroidPermissionManager.check(kManageExternalStorage)) {
_fileOk = false;
bind.mainSetOption(key: "enable-file-transfer", value: "N");
} else {
final fileOption = await bind.mainGetOption(key: 'enable-file-transfer');
_fileOk = fileOption.isEmpty;
}
notifyListeners();
}
updatePasswordModel() async {
2022-07-29 22:07:45 +08:00
var update = false;
final temporaryPassword = await bind.mainGetTemporaryPassword();
final verificationMethod =
await bind.mainGetOption(key: "verification-method");
final temporaryPasswordLength =
await bind.mainGetOption(key: "temporary-password-length");
final approveMode = await bind.mainGetOption(key: 'approve-mode');
/*
var hideCm = option2bool(
'allow-hide-cm', await bind.mainGetOption(key: 'allow-hide-cm'));
if (!(approveMode == 'password' &&
verificationMethod == kUsePermanentPassword)) {
hideCm = false;
}
*/
if (_approveMode != approveMode) {
_approveMode = approveMode;
update = true;
}
var stopped = option2bool(
"stop-service", await bind.mainGetOption(key: "stop-service"));
final oldPwdText = _serverPasswd.text;
if (stopped ||
verificationMethod == kUsePermanentPassword ||
_approveMode == 'click') {
_serverPasswd.text = '-';
} else {
if (_serverPasswd.text != temporaryPassword &&
temporaryPassword.isNotEmpty) {
_serverPasswd.text = temporaryPassword;
}
}
if (oldPwdText != _serverPasswd.text) {
2022-07-29 22:07:45 +08:00
update = true;
}
if (_verificationMethod != verificationMethod) {
_verificationMethod = verificationMethod;
update = true;
}
if (_temporaryPasswordLength != temporaryPasswordLength) {
if (_temporaryPasswordLength.isNotEmpty) {
bind.mainUpdateTemporaryPassword();
}
_temporaryPasswordLength = temporaryPasswordLength;
update = true;
}
/*
if (_hideCm != hideCm) {
_hideCm = hideCm;
if (desktopType == DesktopType.cm) {
if (hideCm) {
await hideCmWindow();
} else {
await showCmWindow();
}
}
update = true;
}
*/
2022-07-29 22:07:45 +08:00
if (update) {
notifyListeners();
}
2022-03-22 21:47:42 +08:00
}
toggleAudio() async {
if (clients.isNotEmpty) {
await showClientsMayNotBeChangedAlert(parent.target);
}
2023-02-27 23:41:09 +08:00
if (!_audioOk && !await AndroidPermissionManager.check(kRecordAudio)) {
final res = await AndroidPermissionManager.request(kRecordAudio);
2022-04-13 15:33:23 +08:00
if (!res) {
showToast(translate('Failed'));
return;
}
}
2022-03-22 21:47:42 +08:00
_audioOk = !_audioOk;
bind.mainSetOption(key: "enable-audio", value: _audioOk ? '' : 'N');
2022-03-22 21:47:42 +08:00
notifyListeners();
}
toggleFile() async {
if (clients.isNotEmpty) {
await showClientsMayNotBeChangedAlert(parent.target);
}
2023-02-27 23:41:09 +08:00
if (!_fileOk &&
!await AndroidPermissionManager.check(kManageExternalStorage)) {
final res =
await AndroidPermissionManager.request(kManageExternalStorage);
2022-04-13 15:33:23 +08:00
if (!res) {
showToast(translate('Failed'));
return;
}
}
_fileOk = !_fileOk;
bind.mainSetOption(key: "enable-file-transfer", value: _fileOk ? '' : 'N');
notifyListeners();
}
toggleInput() async {
if (clients.isNotEmpty) {
await showClientsMayNotBeChangedAlert(parent.target);
}
2022-04-13 15:33:23 +08:00
if (_inputOk) {
parent.target?.invokeMethod("stop_input");
2023-03-07 10:21:23 +08:00
bind.mainSetOption(key: "enable-keyboard", value: 'N');
2022-04-13 15:33:23 +08:00
} else {
if (parent.target != null) {
2023-03-07 10:21:23 +08:00
/// the result of toggle-on depends on user actions in the settings page.
/// handle result, see [ServerModel.changeStatue]
showInputWarnAlert(parent.target!);
}
2022-03-22 21:47:42 +08:00
}
}
2022-05-29 04:39:12 +08:00
/// Toggle the screen sharing service.
2022-03-22 21:47:42 +08:00
toggleService() async {
2022-04-13 15:33:23 +08:00
if (_isStart) {
2023-05-20 21:12:52 +08:00
final res = await parent.target?.dialogManager
.show<bool>((setState, close, context) {
submit() => close(true);
return CustomAlertDialog(
title: Row(children: [
const Icon(Icons.warning_amber_sharp,
color: Colors.redAccent, size: 28),
const SizedBox(width: 10),
Text(translate("Warning")),
]),
content: Text(translate("android_stop_service_tip")),
actions: [
TextButton(onPressed: close, child: Text(translate("Cancel"))),
TextButton(onPressed: submit, child: Text(translate("OK"))),
],
onSubmit: submit,
onCancel: close,
);
});
2022-04-13 15:33:23 +08:00
if (res == true) {
2022-03-22 21:47:42 +08:00
stopService();
}
2022-04-13 15:33:23 +08:00
} else {
2023-05-20 21:12:52 +08:00
final res = await parent.target?.dialogManager
.show<bool>((setState, close, context) {
submit() => close(true);
return CustomAlertDialog(
title: Row(children: [
const Icon(Icons.warning_amber_sharp,
color: Colors.redAccent, size: 28),
const SizedBox(width: 10),
Text(translate("Warning")),
]),
content: Text(translate("android_service_will_start_tip")),
actions: [
dialogButton("Cancel", onPressed: close, isOutline: true),
dialogButton("OK", onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
2022-04-13 15:33:23 +08:00
if (res == true) {
2022-03-22 21:47:42 +08:00
startService();
}
}
}
2022-05-29 04:39:12 +08:00
/// Start the screen sharing service.
Future<void> startService() async {
_isStart = true;
notifyListeners();
parent.target?.ffiModel.updateEventListener(parent.target!.sessionId, "");
await parent.target?.invokeMethod("init_service");
2023-01-26 11:05:23 +08:00
// ugly is here, because for desktop, below is useless
await bind.mainStartService();
updateClientState();
if (isAndroid) {
WakelockPlus.enable();
}
}
2022-05-29 04:39:12 +08:00
/// Stop the screen sharing service.
Future<void> stopService() async {
_isStart = false;
2022-08-12 18:42:02 +08:00
closeAll();
await parent.target?.invokeMethod("stop_service");
await bind.mainStopService();
notifyListeners();
if (!isLinux) {
// current linux is not supported
WakelockPlus.disable();
}
}
2022-07-29 18:34:25 +08:00
Future<bool> setPermanentPassword(String newPW) async {
await bind.mainSetPermanentPassword(password: newPW);
2022-03-30 23:09:19 +08:00
await Future.delayed(Duration(milliseconds: 500));
final pw = await bind.mainGetPermanentPassword();
2022-07-29 18:34:25 +08:00
if (newPW == pw) {
return true;
2022-04-13 15:33:23 +08:00
} else {
2022-07-29 18:34:25 +08:00
return false;
2022-03-30 23:09:19 +08:00
}
}
2022-11-29 22:36:35 +08:00
fetchID() async {
final id = await bind.mainGetMyId();
if (id != _serverId.id) {
_serverId.id = id;
notifyListeners();
}
}
2022-03-19 23:28:29 +08:00
changeStatue(String name, bool value) {
debugPrint("changeStatue value $value");
2022-03-19 23:28:29 +08:00
switch (name) {
case "media":
_mediaOk = value;
2022-04-13 15:33:23 +08:00
if (value && !_isStart) {
startService();
}
2022-03-19 23:28:29 +08:00
break;
case "input":
2022-04-13 15:33:23 +08:00
if (_inputOk != value) {
bind.mainSetOption(key: "enable-keyboard", value: value ? '' : 'N');
2022-03-22 21:47:42 +08:00
}
2022-03-19 23:28:29 +08:00
_inputOk = value;
break;
default:
return;
}
notifyListeners();
}
// force
updateClientState([String? json]) async {
2022-10-20 22:05:34 +08:00
if (isTest) return;
var res = await bind.cmGetClientsState();
List<dynamic> clientsJson;
2022-03-19 23:28:29 +08:00
try {
clientsJson = jsonDecode(res);
} catch (e) {
debugPrint("Failed to decode clientsJson: '$res', error $e");
return;
}
final oldClientLenght = _clients.length;
_clients.clear();
tabController.state.value.tabs.clear();
for (var clientJson in clientsJson) {
try {
final client = Client.fromJson(clientJson);
_clients.add(client);
2022-10-26 20:39:28 +08:00
_addTab(client);
} catch (e) {
debugPrint("Failed to decode clientJson '$clientJson', error $e");
2022-03-25 16:34:27 +08:00
}
}
if (desktopType == DesktopType.cm) {
if (_clients.isEmpty) {
hideCmWindow();
} else if (!hideCm) {
showCmWindow();
}
}
if (_clients.length != oldClientLenght) {
notifyListeners();
}
2022-03-19 23:28:29 +08:00
}
void addConnection(Map<String, dynamic> evt) {
try {
2022-03-19 23:28:29 +08:00
final client = Client.fromJson(jsonDecode(evt["client"]));
if (client.authorized) {
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(client.id));
final index = _clients.indexWhere((c) => c.id == client.id);
if (index < 0) {
_clients.add(client);
} else {
_clients[index].authorized = true;
}
} else {
if (_clients.any((c) => c.id == client.id)) {
return;
}
_clients.add(client);
2022-04-19 13:07:45 +08:00
}
2022-10-26 20:39:28 +08:00
_addTab(client);
// remove disconnected
final index_disconnected = _clients
.indexWhere((c) => c.disconnected && c.peerId == client.peerId);
if (index_disconnected >= 0) {
_clients.removeAt(index_disconnected);
tabController.remove(index_disconnected);
}
if (desktopType == DesktopType.cm && !hideCm) {
showCmWindow();
}
scrollToBottom();
notifyListeners();
if (isAndroid && !client.authorized) showLoginDialog(client);
2022-04-19 13:07:45 +08:00
} catch (e) {
debugPrint("Failed to call loginRequest,error:$e");
}
}
2022-10-26 20:39:28 +08:00
void _addTab(Client client) {
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
onTap: () {},
page: desktop.buildConnectionCard(client)));
2022-10-26 20:39:28 +08:00
Future.delayed(Duration.zero, () async {
if (!hideCm) windowOnTop(null);
2022-10-26 20:39:28 +08:00
});
// Only do the hidden task when on Desktop.
if (client.authorized && isDesktop) {
2022-10-26 20:39:28 +08:00
cmHiddenTimer = Timer(const Duration(seconds: 3), () {
if (!hideCm) windowManager.minimize();
2022-10-26 20:39:28 +08:00
cmHiddenTimer = null;
});
}
parent.target?.chatModel
.updateConnIdOfKey(MessageKey(client.peerId, client.id));
2022-10-26 20:39:28 +08:00
}
2022-04-19 13:07:45 +08:00
void showLoginDialog(Client client) {
2023-05-08 12:34:19 +08:00
parent.target?.dialogManager.show((setState, close, context) {
cancel() {
sendLoginResponse(client, false);
close();
}
submit() {
sendLoginResponse(client, true);
close();
}
return CustomAlertDialog(
title:
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text(translate(
client.isFileTransfer ? "File Connection" : "Screen Connection")),
IconButton(
onPressed: () {
close();
},
icon: const 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: Theme.of(globalKey.currentContext!).textTheme.bodyMedium,
2022-04-19 13:07:45 +08:00
),
],
),
actions: [
dialogButton("Dismiss", onPressed: cancel, isOutline: true),
if (approveMode != 'password')
dialogButton("Accept", onPressed: submit),
],
onSubmit: submit,
onCancel: cancel,
);
}, tag: getLoginDialogTag(client.id));
2022-04-19 13:07:45 +08:00
}
scrollToBottom() {
if (isDesktop) return;
Future.delayed(Duration(milliseconds: 200), () {
controller.animateTo(controller.position.maxScrollExtent,
duration: Duration(milliseconds: 200),
curve: Curves.fastLinearToSlowEaseIn);
});
}
void sendLoginResponse(Client client, bool res) async {
2022-04-19 13:07:45 +08:00
if (res) {
2022-08-17 17:23:55 +08:00
bind.cmLoginRes(connId: client.id, res: res);
2022-04-19 13:07:45 +08:00
if (!client.isFileTransfer) {
parent.target?.invokeMethod("start_capture");
2022-04-19 13:07:45 +08:00
}
parent.target?.invokeMethod("cancel_notification", client.id);
client.authorized = true;
2022-04-19 13:07:45 +08:00
notifyListeners();
} else {
2022-08-17 17:23:55 +08:00
bind.cmLoginRes(connId: client.id, res: res);
parent.target?.invokeMethod("cancel_notification", client.id);
final index = _clients.indexOf(client);
2022-08-24 21:52:21 +08:00
tabController.remove(index);
_clients.remove(client);
2022-03-19 23:28:29 +08:00
}
}
void onClientRemove(Map<String, dynamic> evt) {
try {
2022-03-19 23:28:29 +08:00
final id = int.parse(evt['id'] as String);
final close = (evt['close'] as String) == 'true';
if (_clients.any((c) => c.id == id)) {
final index = _clients.indexWhere((client) => client.id == id);
if (index >= 0) {
if (close) {
_clients.removeAt(index);
tabController.remove(index);
} else {
_clients[index].disconnected = true;
}
}
2022-08-12 18:42:02 +08:00
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
parent.target?.invokeMethod("cancel_notification", id);
2022-03-29 23:10:43 +08:00
}
if (desktopType == DesktopType.cm && _clients.isEmpty) {
hideCmWindow();
}
2022-03-19 23:28:29 +08:00
notifyListeners();
} catch (e) {
2022-03-19 23:28:29 +08:00
debugPrint("onClientRemove failed,error:$e");
}
}
2023-02-10 21:18:55 +08:00
Future<void> closeAll() async {
2023-02-27 23:41:09 +08:00
await Future.wait(
_clients.map((client) => bind.cmCloseConnection(connId: client.id)));
2022-03-25 16:34:27 +08:00
_clients.clear();
2022-08-24 21:52:21 +08:00
tabController.state.value.tabs.clear();
}
void jumpTo(int id) {
final index = _clients.indexWhere((client) => client.id == id);
tabController.jumpTo(index);
2022-03-19 23:28:29 +08:00
}
void setShowElevation(bool show) {
if (_showElevation != show) {
_showElevation = show;
notifyListeners();
}
}
2023-02-07 16:11:55 +08:00
void updateVoiceCallState(Map<String, dynamic> evt) {
try {
final client = Client.fromJson(jsonDecode(evt["client"]));
final index = _clients.indexWhere((element) => element.id == client.id);
if (index != -1) {
2023-02-07 16:47:19 +08:00
_clients[index].inVoiceCall = client.inVoiceCall;
_clients[index].incomingVoiceCall = client.incomingVoiceCall;
2023-02-07 17:09:36 +08:00
if (client.incomingVoiceCall) {
// Has incoming phone call, let's set the window on top.
Future.delayed(Duration.zero, () {
windowOnTop(null);
2023-02-07 17:09:36 +08:00
});
}
2023-02-07 16:11:55 +08:00
notifyListeners();
}
} catch (e) {
debugPrint("updateVoiceCallState failed: $e");
}
}
2022-03-19 23:28:29 +08:00
}
enum ClientType {
remote,
file,
portForward,
}
2022-03-19 23:28:29 +08:00
class Client {
2022-03-22 21:47:42 +08:00
int id = 0; // client connections inner count id
2022-03-19 23:28:29 +08:00
bool authorized = false;
bool isFileTransfer = false;
String portForward = "";
2022-03-19 23:28:29 +08:00
String name = "";
2022-03-22 21:47:42 +08:00
String peerId = ""; // peer user's id,show at app
bool keyboard = false;
bool clipboard = false;
bool audio = false;
bool file = false;
bool restart = false;
bool recording = false;
bool blockInput = false;
bool disconnected = false;
bool fromSwitch = false;
2023-02-07 16:11:55 +08:00
bool inVoiceCall = false;
bool incomingVoiceCall = false;
2022-03-19 23:28:29 +08:00
RxInt unreadChatMessageCount = 0.obs;
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
2022-04-13 15:33:23 +08:00
this.keyboard, this.clipboard, this.audio);
2022-03-19 23:28:29 +08:00
Client.fromJson(Map<String, dynamic> json) {
id = json['id'];
authorized = json['authorized'];
isFileTransfer = json['is_file_transfer'];
portForward = json['port_forward'];
2022-03-19 23:28:29 +08:00
name = json['name'];
peerId = json['peer_id'];
2022-04-13 15:33:23 +08:00
keyboard = json['keyboard'];
clipboard = json['clipboard'];
audio = json['audio'];
file = json['file'];
restart = json['restart'];
recording = json['recording'];
blockInput = json['block_input'];
disconnected = json['disconnected'];
fromSwitch = json['from_switch'];
2023-02-07 16:11:55 +08:00
inVoiceCall = json['in_voice_call'];
incomingVoiceCall = json['incoming_voice_call'];
2022-03-19 23:28:29 +08:00
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['is_start'] = authorized;
data['is_file_transfer'] = isFileTransfer;
data['port_forward'] = portForward;
data['name'] = name;
data['peer_id'] = peerId;
data['keyboard'] = keyboard;
data['clipboard'] = clipboard;
data['audio'] = audio;
data['file'] = file;
data['restart'] = restart;
data['recording'] = recording;
data['block_input'] = blockInput;
data['disconnected'] = disconnected;
data['from_switch'] = fromSwitch;
2022-03-19 23:28:29 +08:00
return data;
}
ClientType type_() {
if (isFileTransfer) {
return ClientType.file;
} else if (portForward.isNotEmpty) {
return ClientType.portForward;
} else {
return ClientType.remote;
}
}
2022-03-19 23:28:29 +08:00
}
2022-03-22 21:47:42 +08:00
2022-04-19 13:07:45 +08:00
String getLoginDialogTag(int id) {
2022-09-29 13:07:20 +08:00
return kLoginDialogTag + id.toString();
2022-04-19 13:07:45 +08:00
}
showInputWarnAlert(FFI ffi) {
2023-05-08 12:34:19 +08:00
ffi.dialogManager.show((setState, close, context) {
submit() {
AndroidPermissionManager.startAction(kActionAccessibilitySettings);
close();
}
return CustomAlertDialog(
title: Text(translate("How to get Android input permission?")),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(translate("android_input_permission_tip1")),
const SizedBox(height: 10),
Text(translate("android_input_permission_tip2")),
2022-04-19 13:07:45 +08:00
],
),
actions: [
dialogButton("Cancel", onPressed: close, isOutline: true),
dialogButton("Open System Setting", onPressed: submit),
],
onSubmit: submit,
onCancel: close,
);
});
2022-03-22 21:47:42 +08:00
}
Future<void> showClientsMayNotBeChangedAlert(FFI? ffi) async {
2023-05-08 12:34:19 +08:00
await ffi?.dialogManager.show((setState, close, context) {
return CustomAlertDialog(
title: Text(translate("Permissions")),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(translate("android_permission_may_not_change_tip")),
],
),
actions: [
dialogButton("OK", onPressed: close),
],
onSubmit: close,
onCancel: close,
);
});
}