mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-07 18:02:48 +08:00
feat: Android change id
This commit is contained in:
parent
e0302de808
commit
e32a019a29
74
flutter/lib/common/widgets/dialog.dart
Normal file
74
flutter/lib/common/widgets/dialog.dart
Normal file
@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
|
||||
void changeIdDialog() {
|
||||
var newId = "";
|
||||
var msg = "";
|
||||
var isInProgress = false;
|
||||
TextEditingController controller = TextEditingController();
|
||||
gFFI.dialogManager.show((setState, close) {
|
||||
submit() async {
|
||||
debugPrint("onSubmit");
|
||||
newId = controller.text.trim();
|
||||
setState(() {
|
||||
msg = "";
|
||||
isInProgress = true;
|
||||
bind.mainChangeId(newId: newId);
|
||||
});
|
||||
|
||||
var status = await bind.mainGetAsyncStatus();
|
||||
while (status == " ") {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
status = await bind.mainGetAsyncStatus();
|
||||
}
|
||||
if (status.isEmpty) {
|
||||
// ok
|
||||
close();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isInProgress = false;
|
||||
msg = translate(status);
|
||||
});
|
||||
}
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Change ID")),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("id_change_tip")),
|
||||
const SizedBox(
|
||||
height: 12.0,
|
||||
),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
errorText: msg.isEmpty ? null : translate(msg)),
|
||||
inputFormatters: [
|
||||
LengthLimitingTextInputFormatter(16),
|
||||
// FilteringTextInputFormatter(RegExp(r"[a-zA-z][a-zA-z0-9\_]*"), allow: true)
|
||||
],
|
||||
maxLength: 16,
|
||||
controller: controller,
|
||||
focusNode: FocusNode()..requestFocus(),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 4.0,
|
||||
),
|
||||
Offstage(
|
||||
offstage: !isInProgress, child: const LinearProgressIndicator())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
||||
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
||||
],
|
||||
onSubmit: submit,
|
||||
onCancel: close,
|
||||
);
|
||||
});
|
||||
}
|
@ -19,6 +19,8 @@ import 'package:tray_manager/tray_manager.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import '../../common/widgets/dialog.dart';
|
||||
|
||||
class _MenubarTheme {
|
||||
static const Color commonColor = MyTheme.accent;
|
||||
// kMinInteractiveDimension
|
||||
|
@ -11,6 +11,8 @@ import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import '../../common/widgets/dialog.dart';
|
||||
|
||||
const double _kTabWidth = 235;
|
||||
const double _kTabHeight = 42;
|
||||
const double _kCardFixedWidth = 560;
|
||||
@ -1496,82 +1498,4 @@ void changeSocks5Proxy() async {
|
||||
});
|
||||
}
|
||||
|
||||
void changeIdDialog() {
|
||||
var newId = "";
|
||||
var msg = "";
|
||||
var isInProgress = false;
|
||||
TextEditingController controller = TextEditingController();
|
||||
gFFI.dialogManager.show((setState, close) {
|
||||
submit() async {
|
||||
newId = controller.text.trim();
|
||||
setState(() {
|
||||
msg = "";
|
||||
isInProgress = true;
|
||||
bind.mainChangeId(newId: newId);
|
||||
});
|
||||
|
||||
var status = await bind.mainGetAsyncStatus();
|
||||
while (status == " ") {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
status = await bind.mainGetAsyncStatus();
|
||||
}
|
||||
if (status.isEmpty) {
|
||||
// ok
|
||||
close();
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isInProgress = false;
|
||||
msg = translate(status);
|
||||
});
|
||||
}
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Change ID")),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(translate("id_change_tip")),
|
||||
const SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
const Text("ID:").marginOnly(bottom: 16.0),
|
||||
const SizedBox(
|
||||
width: 24.0,
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
errorText: msg.isEmpty ? null : translate(msg)),
|
||||
inputFormatters: [
|
||||
LengthLimitingTextInputFormatter(16),
|
||||
// FilteringTextInputFormatter(RegExp(r"[a-zA-z][a-zA-z0-9\_]*"), allow: true)
|
||||
],
|
||||
maxLength: 16,
|
||||
controller: controller,
|
||||
focusNode: FocusNode()..requestFocus(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 4.0,
|
||||
),
|
||||
Offstage(
|
||||
offstage: !isInProgress, child: const LinearProgressIndicator())
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: close, child: Text(translate("Cancel"))),
|
||||
TextButton(onPressed: submit, child: Text(translate("OK"))),
|
||||
],
|
||||
onSubmit: submit,
|
||||
onCancel: close,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter_hbb/mobile/widgets/dialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../common/widgets/dialog.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
import '../../models/server_model.dart';
|
||||
import 'home_page.dart';
|
||||
@ -23,7 +24,6 @@ class ServerPage extends StatefulWidget implements PageShape {
|
||||
PopupMenuItem(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
value: "changeID",
|
||||
enabled: false,
|
||||
child: Text(translate("Change ID")),
|
||||
),
|
||||
PopupMenuItem(
|
||||
@ -86,7 +86,7 @@ class ServerPage extends StatefulWidget implements PageShape {
|
||||
},
|
||||
onSelected: (value) {
|
||||
if (value == "changeID") {
|
||||
// TODO
|
||||
changeIdDialog();
|
||||
} else if (value == "setPermanentPassword") {
|
||||
setPermanentPasswordDialog(gFFI.dialogManager);
|
||||
} else if (value == "setTemporaryPasswordLength") {
|
||||
|
@ -17,15 +17,15 @@ use crate::flutter::{self, SESSIONS};
|
||||
use crate::start_server;
|
||||
use crate::ui_interface;
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::ui_interface::{change_id, get_sound_inputs};
|
||||
use crate::ui_interface::get_sound_inputs;
|
||||
use crate::ui_interface::{
|
||||
check_mouse_time, check_super_user_permission, discover, forget_password, get_api_server,
|
||||
get_app_name, get_async_job_status, get_connect_status, get_fav, get_id, get_lan_peers,
|
||||
get_langs, get_license, get_local_option, get_mouse_time, get_option, get_options, get_peer,
|
||||
get_peer_option, get_socks, get_uuid, get_version, has_hwcodec, has_rendezvous_service,
|
||||
post_request, send_to_cm, set_local_option, set_option, set_options, set_peer_option,
|
||||
set_permanent_password, set_socks, store_fav, test_if_valid_server, update_temporary_password,
|
||||
using_public_server,
|
||||
change_id, check_mouse_time, check_super_user_permission, discover, forget_password,
|
||||
get_api_server, get_app_name, get_async_job_status, get_connect_status, get_fav, get_id,
|
||||
get_lan_peers, get_langs, get_license, get_local_option, get_mouse_time, get_option,
|
||||
get_options, get_peer, get_peer_option, get_socks, get_uuid, get_version, has_hwcodec,
|
||||
has_rendezvous_service, post_request, send_to_cm, set_local_option, set_option, set_options,
|
||||
set_peer_option, set_permanent_password, set_socks, store_fav, test_if_valid_server,
|
||||
update_temporary_password, using_public_server,
|
||||
};
|
||||
use crate::{
|
||||
client::file_trait::FileManager,
|
||||
@ -426,7 +426,6 @@ pub fn main_get_sound_inputs() -> Vec<String> {
|
||||
}
|
||||
|
||||
pub fn main_change_id(new_id: String) {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
change_id(new_id)
|
||||
}
|
||||
|
||||
|
@ -687,7 +687,6 @@ pub fn open_url(url: String) {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn change_id(id: String) {
|
||||
*ASYNC_JOB_STATUS.lock().unwrap() = " ".to_owned();
|
||||
let old_id = get_id();
|
||||
@ -864,17 +863,27 @@ pub(crate) async fn send_to_cm(data: &ipc::Data) {
|
||||
const INVALID_FORMAT: &'static str = "Invalid format";
|
||||
const UNKNOWN_ERROR: &'static str = "Unknown error";
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn change_id_(id: String, old_id: String) -> &'static str {
|
||||
if !hbb_common::is_valid_custom_id(&id) {
|
||||
return INVALID_FORMAT;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let uuid = machine_uid::get().unwrap_or("".to_owned());
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
let uuid = base64::encode(hbb_common::get_uuid());
|
||||
|
||||
if uuid.is_empty() {
|
||||
log::error!("Failed to change id, uuid is_empty");
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
let rendezvous_servers = crate::ipc::get_rendezvous_servers(1_000).await;
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
let rendezvous_servers = Config::get_rendezvous_servers();
|
||||
|
||||
let mut futs = Vec::new();
|
||||
let err: Arc<Mutex<&str>> = Default::default();
|
||||
for rendezvous_server in rendezvous_servers {
|
||||
@ -892,7 +901,13 @@ async fn change_id_(id: String, old_id: String) -> &'static str {
|
||||
join_all(futs).await;
|
||||
let err = *err.lock().unwrap();
|
||||
if err.is_empty() {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
crate::ipc::set_config_async("id", id.to_owned()).await.ok();
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
Config::set_key_confirmed(false);
|
||||
Config::set_id(&id);
|
||||
}
|
||||
}
|
||||
err
|
||||
}
|
||||
@ -937,6 +952,9 @@ async fn check_id(
|
||||
register_pk_response::Result::NOT_SUPPORT => {
|
||||
return "server_not_support";
|
||||
}
|
||||
register_pk_response::Result::SERVER_ERROR => {
|
||||
return "Server error";
|
||||
}
|
||||
register_pk_response::Result::INVALID_ID_FORMAT => {
|
||||
return INVALID_FORMAT;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user