This commit is contained in:
parent
32b26e4ad3
commit
d25670c79a
@ -2674,23 +2674,34 @@ Future<void> start_service(bool is_start) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> canBeBlocked() 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);
|
||||
}
|
||||
|
||||
Future<void> shouldBeBlocked(RxBool block, WhetherUseRemoteBlock? use) async {
|
||||
if (use != null && !await use()) {
|
||||
block.value = false;
|
||||
return;
|
||||
}
|
||||
var time0 = DateTime.now().millisecondsSinceEpoch;
|
||||
await bind.mainCheckMouseTime();
|
||||
Timer(const Duration(milliseconds: 120), () async {
|
||||
var d = time0 - await bind.mainGetMouseTime();
|
||||
if (d < 120) {
|
||||
block.value = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
typedef WhetherUseRemoteBlock = Future<bool> Function();
|
||||
Widget buildRemoteBlock({required Widget child, WhetherUseRemoteBlock? use}) {
|
||||
var block = false.obs;
|
||||
return Obx(() => MouseRegion(
|
||||
onEnter: (_) async {
|
||||
if (use != null && !await use()) {
|
||||
block.value = false;
|
||||
return;
|
||||
}
|
||||
var time0 = DateTime.now().millisecondsSinceEpoch;
|
||||
await bind.mainCheckMouseTime();
|
||||
Timer(const Duration(milliseconds: 120), () async {
|
||||
var d = time0 - await bind.mainGetMouseTime();
|
||||
if (d < 120) {
|
||||
block.value = true;
|
||||
}
|
||||
});
|
||||
await shouldBeBlocked(block, use);
|
||||
},
|
||||
onExit: (event) => block.value = false,
|
||||
child: Stack(children: [
|
||||
|
@ -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 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
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
Get.put<DesktopTabController>(tabController);
|
||||
RemoteCountState.init();
|
||||
tabController.add(TabInfo(
|
||||
@ -68,8 +80,10 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
Get.delete<DesktopTabController>();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@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
|
||||
? tabWidget
|
||||
? Obx(() => widget())
|
||||
: Obx(
|
||||
() => DragToResizeArea(
|
||||
resizeEdgeSize: stateGlobal.resizeEdgeSize.value,
|
||||
child: tabWidget,
|
||||
child: widget(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -320,16 +320,7 @@ class DesktopTab extends StatelessWidget {
|
||||
if (tabType != DesktopTabType.main) {
|
||||
return child;
|
||||
}
|
||||
return buildRemoteBlock(
|
||||
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);
|
||||
});
|
||||
return buildRemoteBlock(child: child, use: canBeBlocked);
|
||||
}
|
||||
|
||||
List<Widget> _tabWidgets = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user