BTReal: Improve error handling for device opening
This commit attempts to improve error handling for device opening by reducing panic alert spam when opening one or several devices fails. Currently, Dolphin shows a panic alert for every device that we fail to open, and another panic alert at the end if no usable device was found. That is certainly a bit excessive -- we should only keep the very last panic alert (the one that is shown if everything fails) and we can just put the error for the last device open operation there. This also changes the PanicAlert to a CriticalAlert to ensure the message is visible even if the user has disabled regular panic alerts. The message has also been reworded and should hopefully be clearer.
This commit is contained in:
parent
d297080f52
commit
73e7f2a839
|
@ -16,6 +16,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
#include "Common/ChunkFile.h"
|
#include "Common/ChunkFile.h"
|
||||||
|
@ -81,6 +82,7 @@ IPCCommandResult BluetoothReal::Open(const OpenRequest& request)
|
||||||
if (!m_context.IsValid())
|
if (!m_context.IsValid())
|
||||||
return GetDefaultReply(IPC_EACCES);
|
return GetDefaultReply(IPC_EACCES);
|
||||||
|
|
||||||
|
m_last_open_error.clear();
|
||||||
m_context.GetDeviceList([this](libusb_device* device) {
|
m_context.GetDeviceList([this](libusb_device* device) {
|
||||||
libusb_device_descriptor device_descriptor;
|
libusb_device_descriptor device_descriptor;
|
||||||
libusb_get_device_descriptor(device, &device_descriptor);
|
libusb_get_device_descriptor(device, &device_descriptor);
|
||||||
|
@ -115,8 +117,19 @@ IPCCommandResult BluetoothReal::Open(const OpenRequest& request)
|
||||||
|
|
||||||
if (m_handle == nullptr)
|
if (m_handle == nullptr)
|
||||||
{
|
{
|
||||||
PanicAlertT("Bluetooth passthrough mode is enabled, "
|
if (m_last_open_error.empty())
|
||||||
"but no usable Bluetooth USB device was found. Aborting.");
|
{
|
||||||
|
CriticalAlertT(
|
||||||
|
"Could not find any usable Bluetooth USB adapter for Bluetooth Passthrough.\n\n"
|
||||||
|
"The emulated console will now stop.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CriticalAlertT("Could not find any usable Bluetooth USB adapter for Bluetooth Passthrough.\n"
|
||||||
|
"The following error occurred when Dolphin tried to use an adapter:\n%s\n\n"
|
||||||
|
"The emulated console will now stop.",
|
||||||
|
m_last_open_error.c_str());
|
||||||
|
}
|
||||||
Core::QueueHostJob(Core::Stop);
|
Core::QueueHostJob(Core::Stop);
|
||||||
return GetDefaultReply(IPC_ENOENT);
|
return GetDefaultReply(IPC_ENOENT);
|
||||||
}
|
}
|
||||||
|
@ -547,7 +560,8 @@ bool BluetoothReal::OpenDevice(libusb_device* device)
|
||||||
const int ret = libusb_open(m_device, &m_handle);
|
const int ret = libusb_open(m_device, &m_handle);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
PanicAlertT("Failed to open Bluetooth device: %s", libusb_error_name(ret));
|
m_last_open_error = fmt::format(Common::GetStringT("Failed to open Bluetooth device: {}"),
|
||||||
|
libusb_error_name(ret));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +574,8 @@ bool BluetoothReal::OpenDevice(libusb_device* device)
|
||||||
result = libusb_detach_kernel_driver(m_handle, INTERFACE);
|
result = libusb_detach_kernel_driver(m_handle, INTERFACE);
|
||||||
if (result < 0 && result != LIBUSB_ERROR_NOT_FOUND && result != LIBUSB_ERROR_NOT_SUPPORTED)
|
if (result < 0 && result != LIBUSB_ERROR_NOT_FOUND && result != LIBUSB_ERROR_NOT_SUPPORTED)
|
||||||
{
|
{
|
||||||
PanicAlertT("Failed to detach kernel driver for BT passthrough: %s",
|
m_last_open_error =
|
||||||
|
fmt::format(Common::GetStringT("Failed to detach kernel driver for BT passthrough: {}"),
|
||||||
libusb_error_name(result));
|
libusb_error_name(result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -568,7 +583,7 @@ bool BluetoothReal::OpenDevice(libusb_device* device)
|
||||||
#endif
|
#endif
|
||||||
if (libusb_claim_interface(m_handle, INTERFACE) < 0)
|
if (libusb_claim_interface(m_handle, INTERFACE) < 0)
|
||||||
{
|
{
|
||||||
PanicAlertT("Failed to claim interface for BT passthrough");
|
m_last_open_error = Common::GetStringT("Failed to claim interface for BT passthrough");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,8 @@ private:
|
||||||
std::atomic<SyncButtonState> m_sync_button_state{SyncButtonState::Unpressed};
|
std::atomic<SyncButtonState> m_sync_button_state{SyncButtonState::Unpressed};
|
||||||
Common::Timer m_sync_button_held_timer;
|
Common::Timer m_sync_button_held_timer;
|
||||||
|
|
||||||
|
std::string m_last_open_error;
|
||||||
|
|
||||||
LibusbUtils::Context m_context;
|
LibusbUtils::Context m_context;
|
||||||
libusb_device* m_device = nullptr;
|
libusb_device* m_device = nullptr;
|
||||||
libusb_device_handle* m_handle = nullptr;
|
libusb_device_handle* m_handle = nullptr;
|
||||||
|
|
Loading…
Reference in New Issue