refact: custom client, more advanced settings (#8085)

* refact: custom client, more advanced settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* feat: custom client, more advanced settings

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2024-05-18 23:13:54 +08:00
committed by GitHub
parent c2b7810c33
commit 96f41fcc02
34 changed files with 356 additions and 258 deletions

View File

@@ -5,6 +5,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/hbbs/hbbs.dart';
import 'package:flutter_hbb/common/widgets/peers_view.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/models/model.dart';
import 'package:flutter_hbb/models/peer_model.dart';
import 'package:flutter_hbb/models/platform_model.dart';
@@ -548,7 +549,7 @@ class AbModel {
}
trySetCurrentToLast() {
final name = bind.getLocalFlutterOption(k: 'current-ab-name');
final name = bind.getLocalFlutterOption(k: kOptionCurrentAbName);
if (addressbooks.containsKey(name)) {
_currentName.value = name;
}

View File

@@ -389,7 +389,7 @@ class FfiModel with ChangeNotifier {
_handleSyncPeerOption(Map<String, dynamic> evt, String peer) {
final k = evt['k'];
final v = evt['v'];
if (k == kOptionViewOnly) {
if (k == kOptionToggleViewOnly) {
setViewOnly(peer, v as bool);
} else if (k == 'keyboard_mode') {
parent.target?.inputModel.updateKeyboardMode();
@@ -765,7 +765,7 @@ class FfiModel with ChangeNotifier {
_touchMode = true;
} else {
_touchMode = await bind.sessionGetOption(
sessionId: sessionId, arg: 'touch-mode') !=
sessionId: sessionId, arg: kOptionTouchMode) !=
'';
}
if (connType == ConnType.fileTransfer) {
@@ -797,7 +797,7 @@ class FfiModel with ChangeNotifier {
setViewOnly(
peerId,
bind.sessionGetToggleOptionSync(
sessionId: sessionId, arg: kOptionViewOnly));
sessionId: sessionId, arg: kOptionToggleViewOnly));
}
if (connType == ConnType.defaultConn) {
final platformAdditions = evt['platform_additions'];

View File

@@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/models/peer_model.dart';
import 'package:flutter_hbb/models/platform_model.dart';
import 'package:get/get.dart';
@@ -22,9 +23,6 @@ class PeerTabModel with ChangeNotifier {
int get currentTab => _currentTab;
int _currentTab = 0; // index in tabNames
static const int maxTabCount = 5;
static const String kPeerTabIndex = 'peer-tab-index';
static const String kPeerTabOrder = 'peer-tab-order';
static const String kPeerTabVisible = 'peer-tab-visible';
static const List<String> tabNames = [
'Recent sessions',
'Favorites',
@@ -72,7 +70,7 @@ class PeerTabModel with ChangeNotifier {
PeerTabModel(this.parent) {
// visible
try {
final option = bind.getLocalFlutterOption(k: kPeerTabVisible);
final option = bind.getLocalFlutterOption(k: kOptionPeerTabVisible);
if (option.isNotEmpty) {
List<dynamic> decodeList = jsonDecode(option);
if (decodeList.length == _isVisible.length) {
@@ -88,7 +86,7 @@ class PeerTabModel with ChangeNotifier {
}
// order
try {
final option = bind.getLocalFlutterOption(k: kPeerTabOrder);
final option = bind.getLocalFlutterOption(k: kOptionPeerTabOrder);
if (option.isNotEmpty) {
List<dynamic> decodeList = jsonDecode(option);
if (decodeList.length == maxTabCount) {
@@ -112,7 +110,7 @@ class PeerTabModel with ChangeNotifier {
}
// init currentTab
_currentTab =
int.tryParse(bind.getLocalFlutterOption(k: kPeerTabIndex)) ?? 0;
int.tryParse(bind.getLocalFlutterOption(k: kOptionPeerTabIndex)) ?? 0;
if (_currentTab < 0 || _currentTab >= maxTabCount) {
_currentTab = 0;
}
@@ -222,7 +220,7 @@ class PeerTabModel with ChangeNotifier {
}
try {
bind.setLocalFlutterOption(
k: kPeerTabVisible, v: jsonEncode(_isVisible));
k: kOptionPeerTabVisible, v: jsonEncode(_isVisible));
} catch (_) {}
notifyListeners();
}
@@ -258,7 +256,7 @@ class PeerTabModel with ChangeNotifier {
for (int i = 0; i < list.length; i++) {
orders[i] = list[i];
}
bind.setLocalFlutterOption(k: kPeerTabOrder, v: jsonEncode(orders));
bind.setLocalFlutterOption(k: kOptionPeerTabOrder, v: jsonEncode(orders));
notifyListeners();
}
}

View File

@@ -125,8 +125,8 @@ class ServerModel with ChangeNotifier {
/*
// initital _hideCm at startup
final verificationMethod =
bind.mainGetOptionSync(key: "verification-method");
final approveMode = bind.mainGetOptionSync(key: 'approve-mode');
bind.mainGetOptionSync(key: kOptionVerificationMethod);
final approveMode = bind.mainGetOptionSync(key: kOptionApproveMode);
_hideCm = option2bool(
'allow-hide-cm', bind.mainGetOptionSync(key: 'allow-hide-cm'));
if (!(approveMode == 'password' &&
@@ -187,18 +187,19 @@ class ServerModel with ChangeNotifier {
if (androidVersion < 30 ||
!await AndroidPermissionManager.check(kRecordAudio)) {
_audioOk = false;
bind.mainSetOption(key: "enable-audio", value: "N");
bind.mainSetOption(key: kOptionEnableAudio, value: "N");
} else {
final audioOption = await bind.mainGetOption(key: 'enable-audio');
final audioOption = await bind.mainGetOption(key: kOptionEnableAudio);
_audioOk = audioOption.isEmpty;
}
// file
if (!await AndroidPermissionManager.check(kManageExternalStorage)) {
_fileOk = false;
bind.mainSetOption(key: "enable-file-transfer", value: "N");
bind.mainSetOption(key: kOptionEnableFileTransfer, value: "N");
} else {
final fileOption = await bind.mainGetOption(key: 'enable-file-transfer');
final fileOption =
await bind.mainGetOption(key: kOptionEnableFileTransfer);
_fileOk = fileOption.isEmpty;
}
@@ -209,10 +210,10 @@ class ServerModel with ChangeNotifier {
var update = false;
final temporaryPassword = await bind.mainGetTemporaryPassword();
final verificationMethod =
await bind.mainGetOption(key: "verification-method");
await bind.mainGetOption(key: kOptionVerificationMethod);
final temporaryPasswordLength =
await bind.mainGetOption(key: "temporary-password-length");
final approveMode = await bind.mainGetOption(key: 'approve-mode');
final approveMode = await bind.mainGetOption(key: kOptionApproveMode);
/*
var hideCm = option2bool(
'allow-hide-cm', await bind.mainGetOption(key: 'allow-hide-cm'));
@@ -283,7 +284,8 @@ class ServerModel with ChangeNotifier {
}
_audioOk = !_audioOk;
bind.mainSetOption(key: "enable-audio", value: _audioOk ? defaultOptionYes : 'N');
bind.mainSetOption(
key: kOptionEnableAudio, value: _audioOk ? defaultOptionYes : 'N');
notifyListeners();
}
@@ -302,7 +304,9 @@ class ServerModel with ChangeNotifier {
}
_fileOk = !_fileOk;
bind.mainSetOption(key: kOptionEnableFileTransfer, value: _fileOk ? defaultOptionYes : 'N');
bind.mainSetOption(
key: kOptionEnableFileTransfer,
value: _fileOk ? defaultOptionYes : 'N');
notifyListeners();
}
@@ -445,7 +449,9 @@ class ServerModel with ChangeNotifier {
break;
case "input":
if (_inputOk != value) {
bind.mainSetOption(key: kOptionEnableKeyboard, value: value ? defaultOptionYes : 'N');
bind.mainSetOption(
key: kOptionEnableKeyboard,
value: value ? defaultOptionYes : 'N');
}
_inputOk = value;
break;