2022-03-22 16:40:23 +08:00
|
|
|
import 'dart:async';
|
2022-03-19 23:28:29 +08:00
|
|
|
import 'dart:convert';
|
2022-05-25 00:28:59 +08:00
|
|
|
|
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';
|
2022-11-23 09:41:05 +08:00
|
|
|
import 'package:flutter_hbb/main.dart';
|
2024-06-13 18:30:29 +08:00
|
|
|
import 'package:flutter_hbb/mobile/pages/settings_page.dart';
|
2023-07-10 09:40:41 +08:00
|
|
|
import 'package:flutter_hbb/models/chat_model.dart';
|
2022-08-08 17:53:51 +08:00
|
|
|
import 'package:flutter_hbb/models/platform_model.dart';
|
2022-10-26 22:50:36 +08:00
|
|
|
import 'package:get/get.dart';
|
2023-10-31 21:10:23 +08:00
|
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
2022-10-26 20:39:28 +08:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2022-05-25 00:28:59 +08:00
|
|
|
|
2022-03-19 23:28:29 +08:00
|
|
|
import '../common.dart';
|
2022-09-02 17:19:44 +08:00
|
|
|
import '../common/formatter/id_formatter.dart';
|
2022-11-03 21:58:25 +08:00
|
|
|
import '../desktop/pages/server_page.dart' as desktop;
|
2022-08-22 20:18:31 +08:00
|
|
|
import '../desktop/widgets/tabbar_widget.dart';
|
2022-05-24 23:33:00 +08:00
|
|
|
import '../mobile/pages/server_page.dart';
|
2023-06-23 18:25:42 +08:00
|
|
|
import 'model.dart';
|
2022-03-19 23:28:29 +08:00
|
|
|
|
2022-09-29 13:07:20 +08:00
|
|
|
const kLoginDialogTag = "LOGIN";
|
2022-03-22 16:40:23 +08:00
|
|
|
|
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;
|
2022-03-28 17:24:52 +08:00
|
|
|
bool _audioOk = false;
|
|
|
|
bool _fileOk = false;
|
2023-01-28 16:41:47 +08:00
|
|
|
bool _showElevation = false;
|
2023-08-30 11:48:42 +08:00
|
|
|
bool hideCm = false;
|
2023-06-23 18:25:42 +08:00
|
|
|
int _connectStatus = 0; // Rendezvous Server status
|
2022-07-29 18:34:25 +08:00
|
|
|
String _verificationMethod = "";
|
2022-08-01 20:42:30 +08:00
|
|
|
String _temporaryPasswordLength = "";
|
2022-11-20 15:53:08 +08:00
|
|
|
String _approveMode = "";
|
2023-08-26 18:49:23 +08:00
|
|
|
int _zeroClientLengthCounter = 0;
|
2022-04-17 11:34:46 +08:00
|
|
|
|
2022-06-13 21:07:26 +08:00
|
|
|
late String _emptyIdShow;
|
2022-09-02 17:19:44 +08:00
|
|
|
late final IDTextEditingController _serverId;
|
2023-09-04 12:11:35 +08:00
|
|
|
final _serverPasswd =
|
|
|
|
TextEditingController(text: translate("Generating ..."));
|
2022-03-22 16:40:23 +08:00
|
|
|
|
2022-09-01 21:18:53 +08:00
|
|
|
final tabController = DesktopTabController(tabType: DesktopTabType.cm);
|
2022-08-22 20:18:31 +08:00
|
|
|
|
2022-09-07 12:20:53 +08:00
|
|
|
final List<Client> _clients = [];
|
2022-03-19 23:28:29 +08:00
|
|
|
|
2022-10-26 20:39:28 +08:00
|
|
|
Timer? cmHiddenTimer;
|
|
|
|
|
2022-03-22 16:40:23 +08:00
|
|
|
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;
|
|
|
|
|
2022-03-22 16:40:23 +08:00
|
|
|
bool get fileOk => _fileOk;
|
|
|
|
|
2022-11-10 10:27:13 +08:00
|
|
|
bool get showElevation => _showElevation;
|
|
|
|
|
2023-06-23 18:25:42 +08:00
|
|
|
int get connectStatus => _connectStatus;
|
|
|
|
|
2022-08-01 20:42:30 +08:00
|
|
|
String get verificationMethod {
|
|
|
|
final index = [
|
|
|
|
kUseTemporaryPassword,
|
|
|
|
kUsePermanentPassword,
|
|
|
|
kUseBothPasswords
|
|
|
|
].indexOf(_verificationMethod);
|
|
|
|
if (index < 0) {
|
2022-08-13 12:43:35 +08:00
|
|
|
return kUseBothPasswords;
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
return _verificationMethod;
|
|
|
|
}
|
|
|
|
|
2022-11-20 15:53:08 +08:00
|
|
|
String get approveMode => _approveMode;
|
|
|
|
|
2022-09-07 12:20:53 +08:00
|
|
|
setVerificationMethod(String method) async {
|
Fix/custom client advanced settings (#8066)
* fix: custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, default options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: cargo test
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: remove prefix $ and unify option keys
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, advanced options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* debug custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings. Add filter-transfer to display settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, codec
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, whitelist
Signed-off-by: fufesou <shuanglongchen@yeah.net>
---------
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2024-05-17 14:19:11 +08:00
|
|
|
await bind.mainSetOption(key: kOptionVerificationMethod, value: method);
|
2023-11-08 11:28:59 +08:00
|
|
|
/*
|
2022-11-23 09:41:05 +08:00
|
|
|
if (method != kUsePermanentPassword) {
|
|
|
|
await bind.mainSetOption(
|
|
|
|
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
|
|
|
}
|
2023-11-08 11:28:59 +08:00
|
|
|
*/
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
String get temporaryPasswordLength {
|
|
|
|
final lengthIndex = ["6", "8", "10"].indexOf(_temporaryPasswordLength);
|
|
|
|
if (lengthIndex < 0) {
|
2022-08-13 12:43:35 +08:00
|
|
|
return "6";
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
return _temporaryPasswordLength;
|
|
|
|
}
|
|
|
|
|
2022-09-07 12:20:53 +08:00
|
|
|
setTemporaryPasswordLength(String length) async {
|
|
|
|
await bind.mainSetOption(key: "temporary-password-length", value: length);
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
2022-07-29 18:34:25 +08:00
|
|
|
|
2022-11-20 15:53:08 +08:00
|
|
|
setApproveMode(String mode) async {
|
Fix/custom client advanced settings (#8066)
* fix: custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, default options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: cargo test
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: remove prefix $ and unify option keys
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, advanced options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* debug custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings. Add filter-transfer to display settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, codec
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, whitelist
Signed-off-by: fufesou <shuanglongchen@yeah.net>
---------
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2024-05-17 14:19:11 +08:00
|
|
|
await bind.mainSetOption(key: kOptionApproveMode, value: mode);
|
2023-11-08 11:28:59 +08:00
|
|
|
/*
|
2022-11-23 09:41:05 +08:00
|
|
|
if (mode != 'password') {
|
|
|
|
await bind.mainSetOption(
|
|
|
|
key: 'allow-hide-cm', value: bool2option('allow-hide-cm', false));
|
|
|
|
}
|
2023-11-08 11:28:59 +08:00
|
|
|
*/
|
2022-11-20 15:53:08 +08:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:40:23 +08:00
|
|
|
TextEditingController get serverId => _serverId;
|
|
|
|
|
|
|
|
TextEditingController get serverPasswd => _serverPasswd;
|
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
List<Client> get clients => _clients;
|
2022-03-19 23:28:29 +08:00
|
|
|
|
2022-04-19 21:15:19 +08:00
|
|
|
final controller = ScrollController();
|
|
|
|
|
2022-06-13 21:07:26 +08:00
|
|
|
WeakReference<FFI> parent;
|
|
|
|
|
|
|
|
ServerModel(this.parent) {
|
2022-08-09 20:36:52 +08:00
|
|
|
_emptyIdShow = translate("Generating ...");
|
2022-09-02 17:19:44 +08:00
|
|
|
_serverId = IDTextEditingController(text: _emptyIdShow);
|
2022-04-17 11:34:46 +08:00
|
|
|
|
2023-08-30 11:48:42 +08:00
|
|
|
/*
|
2023-08-26 18:49:23 +08:00
|
|
|
// initital _hideCm at startup
|
|
|
|
final verificationMethod =
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainGetOptionSync(key: kOptionVerificationMethod);
|
|
|
|
final approveMode = bind.mainGetOptionSync(key: kOptionApproveMode);
|
2023-08-26 18:49:23 +08:00
|
|
|
_hideCm = option2bool(
|
|
|
|
'allow-hide-cm', bind.mainGetOptionSync(key: 'allow-hide-cm'));
|
|
|
|
if (!(approveMode == 'password' &&
|
|
|
|
verificationMethod == kUsePermanentPassword)) {
|
|
|
|
_hideCm = false;
|
|
|
|
}
|
2023-08-30 11:48:42 +08:00
|
|
|
*/
|
2023-08-26 18:49:23 +08:00
|
|
|
|
2022-11-20 15:53:08 +08:00
|
|
|
timerCallback() async {
|
2023-06-24 21:09:45 +08:00
|
|
|
final connectionStatus =
|
|
|
|
jsonDecode(await bind.mainGetConnectStatus()) as Map<String, dynamic>;
|
|
|
|
final statusNum = connectionStatus['status_num'] as int;
|
|
|
|
if (statusNum != _connectStatus) {
|
|
|
|
_connectStatus = statusNum;
|
2023-06-23 18:25:42 +08:00
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2023-03-13 13:46:44 +08:00
|
|
|
if (desktopType == DesktopType.cm) {
|
|
|
|
final res = await bind.cmCheckClientsLength(length: _clients.length);
|
|
|
|
if (res != null) {
|
|
|
|
debugPrint("clients not match!");
|
|
|
|
updateClientState(res);
|
2023-08-26 18:49:23 +08:00
|
|
|
} else {
|
|
|
|
if (_clients.isEmpty) {
|
|
|
|
hideCmWindow();
|
|
|
|
if (_zeroClientLengthCounter++ == 12) {
|
|
|
|
// 6 second
|
|
|
|
windowManager.close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_zeroClientLengthCounter = 0;
|
2023-08-30 11:48:42 +08:00
|
|
|
if (!hideCm) showCmWindow();
|
2023-08-26 18:49:23 +08:00
|
|
|
}
|
2023-03-13 13:46:44 +08:00
|
|
|
}
|
2022-04-19 21:15:19 +08:00
|
|
|
}
|
2022-07-29 18:34:25 +08:00
|
|
|
|
2022-07-29 22:07:45 +08:00
|
|
|
updatePasswordModel();
|
2022-11-20 15:53:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isTest) {
|
2022-11-23 09:41:05 +08:00
|
|
|
Future.delayed(Duration.zero, () async {
|
|
|
|
if (await bind.optionSynced()) {
|
|
|
|
await timerCallback();
|
|
|
|
}
|
|
|
|
});
|
2022-11-20 15:53:08 +08:00
|
|
|
Timer.periodic(Duration(milliseconds: 500), (timer) async {
|
|
|
|
await timerCallback();
|
|
|
|
});
|
|
|
|
}
|
2024-06-27 13:05:45 +08:00
|
|
|
|
|
|
|
// Initial keyboard status is off on mobile
|
|
|
|
if (isMobile) {
|
|
|
|
bind.mainSetOption(key: kOptionEnableKeyboard, value: 'N');
|
|
|
|
}
|
2022-03-22 21:47:42 +08:00
|
|
|
}
|
2022-03-22 16:40:23 +08:00
|
|
|
|
2022-08-09 20:36:52 +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)) {
|
2022-08-09 20:36:52 +08:00
|
|
|
_audioOk = false;
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainSetOption(key: kOptionEnableAudio, value: "N");
|
2022-08-09 20:36:52 +08:00
|
|
|
} else {
|
2024-05-18 23:13:54 +08:00
|
|
|
final audioOption = await bind.mainGetOption(key: kOptionEnableAudio);
|
2024-07-24 17:20:58 +08:00
|
|
|
_audioOk = audioOption != 'N';
|
2022-08-09 20:36:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// file
|
2023-02-27 23:41:09 +08:00
|
|
|
if (!await AndroidPermissionManager.check(kManageExternalStorage)) {
|
2022-08-09 20:36:52 +08:00
|
|
|
_fileOk = false;
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainSetOption(key: kOptionEnableFileTransfer, value: "N");
|
2022-08-09 20:36:52 +08:00
|
|
|
} else {
|
2024-05-18 23:13:54 +08:00
|
|
|
final fileOption =
|
|
|
|
await bind.mainGetOption(key: kOptionEnableFileTransfer);
|
2024-07-24 17:20:58 +08:00
|
|
|
_fileOk = fileOption != 'N';
|
2022-08-09 20:36:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-08-08 17:53:51 +08:00
|
|
|
updatePasswordModel() async {
|
2022-07-29 22:07:45 +08:00
|
|
|
var update = false;
|
2022-08-08 22:27:27 +08:00
|
|
|
final temporaryPassword = await bind.mainGetTemporaryPassword();
|
2022-08-08 17:53:51 +08:00
|
|
|
final verificationMethod =
|
2024-05-18 23:13:54 +08:00
|
|
|
await bind.mainGetOption(key: kOptionVerificationMethod);
|
2022-08-08 17:53:51 +08:00
|
|
|
final temporaryPasswordLength =
|
|
|
|
await bind.mainGetOption(key: "temporary-password-length");
|
2024-05-18 23:13:54 +08:00
|
|
|
final approveMode = await bind.mainGetOption(key: kOptionApproveMode);
|
2023-08-30 11:48:42 +08:00
|
|
|
/*
|
2022-11-23 09:41:05 +08:00
|
|
|
var hideCm = option2bool(
|
|
|
|
'allow-hide-cm', await bind.mainGetOption(key: 'allow-hide-cm'));
|
|
|
|
if (!(approveMode == 'password' &&
|
|
|
|
verificationMethod == kUsePermanentPassword)) {
|
|
|
|
hideCm = false;
|
|
|
|
}
|
2023-08-30 11:48:42 +08:00
|
|
|
*/
|
2022-11-20 15:53:08 +08:00
|
|
|
if (_approveMode != approveMode) {
|
|
|
|
_approveMode = approveMode;
|
|
|
|
update = true;
|
|
|
|
}
|
2024-06-10 11:01:39 +08:00
|
|
|
var stopped = await mainGetBoolOption(kOptionStopService);
|
2023-08-17 18:28:55 +08:00
|
|
|
final oldPwdText = _serverPasswd.text;
|
2023-06-07 14:25:34 +08:00
|
|
|
if (stopped ||
|
|
|
|
verificationMethod == kUsePermanentPassword ||
|
2022-11-20 15:53:08 +08:00
|
|
|
_approveMode == 'click') {
|
2022-08-01 20:42:30 +08:00
|
|
|
_serverPasswd.text = '-';
|
2023-08-17 18:28:55 +08:00
|
|
|
} else {
|
|
|
|
if (_serverPasswd.text != temporaryPassword &&
|
|
|
|
temporaryPassword.isNotEmpty) {
|
|
|
|
_serverPasswd.text = temporaryPassword;
|
|
|
|
}
|
2022-08-01 20:42:30 +08:00
|
|
|
}
|
|
|
|
if (oldPwdText != _serverPasswd.text) {
|
2022-07-29 22:07:45 +08:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
if (_verificationMethod != verificationMethod) {
|
|
|
|
_verificationMethod = verificationMethod;
|
|
|
|
update = true;
|
|
|
|
}
|
2022-08-01 20:42:30 +08:00
|
|
|
if (_temporaryPasswordLength != temporaryPasswordLength) {
|
2023-08-11 11:38:26 +08:00
|
|
|
if (_temporaryPasswordLength.isNotEmpty) {
|
|
|
|
bind.mainUpdateTemporaryPassword();
|
|
|
|
}
|
2022-08-01 20:42:30 +08:00
|
|
|
_temporaryPasswordLength = temporaryPasswordLength;
|
|
|
|
update = true;
|
|
|
|
}
|
2023-08-30 11:48:42 +08:00
|
|
|
/*
|
2022-11-23 09:41:05 +08:00
|
|
|
if (_hideCm != hideCm) {
|
|
|
|
_hideCm = hideCm;
|
|
|
|
if (desktopType == DesktopType.cm) {
|
|
|
|
if (hideCm) {
|
2023-06-20 12:43:38 +08:00
|
|
|
await hideCmWindow();
|
2022-11-23 09:41:05 +08:00
|
|
|
} else {
|
2023-06-20 12:43:38 +08:00
|
|
|
await showCmWindow();
|
2022-11-23 09:41:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
update = true;
|
|
|
|
}
|
2023-08-30 11:48:42 +08:00
|
|
|
*/
|
2022-07-29 22:07:45 +08:00
|
|
|
if (update) {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-03-22 21:47:42 +08:00
|
|
|
}
|
2022-03-22 16:40:23 +08:00
|
|
|
|
2022-04-04 14:54:00 +08:00
|
|
|
toggleAudio() async {
|
2023-03-13 09:37:26 +08:00
|
|
|
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) {
|
2023-02-28 18:46:41 +08:00
|
|
|
showToast(translate('Failed'));
|
2022-04-04 14:54:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 21:47:42 +08:00
|
|
|
_audioOk = !_audioOk;
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainSetOption(
|
|
|
|
key: kOptionEnableAudio, value: _audioOk ? defaultOptionYes : 'N');
|
2022-03-22 21:47:42 +08:00
|
|
|
notifyListeners();
|
2022-03-22 16:40:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-04 14:54:00 +08:00
|
|
|
toggleFile() async {
|
2023-03-13 09:37:26 +08:00
|
|
|
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) {
|
2023-02-28 18:46:41 +08:00
|
|
|
showToast(translate('Failed'));
|
2022-04-04 14:54:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:40:23 +08:00
|
|
|
_fileOk = !_fileOk;
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainSetOption(
|
|
|
|
key: kOptionEnableFileTransfer,
|
|
|
|
value: _fileOk ? defaultOptionYes : 'N');
|
2022-03-22 16:40:23 +08:00
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2023-03-13 09:37:26 +08:00
|
|
|
toggleInput() async {
|
|
|
|
if (clients.isNotEmpty) {
|
|
|
|
await showClientsMayNotBeChangedAlert(parent.target);
|
|
|
|
}
|
2022-04-13 15:33:23 +08:00
|
|
|
if (_inputOk) {
|
2022-06-13 21:07:26 +08:00
|
|
|
parent.target?.invokeMethod("stop_input");
|
Fix/custom client advanced settings (#8066)
* fix: custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, default options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: cargo test
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: remove prefix $ and unify option keys
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* refact: custom client, advanced options
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* debug custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings. Add filter-transfer to display settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* custom client, advanced settings
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, codec
Signed-off-by: fufesou <shuanglongchen@yeah.net>
* fix: custom client, advanced settings, whitelist
Signed-off-by: fufesou <shuanglongchen@yeah.net>
---------
Signed-off-by: fufesou <shuanglongchen@yeah.net>
2024-05-17 14:19:11 +08:00
|
|
|
bind.mainSetOption(key: kOptionEnableKeyboard, value: 'N');
|
2022-04-13 15:33:23 +08:00
|
|
|
} else {
|
2022-06-13 21:07:26 +08:00
|
|
|
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]
|
2022-06-13 21:07:26 +08:00
|
|
|
showInputWarnAlert(parent.target!);
|
|
|
|
}
|
2022-03-22 21:47:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-07 18:45:05 +08:00
|
|
|
Future<bool> checkRequestNotificationPermission() async {
|
|
|
|
debugPrint("androidVersion $androidVersion");
|
|
|
|
if (androidVersion < 33) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (await AndroidPermissionManager.check(kAndroid13Notification)) {
|
|
|
|
debugPrint("notification permission already granted");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
var res = await AndroidPermissionManager.request(kAndroid13Notification);
|
|
|
|
debugPrint("notification permission request result: $res");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-06-05 23:11:44 +08:00
|
|
|
Future<bool> checkFloatingWindowPermission() async {
|
|
|
|
debugPrint("androidVersion $androidVersion");
|
|
|
|
if (androidVersion < 23) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (await AndroidPermissionManager.check(kSystemAlertWindow)) {
|
|
|
|
debugPrint("alert window permission already granted");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
var res = await AndroidPermissionManager.request(kSystemAlertWindow);
|
|
|
|
debugPrint("alert window permission request result: $res");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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) {
|
2022-09-03 18:19:50 +08:00
|
|
|
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"))),
|
2023-03-02 10:50:04 +08:00
|
|
|
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
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 {
|
2024-05-07 18:45:05 +08:00
|
|
|
await checkRequestNotificationPermission();
|
2024-06-05 23:11:44 +08:00
|
|
|
if (bind.mainGetLocalOption(key: kOptionDisableFloatingWindow) != 'Y') {
|
|
|
|
await checkFloatingWindowPermission();
|
|
|
|
}
|
2024-05-27 21:01:09 +08:00
|
|
|
if (!await AndroidPermissionManager.check(kManageExternalStorage)) {
|
|
|
|
await AndroidPermissionManager.request(kManageExternalStorage);
|
|
|
|
}
|
2023-05-20 21:12:52 +08:00
|
|
|
final res = await parent.target?.dialogManager
|
|
|
|
.show<bool>((setState, close, context) {
|
2022-09-03 18:19:50 +08:00
|
|
|
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: [
|
2023-01-15 19:46:16 +08:00
|
|
|
dialogButton("Cancel", onPressed: close, isOutline: true),
|
|
|
|
dialogButton("OK", onPressed: submit),
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
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.
|
2022-11-03 21:58:25 +08:00
|
|
|
Future<void> startService() async {
|
2022-03-22 16:40:23 +08:00
|
|
|
_isStart = true;
|
|
|
|
notifyListeners();
|
2023-06-06 07:39:44 +08:00
|
|
|
parent.target?.ffiModel.updateEventListener(parent.target!.sessionId, "");
|
2022-06-13 21:07:26 +08:00
|
|
|
await parent.target?.invokeMethod("init_service");
|
2023-01-26 11:05:23 +08:00
|
|
|
// ugly is here, because for desktop, below is useless
|
2022-08-08 22:27:27 +08:00
|
|
|
await bind.mainStartService();
|
2022-04-15 17:45:48 +08:00
|
|
|
updateClientState();
|
2024-03-24 11:23:06 +08:00
|
|
|
if (isAndroid) {
|
2024-06-13 18:30:29 +08:00
|
|
|
androidUpdatekeepScreenOn();
|
2022-05-25 00:28:59 +08:00
|
|
|
}
|
2022-03-22 16:40:23 +08:00
|
|
|
}
|
|
|
|
|
2022-05-29 04:39:12 +08:00
|
|
|
/// Stop the screen sharing service.
|
2022-11-03 21:58:25 +08:00
|
|
|
Future<void> stopService() async {
|
2022-03-22 16:40:23 +08:00
|
|
|
_isStart = false;
|
2022-08-12 18:42:02 +08:00
|
|
|
closeAll();
|
2022-06-13 21:07:26 +08:00
|
|
|
await parent.target?.invokeMethod("stop_service");
|
2022-08-08 22:27:27 +08:00
|
|
|
await bind.mainStopService();
|
2022-03-22 16:40:23 +08:00
|
|
|
notifyListeners();
|
2024-03-24 11:23:06 +08:00
|
|
|
if (!isLinux) {
|
2022-05-25 00:28:59 +08:00
|
|
|
// current linux is not supported
|
2023-10-31 21:10:23 +08:00
|
|
|
WakelockPlus.disable();
|
2022-05-25 00:28:59 +08:00
|
|
|
}
|
2022-03-22 16:40:23 +08:00
|
|
|
}
|
|
|
|
|
2022-07-29 18:34:25 +08:00
|
|
|
Future<bool> setPermanentPassword(String newPW) async {
|
2022-08-08 22:27:27 +08:00
|
|
|
await bind.mainSetPermanentPassword(password: newPW);
|
2022-03-30 23:09:19 +08:00
|
|
|
await Future.delayed(Duration(milliseconds: 500));
|
2022-08-08 22:27:27 +08:00
|
|
|
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-22 16:40:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-19 23:28:29 +08:00
|
|
|
changeStatue(String name, bool value) {
|
2022-03-22 16:40:23 +08:00
|
|
|
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) {
|
2022-03-22 16:40:23 +08:00
|
|
|
startService();
|
|
|
|
}
|
2022-03-19 23:28:29 +08:00
|
|
|
break;
|
|
|
|
case "input":
|
2022-04-13 15:33:23 +08:00
|
|
|
if (_inputOk != value) {
|
2024-05-18 23:13:54 +08:00
|
|
|
bind.mainSetOption(
|
|
|
|
key: kOptionEnableKeyboard,
|
|
|
|
value: value ? defaultOptionYes : 'N');
|
2022-03-22 21:47:42 +08:00
|
|
|
}
|
2022-03-19 23:28:29 +08:00
|
|
|
_inputOk = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
// force
|
2022-08-08 22:27:27 +08:00
|
|
|
updateClientState([String? json]) async {
|
2022-10-20 22:05:34 +08:00
|
|
|
if (isTest) return;
|
2022-09-05 19:41:09 +08:00
|
|
|
var res = await bind.cmGetClientsState();
|
2023-07-31 20:02:01 +08:00
|
|
|
List<dynamic> clientsJson;
|
2022-03-19 23:28:29 +08:00
|
|
|
try {
|
2023-07-31 20:02:01 +08:00
|
|
|
clientsJson = jsonDecode(res);
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Failed to decode clientsJson: '$res', error $e");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-26 18:49:23 +08:00
|
|
|
final oldClientLenght = _clients.length;
|
2023-07-31 20:02:01 +08:00
|
|
|
_clients.clear();
|
|
|
|
tabController.state.value.tabs.clear();
|
|
|
|
|
|
|
|
for (var clientJson in clientsJson) {
|
|
|
|
try {
|
2022-04-15 17:45:48 +08:00
|
|
|
final client = Client.fromJson(clientJson);
|
2022-08-22 20:18:31 +08:00
|
|
|
_clients.add(client);
|
2022-10-26 20:39:28 +08:00
|
|
|
_addTab(client);
|
2023-07-31 20:02:01 +08:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("Failed to decode clientJson '$clientJson', error $e");
|
2022-03-25 16:34:27 +08:00
|
|
|
}
|
2022-04-15 17:45:48 +08:00
|
|
|
}
|
2023-08-26 18:49:23 +08:00
|
|
|
if (desktopType == DesktopType.cm) {
|
|
|
|
if (_clients.isEmpty) {
|
|
|
|
hideCmWindow();
|
2023-08-30 11:48:42 +08:00
|
|
|
} else if (!hideCm) {
|
2023-08-26 18:49:23 +08:00
|
|
|
showCmWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_clients.length != oldClientLenght) {
|
|
|
|
notifyListeners();
|
2024-06-13 18:30:29 +08:00
|
|
|
if (isAndroid) androidUpdatekeepScreenOn();
|
2023-08-26 18:49:23 +08:00
|
|
|
}
|
2022-03-19 23:28:29 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 19:41:09 +08:00
|
|
|
void addConnection(Map<String, dynamic> evt) {
|
2022-03-22 16:40:23 +08:00
|
|
|
try {
|
2022-03-19 23:28:29 +08:00
|
|
|
final client = Client.fromJson(jsonDecode(evt["client"]));
|
2022-09-05 19:41:09 +08:00
|
|
|
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);
|
2022-10-08 20:15:02 +08:00
|
|
|
// 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);
|
|
|
|
}
|
2023-08-30 11:48:42 +08:00
|
|
|
if (desktopType == DesktopType.cm && !hideCm) {
|
2023-08-26 18:49:23 +08:00
|
|
|
showCmWindow();
|
|
|
|
}
|
2022-10-08 20:15:02 +08:00
|
|
|
scrollToBottom();
|
|
|
|
notifyListeners();
|
|
|
|
if (isAndroid && !client.authorized) showLoginDialog(client);
|
2024-06-13 18:30:29 +08:00
|
|
|
if (isAndroid) androidUpdatekeepScreenOn();
|
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,
|
2023-07-08 11:09:50 +08:00
|
|
|
onTap: () {},
|
2022-11-03 21:58:25 +08:00
|
|
|
page: desktop.buildConnectionCard(client)));
|
2022-10-26 20:39:28 +08:00
|
|
|
Future.delayed(Duration.zero, () async {
|
2023-08-02 20:38:09 +08:00
|
|
|
if (!hideCm) windowOnTop(null);
|
2022-10-26 20:39:28 +08:00
|
|
|
});
|
2023-03-07 10:56:35 +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), () {
|
2022-11-23 09:41:05 +08:00
|
|
|
if (!hideCm) windowManager.minimize();
|
2022-10-26 20:39:28 +08:00
|
|
|
cmHiddenTimer = null;
|
|
|
|
});
|
|
|
|
}
|
2023-07-10 09:40:41 +08:00
|
|
|
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) {
|
2024-05-14 09:20:27 +08:00
|
|
|
showClientDialog(
|
|
|
|
client,
|
|
|
|
client.isFileTransfer ? "File Connection" : "Screen Connection",
|
|
|
|
'Do you accept?',
|
|
|
|
'android_new_connection_tip',
|
|
|
|
() => sendLoginResponse(client, false),
|
|
|
|
() => sendLoginResponse(client, true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleVoiceCall(Client client, bool accept) {
|
|
|
|
parent.target?.invokeMethod("cancel_notification", client.id);
|
|
|
|
bind.cmHandleIncomingVoiceCall(id: client.id, accept: accept);
|
|
|
|
}
|
|
|
|
|
|
|
|
showVoiceCallDialog(Client client) {
|
|
|
|
showClientDialog(
|
|
|
|
client,
|
|
|
|
'Voice call',
|
|
|
|
'Do you accept?',
|
|
|
|
'android_new_voice_call_tip',
|
|
|
|
() => handleVoiceCall(client, false),
|
|
|
|
() => handleVoiceCall(client, true),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
showClientDialog(Client client, String title, String contentTitle,
|
|
|
|
String content, VoidCallback onCancel, VoidCallback onSubmit) {
|
2023-05-08 12:34:19 +08:00
|
|
|
parent.target?.dialogManager.show((setState, close, context) {
|
2022-09-03 18:19:50 +08:00
|
|
|
cancel() {
|
2024-05-14 09:20:27 +08:00
|
|
|
onCancel();
|
2022-09-03 18:19:50 +08:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
submit() {
|
2024-05-14 09:20:27 +08:00
|
|
|
onSubmit();
|
2022-09-03 18:19:50 +08:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title:
|
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
2024-05-14 09:20:27 +08:00
|
|
|
Text(translate(title)),
|
|
|
|
IconButton(onPressed: close, icon: const Icon(Icons.close))
|
2022-09-03 18:19:50 +08:00
|
|
|
]),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-05-14 09:20:27 +08:00
|
|
|
Text(translate(contentTitle)),
|
2022-09-29 21:53:50 +08:00
|
|
|
ClientInfo(client),
|
2022-09-03 18:19:50 +08:00
|
|
|
Text(
|
2024-05-14 09:20:27 +08:00
|
|
|
translate(content),
|
2022-09-26 11:21:40 +08:00
|
|
|
style: Theme.of(globalKey.currentContext!).textTheme.bodyMedium,
|
2022-04-19 13:07:45 +08:00
|
|
|
),
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
2023-01-15 19:46:16 +08:00
|
|
|
dialogButton("Dismiss", onPressed: cancel, isOutline: true),
|
2023-06-28 20:22:57 +08:00
|
|
|
if (approveMode != 'password')
|
|
|
|
dialogButton("Accept", onPressed: submit),
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
onSubmit: submit,
|
|
|
|
onCancel: cancel,
|
|
|
|
);
|
|
|
|
}, tag: getLoginDialogTag(client.id));
|
2022-04-19 13:07:45 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 21:15:19 +08:00
|
|
|
scrollToBottom() {
|
2022-08-22 20:18:31 +08:00
|
|
|
if (isDesktop) return;
|
2022-04-19 21:15:19 +08:00
|
|
|
Future.delayed(Duration(milliseconds: 200), () {
|
|
|
|
controller.animateTo(controller.position.maxScrollExtent,
|
|
|
|
duration: Duration(milliseconds: 200),
|
|
|
|
curve: Curves.fastLinearToSlowEaseIn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-08 22:27:27 +08:00
|
|
|
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) {
|
2022-06-13 21:07:26 +08:00
|
|
|
parent.target?.invokeMethod("start_capture");
|
2022-04-19 13:07:45 +08:00
|
|
|
}
|
2022-06-13 21:07:26 +08:00
|
|
|
parent.target?.invokeMethod("cancel_notification", client.id);
|
2022-08-22 20:18:31 +08:00
|
|
|
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);
|
2022-06-13 21:07:26 +08:00
|
|
|
parent.target?.invokeMethod("cancel_notification", client.id);
|
2022-08-22 20:18:31 +08:00
|
|
|
final index = _clients.indexOf(client);
|
2022-08-24 21:52:21 +08:00
|
|
|
tabController.remove(index);
|
2022-08-22 20:18:31 +08:00
|
|
|
_clients.remove(client);
|
2024-06-13 18:30:29 +08:00
|
|
|
if (isAndroid) androidUpdatekeepScreenOn();
|
2022-03-19 23:28:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onClientRemove(Map<String, dynamic> evt) {
|
2022-03-22 16:40:23 +08:00
|
|
|
try {
|
2022-03-19 23:28:29 +08:00
|
|
|
final id = int.parse(evt['id'] as String);
|
2022-10-08 20:15:02 +08:00
|
|
|
final close = (evt['close'] as String) == 'true';
|
2022-08-22 20:18:31 +08:00
|
|
|
if (_clients.any((c) => c.id == id)) {
|
|
|
|
final index = _clients.indexWhere((client) => client.id == id);
|
2022-09-01 21:18:53 +08:00
|
|
|
if (index >= 0) {
|
2022-10-08 20:15:02 +08:00
|
|
|
if (close) {
|
|
|
|
_clients.removeAt(index);
|
|
|
|
tabController.remove(index);
|
|
|
|
} else {
|
|
|
|
_clients[index].disconnected = true;
|
|
|
|
}
|
2022-09-01 21:18:53 +08:00
|
|
|
}
|
2022-08-12 18:42:02 +08:00
|
|
|
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
|
2022-06-13 21:07:26 +08:00
|
|
|
parent.target?.invokeMethod("cancel_notification", id);
|
2022-03-29 23:10:43 +08:00
|
|
|
}
|
2023-08-26 18:49:23 +08:00
|
|
|
if (desktopType == DesktopType.cm && _clients.isEmpty) {
|
|
|
|
hideCmWindow();
|
|
|
|
}
|
2024-06-13 18:30:29 +08:00
|
|
|
if (isAndroid) androidUpdatekeepScreenOn();
|
2022-03-19 23:28:29 +08:00
|
|
|
notifyListeners();
|
2022-03-22 16:40:23 +08:00
|
|
|
} 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();
|
2024-06-13 18:30:29 +08:00
|
|
|
if (isAndroid) androidUpdatekeepScreenOn();
|
2022-08-24 21:52:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void jumpTo(int id) {
|
|
|
|
final index = _clients.indexWhere((client) => client.id == id);
|
|
|
|
tabController.jumpTo(index);
|
2022-03-19 23:28:29 +08:00
|
|
|
}
|
2022-11-10 10:27:13 +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) {
|
2024-05-14 09:20:27 +08:00
|
|
|
if (isAndroid) {
|
|
|
|
showVoiceCallDialog(client);
|
|
|
|
} else {
|
|
|
|
// 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");
|
|
|
|
}
|
|
|
|
}
|
2024-06-13 18:30:29 +08:00
|
|
|
|
|
|
|
void androidUpdatekeepScreenOn() async {
|
|
|
|
if (!isAndroid) return;
|
|
|
|
var floatingWindowDisabled =
|
|
|
|
bind.mainGetLocalOption(key: kOptionDisableFloatingWindow) == "Y" ||
|
|
|
|
!await AndroidPermissionManager.check(kSystemAlertWindow);
|
|
|
|
final keepScreenOn = floatingWindowDisabled
|
|
|
|
? KeepScreenOn.never
|
|
|
|
: optionToKeepScreenOn(
|
|
|
|
bind.mainGetLocalOption(key: kOptionKeepScreenOn));
|
|
|
|
final on = ((keepScreenOn == KeepScreenOn.serviceOn) && _isStart) ||
|
|
|
|
(keepScreenOn == KeepScreenOn.duringControlled &&
|
|
|
|
_clients.map((e) => !e.disconnected).isNotEmpty);
|
|
|
|
if (on != await WakelockPlus.enabled) {
|
|
|
|
if (on) {
|
|
|
|
WakelockPlus.enable();
|
|
|
|
} else {
|
|
|
|
WakelockPlus.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-19 23:28:29 +08:00
|
|
|
}
|
|
|
|
|
2022-12-04 18:47:02 +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;
|
2022-12-04 18:47:02 +08:00
|
|
|
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;
|
2022-08-18 19:49:41 +08:00
|
|
|
bool file = false;
|
|
|
|
bool restart = false;
|
2022-09-22 09:55:34 +08:00
|
|
|
bool recording = false;
|
2023-11-05 21:53:21 +08:00
|
|
|
bool blockInput = false;
|
2022-10-08 20:15:02 +08:00
|
|
|
bool disconnected = false;
|
2023-01-17 13:28:33 +08:00
|
|
|
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
|
|
|
|
2023-07-05 17:01:33 +08:00
|
|
|
RxInt unreadChatMessageCount = 0.obs;
|
2022-10-26 22:50:36 +08:00
|
|
|
|
2022-08-22 20:18:31 +08:00
|
|
|
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'];
|
2022-12-04 18:47:02 +08:00
|
|
|
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'];
|
2022-08-18 19:49:41 +08:00
|
|
|
file = json['file'];
|
|
|
|
restart = json['restart'];
|
2022-09-22 09:55:34 +08:00
|
|
|
recording = json['recording'];
|
2023-11-05 21:53:21 +08:00
|
|
|
blockInput = json['block_input'];
|
2022-10-08 20:15:02 +08:00
|
|
|
disconnected = json['disconnected'];
|
2023-01-17 13:28:33 +08:00
|
|
|
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() {
|
2022-10-26 22:50:36 +08:00
|
|
|
final Map<String, dynamic> data = <String, dynamic>{};
|
2022-10-08 20:15:02 +08:00
|
|
|
data['id'] = id;
|
2024-08-20 15:34:10 +08:00
|
|
|
data['authorized'] = authorized;
|
2022-10-08 20:15:02 +08:00
|
|
|
data['is_file_transfer'] = isFileTransfer;
|
2022-12-04 18:47:02 +08:00
|
|
|
data['port_forward'] = portForward;
|
2022-10-08 20:15:02 +08:00
|
|
|
data['name'] = name;
|
|
|
|
data['peer_id'] = peerId;
|
|
|
|
data['keyboard'] = keyboard;
|
|
|
|
data['clipboard'] = clipboard;
|
|
|
|
data['audio'] = audio;
|
2022-10-16 12:32:52 +08:00
|
|
|
data['file'] = file;
|
|
|
|
data['restart'] = restart;
|
|
|
|
data['recording'] = recording;
|
2023-11-05 21:53:21 +08:00
|
|
|
data['block_input'] = blockInput;
|
2022-10-08 20:15:02 +08:00
|
|
|
data['disconnected'] = disconnected;
|
2023-01-17 13:28:33 +08:00
|
|
|
data['from_switch'] = fromSwitch;
|
2024-08-20 15:34:10 +08:00
|
|
|
data['in_voice_call'] = inVoiceCall;
|
|
|
|
data['incoming_voice_call'] = incomingVoiceCall;
|
2022-03-19 23:28:29 +08:00
|
|
|
return data;
|
|
|
|
}
|
2022-12-04 18:47:02 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-06-13 21:07:26 +08:00
|
|
|
showInputWarnAlert(FFI ffi) {
|
2023-05-08 12:34:19 +08:00
|
|
|
ffi.dialogManager.show((setState, close, context) {
|
2022-09-03 18:19:50 +08:00
|
|
|
submit() {
|
2023-02-28 18:46:41 +08:00
|
|
|
AndroidPermissionManager.startAction(kActionAccessibilitySettings);
|
2022-09-03 18:19:50 +08:00
|
|
|
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
|
|
|
],
|
2022-09-03 18:19:50 +08:00
|
|
|
),
|
|
|
|
actions: [
|
2023-01-15 19:46:16 +08:00
|
|
|
dialogButton("Cancel", onPressed: close, isOutline: true),
|
|
|
|
dialogButton("Open System Setting", onPressed: submit),
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
onSubmit: submit,
|
|
|
|
onCancel: close,
|
|
|
|
);
|
|
|
|
});
|
2022-03-22 21:47:42 +08:00
|
|
|
}
|
2023-03-13 09:37:26 +08:00
|
|
|
|
|
|
|
Future<void> showClientsMayNotBeChangedAlert(FFI? ffi) async {
|
2023-05-08 12:34:19 +08:00
|
|
|
await ffi?.dialogManager.show((setState, close, context) {
|
2023-03-13 09:37:26 +08:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|