android rendezvous server status

This commit is contained in:
csf 2022-04-17 11:34:46 +08:00
parent 7177a566ae
commit cabb39005b
3 changed files with 63 additions and 27 deletions

View File

@ -137,6 +137,7 @@ class CustomAlertDialog extends StatelessWidget {
return WillPopScope( return WillPopScope(
onWillPop: onWillPop ?? () async => false, onWillPop: onWillPop ?? () async => false,
child: AlertDialog( child: AlertDialog(
scrollable: true,
title: title, title: title,
contentPadding: EdgeInsets.symmetric( contentPadding: EdgeInsets.symmetric(
horizontal: contentPadding ?? 25, vertical: 10), horizontal: contentPadding ?? 25, vertical: 10),

View File

@ -6,15 +6,17 @@ import '../common.dart';
import '../pages/server_page.dart'; import '../pages/server_page.dart';
import 'model.dart'; import 'model.dart';
final _emptyIdShow = translate("connecting_status"); final _emptyIdShow = translate("Generating ...");
class ServerModel with ChangeNotifier { class ServerModel with ChangeNotifier {
Timer? _interval; Timer? _interval;
bool _isStart = false; bool _isStart = false; // Android MainService status
bool _mediaOk = false; bool _mediaOk = false;
bool _inputOk = false; bool _inputOk = false;
bool _audioOk = false; bool _audioOk = false;
bool _fileOk = false; bool _fileOk = false;
int _connectStatus = 0; // Rendezvous Server status
final _serverId = TextEditingController(text: _emptyIdShow); final _serverId = TextEditingController(text: _emptyIdShow);
final _serverPasswd = TextEditingController(text: ""); final _serverPasswd = TextEditingController(text: "");
@ -30,6 +32,8 @@ class ServerModel with ChangeNotifier {
bool get fileOk => _fileOk; bool get fileOk => _fileOk;
int get connectStatus => _connectStatus;
TextEditingController get serverId => _serverId; TextEditingController get serverId => _serverId;
TextEditingController get serverPasswd => _serverPasswd; TextEditingController get serverPasswd => _serverPasswd;
@ -80,6 +84,17 @@ class ServerModel with ChangeNotifier {
FFI.setByName('option', jsonEncode(res)); // input false by default FFI.setByName('option', jsonEncode(res)); // input false by default
notifyListeners(); notifyListeners();
}(); }();
Timer.periodic(Duration(seconds: 1), (timer) {
var status = int.tryParse(FFI.getByName('connect_statue')) ?? 0;
if (status > 0) {
status = 1;
}
if (status != _connectStatus) {
_connectStatus = status;
notifyListeners();
}
});
} }
toggleAudio() async { toggleAudio() async {

View File

@ -189,6 +189,14 @@ class _PermissionCheckerState extends State<PermissionChecker> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final serverModel = Provider.of<ServerModel>(context); final serverModel = Provider.of<ServerModel>(context);
final hasAudioPermission = androidVersion >= 30; final hasAudioPermission = androidVersion >= 30;
final status;
if (serverModel.connectStatus == -1) {
status = 'not_ready_status';
} else if (serverModel.connectStatus == 0) {
status = 'connecting_status';
} else {
status = 'Ready';
}
return PaddingCard( return PaddingCard(
title: translate("Configuration Permissions"), title: translate("Configuration Permissions"),
child: Column( child: Column(
@ -211,7 +219,9 @@ class _PermissionCheckerState extends State<PermissionChecker> {
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
serverModel.mediaOk Expanded(
flex: 0,
child: serverModel.mediaOk
? ElevatedButton.icon( ? ElevatedButton.icon(
style: ButtonStyle( style: ButtonStyle(
backgroundColor: backgroundColor:
@ -222,20 +232,30 @@ class _PermissionCheckerState extends State<PermissionChecker> {
: ElevatedButton.icon( : ElevatedButton.icon(
icon: Icon(Icons.play_arrow), icon: Icon(Icons.play_arrow),
onPressed: serverModel.toggleService, onPressed: serverModel.toggleService,
label: Text(translate("Start Service"))), label: Text(translate("Start Service")))),
serverModel.mediaOk Expanded(
child: serverModel.mediaOk
? Row( ? Row(
children: [ children: [
Padding( Expanded(
padding: EdgeInsets.only(left: 20, right: 5), flex: 0,
child: Padding(
padding:
EdgeInsets.only(left: 20, right: 5),
child: Icon(Icons.circle, child: Icon(Icons.circle,
color: Colors.greenAccent, size: 10)), color: serverModel.connectStatus > 0
Text(translate("Ready"), ? Colors.greenAccent
: Colors.deepOrangeAccent,
size: 10))),
Expanded(
child: Text(translate(status),
softWrap: true,
style: TextStyle( style: TextStyle(
fontSize: 16.0, color: MyTheme.accent50)) fontSize: 14.0,
color: MyTheme.accent50)))
], ],
) )
: SizedBox.shrink() : SizedBox.shrink())
], ],
), ),
], ],