listen flutter key event when there's no input monitor permission
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
6157889bb0
commit
9dbd1f88f5
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
|
||||
import '../../common.dart';
|
||||
import '../../models/input_model.dart';
|
||||
|
||||
class RawKeyFocusScope extends StatelessWidget {
|
||||
@ -20,13 +18,6 @@ class RawKeyFocusScope extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final FocusOnKeyCallback? onKey;
|
||||
if (isAndroid) {
|
||||
onKey = inputModel.handleRawKeyEvent;
|
||||
} else {
|
||||
onKey = stateGlobal.grabKeyboard ? inputModel.handleRawKeyEvent : null;
|
||||
}
|
||||
|
||||
return FocusScope(
|
||||
autofocus: true,
|
||||
child: Focus(
|
||||
@ -34,7 +25,7 @@ class RawKeyFocusScope extends StatelessWidget {
|
||||
canRequestFocus: true,
|
||||
focusNode: focusNode,
|
||||
onFocusChange: onFocusChange,
|
||||
onKey: onKey,
|
||||
onKey: inputModel.handleRawKeyEvent,
|
||||
child: child));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ const String kAppTypeDesktopPortForward = "port forward";
|
||||
|
||||
const String kWindowMainWindowOnTop = "main_window_on_top";
|
||||
const String kWindowGetWindowInfo = "get_window_info";
|
||||
const String kWindowDisableGrabKeyboard = "disable_grab_keyboard";
|
||||
const String kWindowActionRebuild = "rebuild";
|
||||
const String kWindowEventHide = "hide";
|
||||
const String kWindowEventShow = "show";
|
||||
|
@ -14,6 +14,7 @@ import 'package:flutter_hbb/desktop/pages/desktop_tab_page.dart';
|
||||
import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -498,6 +499,10 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
if (watchIsInputMonitoring) {
|
||||
if (bind.mainIsCanInputMonitoring(prompt: false)) {
|
||||
watchIsInputMonitoring = false;
|
||||
// Do not notify for now.
|
||||
// Monitoring may not take effect until the process is restarted.
|
||||
// rustDeskWinManager.call(
|
||||
// WindowType.RemoteDesktop, kWindowDisableGrabKeyboard, '');
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,8 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
forceRelay: args['forceRelay'],
|
||||
),
|
||||
));
|
||||
} else if (call.method == kWindowDisableGrabKeyboard) {
|
||||
stateGlobal.grabKeyboard = false;
|
||||
} else if (call.method == "onDestroy") {
|
||||
tabController.clear();
|
||||
} else if (call.method == kWindowActionRebuild) {
|
||||
|
@ -650,6 +650,12 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
}
|
||||
|
||||
Widget _buildKeyboard(BuildContext context) {
|
||||
// Do not support peer 1.1.9.
|
||||
if (Platform.isMacOS && stateGlobal.grabKeyboard) {
|
||||
bind.sessionSetKeyboardMode(id: widget.id, value: 'map');
|
||||
return Offstage();
|
||||
}
|
||||
|
||||
FfiModel ffiModel = Provider.of<FfiModel>(context);
|
||||
if (ffiModel.permissions['keyboard'] == false) {
|
||||
return Offstage();
|
||||
|
@ -58,6 +58,10 @@ class InputModel {
|
||||
InputModel(this.parent);
|
||||
|
||||
KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
|
||||
if (!stateGlobal.grabKeyboard) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
// * Currently mobile does not enable map mode
|
||||
if (isDesktop) {
|
||||
bind.sessionGetKeyboardMode(id: id).then((result) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::common::get_default_sound_input;
|
||||
use crate::{
|
||||
client::file_trait::FileManager,
|
||||
common::make_fd_to_json,
|
||||
common::is_keyboard_mode_supported,
|
||||
common::make_fd_to_json,
|
||||
flutter::{self, SESSIONS},
|
||||
flutter::{session_add, session_start_},
|
||||
ui_interface::{self, *},
|
||||
};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::common::get_default_sound_input;
|
||||
use flutter_rust_bridge::{StreamSink, SyncReturn};
|
||||
use hbb_common::{
|
||||
config::{self, LocalConfig, PeerConfig, ONLINE},
|
||||
@ -1181,6 +1181,9 @@ pub fn main_start_grab_keyboard() -> SyncReturn<bool> {
|
||||
return SyncReturn(false);
|
||||
}
|
||||
crate::keyboard::client::start_grab_loop();
|
||||
if !is_can_input_monitoring(false) {
|
||||
return SyncReturn(false);
|
||||
}
|
||||
SyncReturn(true)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user