Check if peer info is set

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-08-24 12:03:29 +08:00
parent e17002c6da
commit 0e838d59d5
4 changed files with 48 additions and 22 deletions

View File

@ -228,18 +228,12 @@ class _RemotePageState extends State<RemotePage>
removeSharedStates(widget.id); removeSharedStates(widget.id);
} }
Widget emptyOverlay() => GestureDetector( Widget emptyOverlay() => BlockableOverlay(
behavior: HitTestBehavior.translucent, /// the Overlay key will be set with _blockableOverlayState in BlockableOverlay
onTap: () { /// see override build() in [BlockableOverlay]
bind.sessionInputOsPassword(sessionId: sessionId, value: ''); state: _blockableOverlayState,
}, underlying: Container(
child: BlockableOverlay( color: Colors.transparent,
/// the Overlay key will be set with _blockableOverlayState in BlockableOverlay
/// see override build() in [BlockableOverlay]
state: _blockableOverlayState,
underlying: Container(
color: Colors.transparent,
),
), ),
); );
@ -273,7 +267,8 @@ class _RemotePageState extends State<RemotePage>
inputModel: _ffi.inputModel, inputModel: _ffi.inputModel,
child: getBodyForDesktop(context))), child: getBodyForDesktop(context))),
Obx( Obx(
() => _ffi.ffiModel.waitForFirstImage.isTrue () => _ffi.ffiModel.pi.isSet.isTrue &&
_ffi.ffiModel.waitForFirstImage.isTrue
? emptyOverlay() ? emptyOverlay()
: Offstage(), : Offstage(),
), ),
@ -286,6 +281,9 @@ class _RemotePageState extends State<RemotePage>
onEnterOrLeaveImageCleaner: () => onEnterOrLeaveImageCleaner: () =>
_onEnterOrLeaveImage4Toolbar = null, _onEnterOrLeaveImage4Toolbar = null,
), ),
Obx(
() => _ffi.ffiModel.pi.isSet.isFalse ? emptyOverlay() : Offstage(),
),
], ],
), ),
); );

View File

