mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-18 07:43:01 +08:00
add ServerConfig, update server config import and export
This commit is contained in:
parent
e47d1c7dbe
commit
4f74acba76
@ -1510,3 +1510,42 @@ Pointer<win32.OSVERSIONINFOEX> getOSVERSIONINFOEXPointer() {
|
||||
bool get kUseCompatibleUiMode =>
|
||||
Platform.isWindows &&
|
||||
const [WindowsTarget.w7].contains(windowsBuildNumber.windowsVersion);
|
||||
|
||||
class ServerConfig {
|
||||
late String idServer;
|
||||
late String relayServer;
|
||||
late String apiServer;
|
||||
late String key;
|
||||
|
||||
ServerConfig(
|
||||
{String? idServer, String? relayServer, String? apiServer, String? key}) {
|
||||
this.idServer = idServer?.trim() ?? '';
|
||||
this.relayServer = relayServer?.trim() ?? '';
|
||||
this.apiServer = apiServer?.trim() ?? '';
|
||||
this.key = key?.trim() ?? '';
|
||||
}
|
||||
|
||||
/// throw decoding failure
|
||||
ServerConfig.decode(String msg) {
|
||||
final input = msg.split('').reversed.join('');
|
||||
final bytes = base64Decode(base64.normalize(input));
|
||||
final json = jsonDecode(utf8.decode(bytes));
|
||||
|
||||
idServer = json['host'] ?? '';
|
||||
relayServer = json['relay'] ?? '';
|
||||
apiServer = json['api'] ?? '';
|
||||
key = json['key'] ?? '';
|
||||
}
|
||||
|
||||
String encode() {
|
||||
Map<String, String> config = {};
|
||||
config['host'] = idServer.trim();
|
||||
config['relay'] = relayServer.trim();
|
||||
config['api'] = apiServer.trim();
|
||||
config['key'] = key.trim();
|
||||
return base64Encode(Uint8List.fromList(jsonEncode(config).codeUnits))
|
||||
.split('')
|
||||
.reversed
|
||||
.join();
|
||||
}
|
||||
}
|
||||
|
@ -958,23 +958,17 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
|
||||
|
||||
import() {
|
||||
Clipboard.getData(Clipboard.kTextPlain).then((value) {
|
||||
TextEditingController mytext = TextEditingController();
|
||||
String? aNullableString = '';
|
||||
aNullableString = value?.text;
|
||||
mytext.text = aNullableString.toString();
|
||||
if (mytext.text.isNotEmpty) {
|
||||
final text = value?.text;
|
||||
if (text != null && text.isNotEmpty) {
|
||||
try {
|
||||
Map<String, dynamic> config = jsonDecode(mytext.text);
|
||||
if (config.containsKey('IdServer')) {
|
||||
String id = config['IdServer'] ?? '';
|
||||
String relay = config['RelayServer'] ?? '';
|
||||
String api = config['ApiServer'] ?? '';
|
||||
String key = config['Key'] ?? '';
|
||||
idController.text = id;
|
||||
relayController.text = relay;
|
||||
apiController.text = api;
|
||||
keyController.text = key;
|
||||
Future<bool> success = set(id, relay, api, key);
|
||||
final sc = ServerConfig.decode(text);
|
||||
if (sc.idServer.isNotEmpty) {
|
||||
idController.text = sc.idServer;
|
||||
relayController.text = sc.relayServer;
|
||||
apiController.text = sc.apiServer;
|
||||
keyController.text = sc.key;
|
||||
Future<bool> success =
|
||||
set(sc.idServer, sc.relayServer, sc.apiServer, sc.key);
|
||||
success.then((value) {
|
||||
if (value) {
|
||||
showToast(
|
||||
@ -996,12 +990,15 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
|
||||
}
|
||||
|
||||
export() {
|
||||
Map<String, String> config = {};
|
||||
config['IdServer'] = idController.text.trim();
|
||||
config['RelayServer'] = relayController.text.trim();
|
||||
config['ApiServer'] = apiController.text.trim();
|
||||
config['Key'] = keyController.text.trim();
|
||||
Clipboard.setData(ClipboardData(text: jsonEncode(config)));
|
||||
final text = ServerConfig(
|
||||
idServer: idController.text,
|
||||
relayServer: relayController.text,
|
||||
apiServer: apiController.text,
|
||||
key: keyController.text)
|
||||
.encode();
|
||||
debugPrint("ServerConfig export: $text");
|
||||
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
showToast(translate('Export server configuration successfully'));
|
||||
}
|
||||
|
||||
@ -1106,8 +1103,10 @@ class _AboutState extends State<_About> {
|
||||
const SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Text(translate('Version') + ': $version').marginSymmetric(vertical: 4.0),
|
||||
Text(translate('Build Date') + ': $buildDate').marginSymmetric(vertical: 4.0),
|
||||
Text(translate('Version') + ': $version')
|
||||
.marginSymmetric(vertical: 4.0),
|
||||
Text(translate('Build Date') + ': $buildDate')
|
||||
.marginSymmetric(vertical: 4.0),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
launchUrlString('https://rustdesk.com/privacy');
|
||||
|
Loading…
Reference in New Issue
Block a user