del use global ctx,fix server alert

This commit is contained in:
csf 2022-02-25 21:54:05 +08:00
parent 18a9837dc9
commit eaff76370e
4 changed files with 73 additions and 38 deletions

View File

@ -192,4 +192,3 @@ bool isAndroid = false;
bool isIOS = false; bool isIOS = false;
bool isWeb = false; bool isWeb = false;
bool isDesktop = false; bool isDesktop = false;
BuildContext? currentCtx;

View File

@ -24,7 +24,6 @@ class _HomePageState extends State<HomePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
currentCtx = context;
if (isAndroid) { if (isAndroid) {
Timer(Duration(seconds: 5), () { Timer(Duration(seconds: 5), () {
_updateUrl = FFI.getByName('software_update_url'); _updateUrl = FFI.getByName('software_update_url');

View File

@ -16,6 +16,7 @@ Future<Null> main() async {
runApp(App()); runApp(App());
} }
final globalKey = GlobalKey<NavigatorState>();
class App extends StatelessWidget { class App extends StatelessWidget {
@override @override
@ -29,6 +30,7 @@ class App extends StatelessWidget {
ChangeNotifierProvider.value(value: FFI.canvasModel), ChangeNotifierProvider.value(value: FFI.canvasModel),
], ],
child: MaterialApp( child: MaterialApp(
navigatorKey: globalKey,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'RustDesk', title: 'RustDesk',
theme: ThemeData( theme: ThemeData(

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/main.dart';
import 'package:flutter_hbb/model.dart'; import 'package:flutter_hbb/model.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -155,12 +156,6 @@ class PermissionChecker extends StatefulWidget {
} }
class _PermissionCheckerState extends State<PermissionChecker> { class _PermissionCheckerState extends State<PermissionChecker> {
@override
void initState() {
super.initState();
currentCtx = context;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serverModel = Provider.of<ServerModel>(context); final serverModel = Provider.of<ServerModel>(context);
@ -169,9 +164,11 @@ class _PermissionCheckerState extends State<PermissionChecker> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
cardTitle(translate("Configuration Permissions")), cardTitle(translate("Configuration Permissions")),
PermissionRow(translate("Media"), serverModel.mediaOk, _toAndroidInitService), PermissionRow(
translate("Media"), serverModel.mediaOk, _toAndroidInitService),
const Divider(height: 0), const Divider(height: 0),
PermissionRow(translate("Input"), serverModel.inputOk, _toAndroidInitInput), PermissionRow(
translate("Input"), serverModel.inputOk, showInputWarnAlert),
const Divider(), const Divider(),
serverModel.mediaOk serverModel.mediaOk
? ElevatedButton.icon( ? ElevatedButton.icon(
@ -189,32 +186,42 @@ class _PermissionCheckerState extends State<PermissionChecker> {
BuildContext? loginReqAlertCtx; BuildContext? loginReqAlertCtx;
void showLoginReqAlert(BuildContext context, String peerID, String name) async { void showLoginReqAlert(String peerID, String name) async {
if (globalKey.currentContext == null) return;
await showDialog( await showDialog(
context: context, barrierDismissible: false,
context: globalKey.currentContext!,
builder: (alertContext) { builder: (alertContext) {
loginReqAlertCtx = alertContext; loginReqAlertCtx = alertContext;
return AlertDialog( return AlertDialog(
title: Text("Control Request"), title: Text("Control Request"),
content:Column( content: Container(
mainAxisAlignment: MainAxisAlignment.start, height: 100,
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ mainAxisAlignment: MainAxisAlignment.center,
Text(translate("Do you accept?")), crossAxisAlignment: CrossAxisAlignment.start,
SizedBox(width: 20),
Row(
children: [ children: [
CircleAvatar(child: Text(name[0])), Text(translate("Do you accept?")),
SizedBox(width: 10), SizedBox(height: 20),
Text(name), Row(
SizedBox(width: 5), children: [
Text(peerID) CircleAvatar(child: Text(name[0])),
SizedBox(width: 10),
Text(name),
SizedBox(width: 5),
Text(peerID)
],
),
], ],
), )),
],
),
actions: [ actions: [
TextButton( TextButton(
child: Text(translate("Dismiss")),
onPressed: () {
FFI.setByName("login_res", "false");
Navigator.of(alertContext).pop();
}),
ElevatedButton(
child: Text(translate("Accept")), child: Text(translate("Accept")),
onPressed: () { onPressed: () {
FFI.setByName("login_res", "true"); FFI.setByName("login_res", "true");
@ -224,12 +231,6 @@ void showLoginReqAlert(BuildContext context, String peerID, String name) async {
FFI.serverModel.setPeer(true); FFI.serverModel.setPeer(true);
Navigator.of(alertContext).pop(); Navigator.of(alertContext).pop();
}), }),
TextButton(
child: Text(translate("Dismiss")),
onPressed: () {
FFI.setByName("login_res", "false");
Navigator.of(alertContext).pop();
})
], ],
); );
}); });
@ -240,6 +241,7 @@ clearLoginReqAlert() {
if (loginReqAlertCtx != null) { if (loginReqAlertCtx != null) {
Navigator.of(loginReqAlertCtx!).pop(); Navigator.of(loginReqAlertCtx!).pop();
FFI.serverModel.updateClientState(); FFI.serverModel.updateClientState();
loginReqAlertCtx = null;
} }
} }
@ -362,9 +364,44 @@ Future<Null> _toAndroidInitInput() async {
debugPrint("_toAndroidInitInput:$res"); debugPrint("_toAndroidInitInput:$res");
} }
showInputWarnAlert() async {
if (globalKey.currentContext == null) return;
await showDialog<bool>(
context: globalKey.currentContext!,
builder: (alertContext) {
return AlertDialog(
title: Text("获取输入权限引导"),
// content: Text("请在接下来的系统设置页面 \n进入 [服务] 配置页面\n将[RustDesk Input]服务开启"),
content: Text.rich(TextSpan(
style: TextStyle(),
children: [
TextSpan(text:"请在接下来的系统设置页\n进入"),
TextSpan(text:" [服务] ",style: TextStyle(color: MyTheme.accent)),
TextSpan(text:"配置页面\n"),
TextSpan(text:" [RustDesk Input] ",style: TextStyle(color: MyTheme.accent)),
TextSpan(text:"服务开启")
]
)),
actions: [
TextButton(
child: Text(translate("Do nothing")),
onPressed: () {
Navigator.of(alertContext).pop();
}),
ElevatedButton(
child: Text(translate("Go System Setting")),
onPressed: () {
_toAndroidInitInput();
Navigator.of(alertContext).pop();
}),
],
);
});
}
void toAndroidChannelInit() { void toAndroidChannelInit() {
FFI.setMethodCallHandler((method, arguments) { FFI.setMethodCallHandler((method, arguments) {
debugPrint("flutter got android msg"); debugPrint("flutter got android msg,$method,$arguments");
try { try {
switch (method) { switch (method) {
case "try_start_without_auth": case "try_start_without_auth":
@ -372,10 +409,7 @@ void toAndroidChannelInit() {
FFI.serverModel.updateClientState(); FFI.serverModel.updateClientState();
debugPrint( debugPrint(
"pre show loginAlert:${FFI.serverModel.isFileTransfer.toString()}"); "pre show loginAlert:${FFI.serverModel.isFileTransfer.toString()}");
if(currentCtx!=null){ showLoginReqAlert(FFI.serverModel.peerID, FFI.serverModel.peerName);
showLoginReqAlert(
currentCtx!, FFI.serverModel.peerID, FFI.serverModel.peerName);
}
debugPrint("from jvm:try_start_without_auth done"); debugPrint("from jvm:try_start_without_auth done");
break; break;
} }
@ -388,6 +422,7 @@ void toAndroidChannelInit() {
case "stop_capture": case "stop_capture":
{ {
FFI.serverModel.setPeer(false); FFI.serverModel.setPeer(false);
clearLoginReqAlert();
break; break;
} }
case "on_permission_changed": case "on_permission_changed":