@ -20,6 +20,7 @@ import 'package:get/get.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import '../../common/widgets/dialog.dart'; import '../../common/widgets/dialog.dart';
import '../../models/model.dart';
import '../../models/platform_model.dart'; import '../../models/platform_model.dart';
class _MenuTheme { class _MenuTheme {
@ -266,7 +267,11 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
if (e.kind != ui.PointerDeviceKind.mouse) { if (e.kind != ui.PointerDeviceKind.mouse) {
return; return;
} }
if (e.buttons == 2) { final remotePage = tabController.state.value.tabs
.firstWhere((tab) => tab.key == key)
.page as RemotePage;
if (remotePage.ffi.ffiModel.pi.isSet.isTrue &&
e.buttons == 2) {
showRightMenu( showRightMenu(
(CancelFunc cancelFunc) { (CancelFunc cancelFunc) {
return _tabMenuBuilder(key, cancelFunc); return _tabMenuBuilder(key, cancelFunc);

View File

@ -99,6 +99,7 @@ class FfiModel with ChangeNotifier {
late final SessionID sessionId; late final SessionID sessionId;
RxBool waitForImageDialogShow = true.obs; RxBool waitForImageDialogShow = true.obs;
Timer? waitForImageTimer;
RxBool waitForFirstImage = true.obs; RxBool waitForFirstImage = true.obs;
Map<String, bool> get permissions => _permissions; Map<String, bool> get permissions => _permissions;
@ -159,6 +160,7 @@ class FfiModel with ChangeNotifier {
_timer?.cancel(); _timer?.cancel();
_timer = null; _timer = null;
clearPermissions(); clearPermissions();
waitForImageTimer?.cancel();
} }
setConnectionType(String peerId, bool secure, bool direct) { setConnectionType(String peerId, bool secure, bool direct) {
@ -511,6 +513,11 @@ class FfiModel with ChangeNotifier {
tag: '$sessionId-waiting-for-image', tag: '$sessionId-waiting-for-image',
); );
waitForImageDialogShow.value = true; waitForImageDialogShow.value = true;
waitForImageTimer = Timer(Duration(milliseconds: 1500), () {
if (waitForFirstImage.isTrue) {
bind.sessionInputOsPassword(sessionId: sessionId, value: '');
}
});
bind.sessionOnWaitingForImageDialogShow(sessionId: sessionId); bind.sessionOnWaitingForImageDialogShow(sessionId: sessionId);
} }
@ -603,6 +610,7 @@ class FfiModel with ChangeNotifier {
} }
} }
_pi.isSet.value = true;
stateGlobal.resetLastResolutionGroupValues(peerId); stateGlobal.resetLastResolutionGroupValues(peerId);
notifyListeners(); notifyListeners();
@ -1817,6 +1825,7 @@ class FFI {
void onEvent2UIRgba() async { void onEvent2UIRgba() async {
if (ffiModel.waitForImageDialogShow.isTrue) { if (ffiModel.waitForImageDialogShow.isTrue) {
ffiModel.waitForImageDialogShow.value = false; ffiModel.waitForImageDialogShow.value = false;
ffiModel.waitForImageTimer?.cancel();
clearWaitingForImage(dialogManager, sessionId); clearWaitingForImage(dialogManager, sessionId);
} }
if (ffiModel.waitForFirstImage.value == true) { if (ffiModel.waitForFirstImage.value == true) {
@ -1935,7 +1944,7 @@ class Features {
bool privacyMode = false; bool privacyMode = false;
} }
class PeerInfo { class PeerInfo with ChangeNotifier {
String version = ''; String version = '';
String username = ''; String username = '';
String hostname = ''; String hostname = '';
@ -1947,6 +1956,8 @@ class PeerInfo {
List<Resolution> resolutions = []; List<Resolution> resolutions = [];
Map<String, dynamic> platform_additions = {}; Map<String, dynamic> platform_additions = {};
RxBool isSet = false.obs;
bool get is_wayland => platform_additions['is_wayland'] == true; bool get is_wayland => platform_additions['is_wayland'] == true;
bool get is_headless => platform_additions['headless'] == true; bool get is_headless => platform_additions['headless'] == true;
} }

View File

@ -57,7 +57,10 @@ use scrap::{
ImageFormat, ImageRgb, ImageFormat, ImageRgb,
}; };
use crate::is_keyboard_mode_supported; use crate::{
common::input::{MOUSE_BUTTON_LEFT, MOUSE_TYPE_DOWN, MOUSE_TYPE_UP},
is_keyboard_mode_supported,
};
#[cfg(not(feature = "flutter"))] #[cfg(not(feature = "flutter"))]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
@ -2057,13 +2060,20 @@ pub fn send_pointer_device_event(
/// # Arguments /// # Arguments
/// ///
/// * `interface` - The interface for sending data. /// * `interface` - The interface for sending data.
fn activate_os(interface: &impl Interface) { /// * `send_click` - Whether to send a click event.
fn activate_os(interface: &impl Interface, send_click: bool) {
let left_down = MOUSE_BUTTON_LEFT << 3 | MOUSE_TYPE_DOWN;
let left_up = MOUSE_BUTTON_LEFT << 3 | MOUSE_TYPE_UP;
send_mouse(left_up, 0, 0, false, false, false, false, interface);
std::thread::sleep(Duration::from_millis(50));
send_mouse(0, 0, 0, false, false, false, false, interface); send_mouse(0, 0, 0, false, false, false, false, interface);
std::thread::sleep(Duration::from_millis(50)); std::thread::sleep(Duration::from_millis(50));
send_mouse(0, 3, 3, false, false, false, false, interface); send_mouse(0, 3, 3, false, false, false, false, interface);
std::thread::sleep(Duration::from_millis(50)); if send_click {
send_mouse(1 | 1 << 3, 0, 0, false, false, false, false, interface); std::thread::sleep(Duration::from_millis(50));
send_mouse(2 | 1 << 3, 0, 0, false, false, false, false, interface); send_mouse(left_down, 0, 0, false, false, false, false, interface);
send_mouse(left_up, 0, 0, false, false, false, false, interface);
}
/* /*
let mut key_event = KeyEvent::new(); let mut key_event = KeyEvent::new();
// do not use Esc, which has problem with Linux // do not use Esc, which has problem with Linux
@ -2096,11 +2106,13 @@ pub fn input_os_password(p: String, activate: bool, interface: impl Interface) {
/// * `activate` - Whether to activate OS. /// * `activate` - Whether to activate OS.
/// * `interface` - The interface for sending data. /// * `interface` - The interface for sending data.
fn _input_os_password(p: String, activate: bool, interface: impl Interface) { fn _input_os_password(p: String, activate: bool, interface: impl Interface) {
let input_password = !p.is_empty();
if activate { if activate {
activate_os(&interface); // Click event is used to bring up the password input box.
activate_os(&interface, input_password);
std::thread::sleep(Duration::from_millis(1200)); std::thread::sleep(Duration::from_millis(1200));
} }
if p.is_empty() { if !input_password {
return; return;
} }
let mut key_event = KeyEvent::new(); let mut key_event = KeyEvent::new();