fix(native): do not crash on bootstrap if API is not available (#10582)

This commit is contained in:
Brooooooklyn
2025-03-03 10:15:42 +00:00
committed by forehalo
parent 00398fc63a
commit 56604b6dc2
@@ -74,8 +74,9 @@ unsafe impl Encode for NSRect {
const ENCODING: Encoding = Encoding::Struct("NSRect", &[<NSPoint>::ENCODING, <NSSize>::ENCODING]); const ENCODING: Encoding = Encoding::Struct("NSRect", &[<NSPoint>::ENCODING, <NSSize>::ENCODING]);
} }
static RUNNING_APPLICATIONS: LazyLock<RwLock<Vec<AudioObjectID>>> = static RUNNING_APPLICATIONS: LazyLock<
LazyLock::new(|| RwLock::new(audio_process_list().expect("Failed to get running applications"))); RwLock<std::result::Result<Vec<AudioObjectID>, CoreAudioError>>,
> = LazyLock::new(|| RwLock::new(audio_process_list()));
static APPLICATION_STATE_CHANGED_SUBSCRIBERS: LazyLock< static APPLICATION_STATE_CHANGED_SUBSCRIBERS: LazyLock<
RwLock<HashMap<AudioObjectID, HashMap<Uuid, Arc<ThreadsafeFunction<(), ()>>>>>, RwLock<HashMap<AudioObjectID, HashMap<Uuid, Arc<ThreadsafeFunction<(), ()>>>>>,
@@ -551,9 +552,8 @@ impl ShareableContent {
) )
}) })
.and_then(|mut running_applications| { .and_then(|mut running_applications| {
audio_process_list().map_err(From::from).map(|apps| { *running_applications = audio_process_list();
*running_applications = apps; Ok(())
})
}) })
{ {
callback.call(Err(err), ThreadsafeFunctionCallMode::NonBlocking); callback.call(Err(err), ThreadsafeFunctionCallMode::NonBlocking);
@@ -673,6 +673,7 @@ impl ShareableContent {
) )
})? })?
.iter() .iter()
.flatten()
.filter_map(|id| { .filter_map(|id| {
let app = TappableApplication::new(*id); let app = TappableApplication::new(*id);
if !app.bundle_identifier().ok()?.is_empty() { if !app.bundle_identifier().ok()?.is_empty() {