Fix daemon device discovery crash when Xcode isn't installed (#60546)
This commit is contained in:
@@ -64,6 +64,9 @@ class IOSDevices extends PollingDeviceDiscovery {
|
||||
'Control of iOS devices or simulators only supported on macOS.'
|
||||
);
|
||||
}
|
||||
if (!_xcdevice.isInstalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
deviceNotifier ??= ItemListNotifier<Device>();
|
||||
|
||||
@@ -72,7 +75,7 @@ class IOSDevices extends PollingDeviceDiscovery {
|
||||
|
||||
// cancel any outstanding subscriptions.
|
||||
await _observedDeviceEventsSubscription?.cancel();
|
||||
_observedDeviceEventsSubscription = _xcdevice.observedDeviceEvents().listen(
|
||||
_observedDeviceEventsSubscription = _xcdevice.observedDeviceEvents()?.listen(
|
||||
_onDeviceEvent,
|
||||
onError: (dynamic error, StackTrace stack) {
|
||||
_logger.printTrace('Process exception running xcdevice observe:\n$error\n$stack');
|
||||
|
||||
@@ -370,6 +370,19 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('start polling without Xcode', () async {
|
||||
final IOSDevices iosDevices = IOSDevices(
|
||||
platform: macPlatform,
|
||||
xcdevice: mockXcdevice,
|
||||
iosWorkflow: mockIosWorkflow,
|
||||
logger: logger,
|
||||
);
|
||||
when(mockXcdevice.isInstalled).thenReturn(false);
|
||||
|
||||
await iosDevices.startPolling();
|
||||
verifyNever(mockXcdevice.getAvailableIOSDevices());
|
||||
});
|
||||
|
||||
testWithoutContext('start polling', () async {
|
||||
final IOSDevices iosDevices = IOSDevices(
|
||||
platform: macPlatform,
|
||||
|
||||
Reference in New Issue
Block a user