parent
b45262c75b
commit
791506b510
2 changed files with 30 additions and 14 deletions
|
@ -49,7 +49,7 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
|
|||
const SizedBox(height: 16),
|
||||
FutureBuilder<List<(String, Object)>>(
|
||||
future: castService.searchDevices(),
|
||||
builder: (context, snapshot) {
|
||||
builder: (_, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
|
@ -79,13 +79,20 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
|
|||
});
|
||||
try {
|
||||
await _connectToYourApp(context, device);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isDeviceTapInProgress.remove(device);
|
||||
});
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
showGenericErrorDialog(context: context, error: e)
|
||||
.ignore();
|
||||
} finally {
|
||||
setState(() {
|
||||
_isDeviceTapInProgress.remove(device);
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isDeviceTapInProgress.remove(device);
|
||||
});
|
||||
showGenericErrorDialog(context: context, error: e)
|
||||
.ignore();
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
|
@ -120,7 +127,6 @@ class _AutoCastDialogState extends State<AutoCastDialog> {
|
|||
if (message.containsKey(CastMessageType.pairCode)) {
|
||||
final code = message[CastMessageType.pairCode]!['code'];
|
||||
widget.onConnect(code);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
@ -749,10 +749,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (BuildContext context) {
|
||||
builder: (BuildContext bContext) {
|
||||
return AutoCastDialog(
|
||||
(device) async {
|
||||
await _castPair(gw, device);
|
||||
await _castPair(bContext, gw, device);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
@ -775,7 +775,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
alwaysShowSuccessState: false,
|
||||
initialValue: code,
|
||||
onSubmit: (String text) async {
|
||||
final bool paired = await _castPair(gw, text);
|
||||
final bool paired = await _castPair(context, gw, text);
|
||||
if (!paired) {
|
||||
Future.delayed(Duration.zero, () => _pairWithPin(gw, code));
|
||||
}
|
||||
|
@ -783,8 +783,15 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
);
|
||||
}
|
||||
|
||||
Future<bool> _castPair(CastGateway gw, String code) async {
|
||||
String lastCode = '';
|
||||
Future<bool> _castPair(
|
||||
BuildContext bContext, CastGateway gw, String code) async {
|
||||
try {
|
||||
if (lastCode == code) {
|
||||
return false;
|
||||
}
|
||||
lastCode = code;
|
||||
_logger.info("Casting album to device with code $code");
|
||||
final String? publicKey = await gw.getPublicKey(code);
|
||||
if (publicKey == null) {
|
||||
showToast(context, S.of(context).deviceNotFound);
|
||||
|
@ -794,15 +801,18 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
final String castToken = const Uuid().v4().toString();
|
||||
final castPayload = CollectionsService.instance
|
||||
.getCastData(castToken, widget.collection!, publicKey);
|
||||
_logger.info("Casting album with token $castToken");
|
||||
await gw.publishCastPayload(
|
||||
code,
|
||||
castPayload,
|
||||
widget.collection!.id,
|
||||
castToken,
|
||||
);
|
||||
showToast(context, S.of(context).pairingComplete);
|
||||
_logger.info("Casted album with token $castToken");
|
||||
// showToast(bContext, S.of(context).pairingComplete);
|
||||
return true;
|
||||
} catch (e, s) {
|
||||
lastCode = '';
|
||||
_logger.severe("Failed to cast album", e, s);
|
||||
if (e is CastIPMismatchException) {
|
||||
await showErrorDialog(
|
||||
|
@ -811,7 +821,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
|
|||
S.of(context).castIPMismatchBody,
|
||||
);
|
||||
} else {
|
||||
await showGenericErrorDialog(context: context, error: e);
|
||||
await showGenericErrorDialog(context: bContext, error: e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue