Skip to content

Commit

Permalink
Safer use of volumeCallBack
Browse files Browse the repository at this point in the history
  • Loading branch information
JG committed Jan 7, 2019
1 parent 64e3838 commit 9332e54
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void startCasting() async {
// try to load previous state saved as json in saved_cast_state.json
Map savedState;
try {
File savedStateFile = await File('./saved_cast_state.json');
File savedStateFile = await File("saved_cast_state.json");
if (null != savedStateFile) {
savedState = jsonDecode(await savedStateFile.readAsString());
}
Expand Down Expand Up @@ -124,6 +124,8 @@ void startCasting() async {
// s = stop playing
// left arrow = seek current playback - 10s
// right arrow = seek current playback + 10s

stdin.echoMode = false;
stdin.lineMode = false;
stdin.listen(_handleUserInput);

Expand Down
17 changes: 9 additions & 8 deletions lib/casting/cast_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ class CastDevice extends ChangeNotifier {
CastModel castModel;

CastDevice({this.name, this.type, this.host, this.port, this.attr}) {
modelName = utf8.decode(attr['md']);
friendlyName = utf8.decode(attr['fn']);
if (attr != null) {
modelName = utf8.decode(attr['md']);
friendlyName = utf8.decode(attr['fn']);
}

switch (modelName) {
case "Google Home":
Expand Down Expand Up @@ -86,9 +88,9 @@ class CastDevice extends ChangeNotifier {
castModel = CastModel.NonGoogle;
break;
}

}


CastDeviceType get deviceType {
if (type.startsWith('_googlecast._tcp')) {
return CastDeviceType.ChromeCast;
Expand All @@ -98,8 +100,6 @@ class CastDevice extends ChangeNotifier {
return CastDeviceType.Unknown;
}



/// Comparator
/// In a List, the order will be:
///
Expand Down Expand Up @@ -130,15 +130,17 @@ class CastDevice extends ChangeNotifier {
b.castModel == CastModel.GoogleMax ||
b.castModel == CastModel.GoogleHub) {
return 1; // Go down under GoogleHome
} else if (b.castModel == CastModel.CastGroup || b.castModel == CastModel.NonGoogle) {
} else if (b.castModel == CastModel.CastGroup ||
b.castModel == CastModel.NonGoogle) {
return -1; // Before castGroup and NonGoogle in list
} else {
return this.host.compareTo(b.host);
}
break;
case CastModel.NonGoogle:
case CastModel.CastGroup:
if (b.castModel != CastModel.CastGroup && b.castModel != CastModel.NonGoogle) {
if (b.castModel != CastModel.CastGroup &&
b.castModel != CastModel.NonGoogle) {
return 1;
} else {
return this.host.compareTo(b.host);
Expand All @@ -149,6 +151,5 @@ class CastDevice extends ChangeNotifier {
return this.host.compareTo(b.host);
break;
}

}
}
10 changes: 7 additions & 3 deletions lib/casting/cast_sender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CastSender extends Object {
/// OVERRIDE FOR PRINT
///
/// This is there so print() is disabled in release versions. NOT FOR USE.
void print(dynamic theString) {}
//void print(dynamic theString) {}

/// The callback you set is called everytime:
///
Expand Down Expand Up @@ -280,7 +280,9 @@ class CastSender extends Object {
if ('CLOSE' == payloadMap['type']) {
_dispose();
connectionDidClose = true;
_volumeChangedCallback();
if (_volumeChangedCallback!=null) {
_volumeChangedCallback();
}
}
if ('RECEIVER_STATUS' == payloadMap['type']) {
_handleReceiverStatus(payloadMap);
Expand Down Expand Up @@ -387,7 +389,9 @@ class CastSender extends Object {

// Only update UI if new values
if (refresh) {
_volumeChangedCallback();
if (_volumeChangedCallback != null) {
_volumeChangedCallback();
}
}

try {
Expand Down

0 comments on commit 9332e54

Please sign in to comment.