fix: bluetooth crash in select-bluetooth-device event (#46745)

fix: bluetooth crash on bluetooth off
This commit is contained in:
Shelley Vohr 2025-04-25 17:26:19 +02:00 committed by GitHub
parent 973e5d0249
commit 372cdb5dee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 40 deletions

View file

@ -5,13 +5,14 @@
#ifndef ELECTRON_SHELL_BROWSER_LIB_BLUETOOTH_CHOOSER_H_
#define ELECTRON_SHELL_BROWSER_LIB_BLUETOOTH_CHOOSER_H_
#include <map>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/bluetooth_chooser.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
namespace electron {
@ -39,14 +40,18 @@ class BluetoothChooser : public content::BluetoothChooser {
bool is_gatt_connected,
bool is_paired,
int signal_strength_level) override;
void OnDeviceChosen(const std::string& device_id);
std::vector<DeviceInfo> GetDeviceList();
private:
std::map<std::string, std::u16string> device_map_;
absl::flat_hash_map<std::string, std::u16string> device_id_to_name_map_;
raw_ptr<api::WebContents> api_web_contents_;
EventHandler event_handler_;
bool refreshing_ = false;
bool rescan_ = false;
base::WeakPtrFactory<BluetoothChooser> weak_ptr_factory_{this};
};
} // namespace electron