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(
onWillPop: onWillPop ?? () async => false,
child: AlertDialog(
scrollable: true,
title: title,
contentPadding: EdgeInsets.symmetric(
horizontal: contentPadding ?? 25, vertical: 10),

View File

@ -6,15 +6,17 @@ import '../common.dart';
import '../pages/server_page.dart';
import 'model.dart';
final _emptyIdShow = translate("connecting_status");
final _emptyIdShow = translate("Generating ...");
class ServerModel with ChangeNotifier {
Timer? _interval;
bool _isStart = false;
bool _isStart = false; // Android MainService status
bool _mediaOk = false;
bool _inputOk = false;
bool _audioOk = false;
bool _fileOk = false;
int _connectStatus = 0; // Rendezvous Server status
final _serverId = TextEditingController(text: _emptyIdShow);
final _serverPasswd = TextEditingController(text: "");
@ -30,6 +32,8 @@ class ServerModel with ChangeNotifier {
bool get fileOk => _fileOk;
int get connectStatus => _connectStatus;
TextEditingController get serverId => _serverId;
TextEditingController get serverPasswd => _serverPasswd;
@ -80,6 +84,17 @@ class ServerModel with ChangeNotifier {
FFI.setByName('option', jsonEncode(res)); // input false by default
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 {

View File

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