From f4e0b6e50a2952b13b16e309276a04a803ef9eed Mon Sep 17 00:00:00 2001 From: Kingtous Date: Fri, 15 Jul 2022 17:00:37 +0800 Subject: [PATCH] add: change id on flutter --- .../lib/desktop/pages/desktop_home_page.dart | 62 +++++++++++++++++++ flutter/pubspec.lock | 4 +- src/flutter_ffi.rs | 10 ++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dart index 02b87f1c7..305155f0e 100644 --- a/flutter/lib/desktop/pages/desktop_home_page.dart +++ b/flutter/lib/desktop/pages/desktop_home_page.dart @@ -266,6 +266,8 @@ class _DesktopHomePageState extends State with TrayListener { } else if (value == "stop-service") { final option = gFFI.getOption(value); gFFI.setOption(value, option == "Y" ? "" : "Y"); + } else if (value == "change-id") { + changeId(); } } @@ -341,4 +343,64 @@ class _DesktopHomePageState extends State with TrayListener { }, ), value: 'audio-input',); } + + /// change local ID + void changeId() { + var newId = ""; + var msg = ""; + var isInProgress = false; + DialogManager.show( (setState, close) { + return CustomAlertDialog( + title: Text(translate("Change ID")), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(translate("id_change_tip")), + Offstage( + offstage: msg.isEmpty, + child: Text(msg, style: TextStyle(color: Colors.grey),)).marginOnly(bottom: 4.0), + TextField( + onChanged: (s) { + newId = s; + }, + decoration: InputDecoration( + border: OutlineInputBorder() + ), + inputFormatters: [ + LengthLimitingTextInputFormatter(16), + // FilteringTextInputFormatter(RegExp(r"[a-zA-z][a-zA-z0-9\_]*"), allow: true) + ], + maxLength: 16, + ), + SizedBox(height: 4.0,), + Offstage( + offstage: !isInProgress, + child: LinearProgressIndicator()) + ], + ), actions: [ + TextButton(onPressed: (){ + close(); + }, child: Text("取消")), + TextButton(onPressed: () async { + setState(() { + msg = ""; + isInProgress = true; + gFFI.bind.mainChangeId(newId: newId); + }); + + var status = await gFFI.bind.mainGetAsyncStatus(); + while (status == " "){ + await Future.delayed(Duration(milliseconds: 100)); + status = await gFFI.bind.mainGetAsyncStatus(); + } + setState(() { + isInProgress = false; + msg = translate(status); + }); + + }, child: Text("确定")), + ], + ); + }); + } } diff --git a/flutter/pubspec.lock b/flutter/pubspec.lock index b34076310..a798799f1 100644 --- a/flutter/pubspec.lock +++ b/flutter/pubspec.lock @@ -187,8 +187,8 @@ packages: dependency: "direct main" description: path: "." - ref: c7d97cb6615f2def34f8bad4def01af9e0077beb - resolved-ref: c7d97cb6615f2def34f8bad4def01af9e0077beb + ref: "7b72918710921f5fe79eae2dbaa411a66f5dfb45" + resolved-ref: "7b72918710921f5fe79eae2dbaa411a66f5dfb45" url: "https://github.com/Kingtous/rustdesk_desktop_multi_window" source: git version: "0.0.1" diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index f10fd6587..60d8fd4b5 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -19,7 +19,7 @@ use crate::flutter::connection_manager::{self, get_clients_length, get_clients_s use crate::flutter::{self, Session, SESSIONS}; use crate::start_server; use crate::ui_interface; -use crate::ui_interface::get_sound_inputs; +use crate::ui_interface::{change_id, get_async_job_status, get_sound_inputs, is_ok_change_id}; fn initialize(app_dir: &str) { *config::APP_DIR.write().unwrap() = app_dir.to_owned(); @@ -383,6 +383,14 @@ pub fn main_get_sound_inputs() -> Vec { get_sound_inputs() } +pub fn main_change_id(new_id: String) { + change_id(new_id) +} + +pub fn main_get_async_status() -> String { + get_async_job_status() +} + /// FFI for **get** commands which are idempotent. /// Return result in c string. ///