1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-03 10:13:31 +00:00

Use NO_CALLBACK_INDICATOR

This commit is contained in:
Anders Åberg
2025-10-13 15:32:20 -07:00
parent c8d55d9c4b
commit f97e7cf601

View File

@@ -79,6 +79,9 @@ pub struct NativeStatus {
value: String,
}
// In our callback management, 0 is a reserved sequence number indicating that a message does not have a callback.
const NO_CALLBACK_INDICATOR: u32 = 0;
#[uniffi::export]
impl MacOSProviderClient {
// FIXME: Remove unwraps! They panic and terminate the whole application.
@@ -94,7 +97,7 @@ impl MacOSProviderClient {
let client = MacOSProviderClient {
to_server_send,
response_callbacks_counter: AtomicU32::new(1), // 0 is reserved for no callback
response_callbacks_counter: AtomicU32::new(1), // Start at 1 since 0 is reserved for "no callback" scenarios
response_callbacks_queue: Arc::new(Mutex::new(HashMap::new())),
connection_status: Arc::new(std::sync::atomic::AtomicBool::new(false)),
};
@@ -246,7 +249,7 @@ impl MacOSProviderClient {
let sequence_number = if let Some(cb) = callback {
self.add_callback(cb)
} else {
0 // Special value indicating "no callback"
NO_CALLBACK_INDICATOR
};
let message = serde_json::to_string(&SerializedMessage::Message {
@@ -257,7 +260,7 @@ impl MacOSProviderClient {
if let Err(e) = self.to_server_send.blocking_send(message) {
// Make sure we remove the callback from the queue if we can't send the message
if sequence_number != 0 {
if sequence_number != NO_CALLBACK_INDICATOR {
if let Some((cb, _)) = self
.response_callbacks_queue
.lock()