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 =>
|
bool get kUseCompatibleUiMode =>
|
||||||
Platform.isWindows &&
|
Platform.isWindows &&
|
||||||
const [WindowsTarget.w7].contains(windowsBuildNumber.windowsVersion);
|
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() {
|
import() {
|
||||||
Clipboard.getData(Clipboard.kTextPlain).then((value) {
|
Clipboard.getData(Clipboard.kTextPlain).then((value) {
|
||||||
TextEditingController mytext = TextEditingController();
|
final text = value?.text;
|
||||||
String? aNullableString = '';
|
if (text != null && text.isNotEmpty) {
|
||||||
aNullableString = value?.text;
|
|
||||||
mytext.text = aNullableString.toString();
|
|
||||||
if (mytext.text.isNotEmpty) {
|
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic> config = jsonDecode(mytext.text);
|
final sc = ServerConfig.decode(text);
|
||||||
if (config.containsKey('IdServer')) {
|
if (sc.idServer.isNotEmpty) {
|
||||||
String id = config['IdServer'] ?? '';
|
idController.text = sc.idServer;
|
||||||
String relay = config['RelayServer'] ?? '';
|
relayController.text = sc.relayServer;
|
||||||
String api = config['ApiServer'] ?? '';
|
apiController.text = sc.apiServer;
|
||||||
String key = config['Key'] ?? '';
|
keyController.text = sc.key;
|
||||||
idController.text = id;
|
Future<bool> success =
|
||||||
relayController.text = relay;
|
set(sc.idServer, sc.relayServer, sc.apiServer, sc.key);
|
||||||
apiController.text = api;
|
|
||||||
keyController.text = key;
|
|
||||||
Future<bool> success = set(id, relay, api, key);
|
|
||||||
success.then((value) {
|
success.then((value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
showToast(
|
showToast(
|
||||||
@ -996,12 +990,15 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export() {
|
export() {
|
||||||
Map<String, String> config = {};
|
final text = ServerConfig(
|
||||||
config['IdServer'] = idController.text.trim();
|
idServer: idController.text,
|
||||||
config['RelayServer'] = relayController.text.trim();
|
relayServer: relayController.text,
|
||||||
config['ApiServer'] = apiController.text.trim();
|
apiServer: apiController.text,
|
||||||
config['Key'] = keyController.text.trim();
|
key: keyController.text)
|
||||||
Clipboard.setData(ClipboardData(text: jsonEncode(config)));
|
.encode();
|
||||||
|
debugPrint("ServerConfig export: $text");
|
||||||
|
|
||||||
|
Clipboard.setData(ClipboardData(text: text));
|
||||||
showToast(translate('Export server configuration successfully'));
|
showToast(translate('Export server configuration successfully'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1106,8 +1103,10 @@ class _AboutState extends State<_About> {
|
|||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 8.0,
|
height: 8.0,
|
||||||
),
|
),
|
||||||
Text(translate('Version') + ': $version').marginSymmetric(vertical: 4.0),
|
Text(translate('Version') + ': $version')
|
||||||
Text(translate('Build Date') + ': $buildDate').marginSymmetric(vertical: 4.0),
|
.marginSymmetric(vertical: 4.0),
|
||||||
|
Text(translate('Build Date') + ': $buildDate')
|
||||||
|
.marginSymmetric(vertical: 4.0),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
launchUrlString('https://rustdesk.com/privacy');
|
launchUrlString('https://rustdesk.com/privacy');
|
||||||
|
Loading…
Reference in New Issue
Block a user