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

fix: bluetooth crash on bluetooth off

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-04-25 15:01:12 -05:00 committed by GitHub
parent fbc175aa1f
commit ffe6656d2f
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