rustdesk 2024-06-18 14:39:56 +08:00
parent 32b26e4ad3
commit d25670c79a
3 changed files with 47 additions and 26 deletions

View File

@ -2674,11 +2674,14 @@ Future<void> start_service(bool is_start) async {
} }
} }
typedef WhetherUseRemoteBlock = Future<bool> Function(); Future<bool> canBeBlocked() async {
Widget buildRemoteBlock({required Widget child, WhetherUseRemoteBlock? use}) { var access_mode = await bind.mainGetOption(key: kOptionAccessMode);
var block = false.obs; var option = option2bool(kOptionAllowRemoteConfigModification,
return Obx(() => MouseRegion( await bind.mainGetOption(key: kOptionAllowRemoteConfigModification));
onEnter: (_) async { return access_mode == 'view' || (access_mode.isEmpty && !option);
}
Future<void> shouldBeBlocked(RxBool block, WhetherUseRemoteBlock? use) async {
if (use != null && !await use()) { if (use != null && !await use()) {
block.value = false; block.value = false;
return; return;
@ -2691,6 +2694,14 @@ Widget buildRemoteBlock({required Widget child, WhetherUseRemoteBlock? use}) {
block.value = true; block.value = true;
} }
}); });
}
typedef WhetherUseRemoteBlock = Future<bool> Function();
Widget buildRemoteBlock({required Widget child, WhetherUseRemoteBlock? use}) {
var block = false.obs;
return Obx(() => MouseRegion(
onEnter: (_) async {
await shouldBeBlocked(block, use);
}, },
onExit: (event) => block.value = false, onExit: (event) => block.value = false,
child: Stack(children: [ child: Stack(children: [

View File

@ -36,12 +36,24 @@ class DesktopTabPage extends StatefulWidget {
} }
} }
class _DesktopTabPageState extends State<DesktopTabPage> { class _DesktopTabPageState extends State<DesktopTabPage>
with WidgetsBindingObserver {
final tabController = DesktopTabController(tabType: DesktopTabType.main); final tabController = DesktopTabController(tabType: DesktopTabType.main);
final RxBool _block = false.obs;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
if (state == AppLifecycleState.resumed) {
shouldBeBlocked(_block, canBeBlocked);
} else if (state == AppLifecycleState.inactive) {}
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addObserver(this);
Get.put<DesktopTabController>(tabController); Get.put<DesktopTabController>(tabController);
RemoteCountState.init(); RemoteCountState.init();
tabController.add(TabInfo( tabController.add(TabInfo(
@ -68,8 +80,10 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
@override @override
void dispose() { void dispose() {
super.dispose(); WidgetsBinding.instance.removeObserver(this);
Get.delete<DesktopTabController>(); Get.delete<DesktopTabController>();
super.dispose();
} }
@override @override
@ -89,12 +103,17 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
), ),
), ),
))); )));
widget() => MouseRegion(
onEnter: (_) async {
await shouldBeBlocked(_block, canBeBlocked);
},
child: FocusScope(child: tabWidget, canRequestFocus: !_block.value));
return isMacOS || kUseCompatibleUiMode return isMacOS || kUseCompatibleUiMode
? tabWidget ? Obx(() => widget())
: Obx( : Obx(
() => DragToResizeArea( () => DragToResizeArea(
resizeEdgeSize: stateGlobal.resizeEdgeSize.value, resizeEdgeSize: stateGlobal.resizeEdgeSize.value,
child: tabWidget, child: widget(),
), ),
); );
} }

View File

@ -320,16 +320,7 @@ class DesktopTab extends StatelessWidget {
if (tabType != DesktopTabType.main) { if (tabType != DesktopTabType.main) {
return child; return child;
} }
return buildRemoteBlock( return buildRemoteBlock(child: child, use: canBeBlocked);
child: child,
use: () async {
var access_mode = await bind.mainGetOption(key: kOptionAccessMode);
var option = option2bool(
kOptionAllowRemoteConfigModification,
await bind.mainGetOption(
key: kOptionAllowRemoteConfigModification));
return access_mode == 'view' || (access_mode.isEmpty && !option);
});
} }
List<Widget> _tabWidgets = []; List<Widget> _tabWidgets = [];