Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: ask for camera and microphone permissions #14798

Merged
merged 3 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const
extern bool ppu_load_rel_exec(const ppu_rel_object&);

extern void send_close_home_menu_cmds();
extern void check_microphone_permissions();

extern void signal_system_cache_can_stay();

Expand Down Expand Up @@ -1722,6 +1723,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,
return game_boot_result::no_errors;
}

// Check microphone permissions
if (g_cfg.audio.microphone_type != microphone_handler::null)
{
if (const std::vector<std::string> device_list = fmt::split(g_cfg.audio.microphone_devices.to_string(), {"@@@"}); !device_list.empty())
{
check_microphone_permissions();
}
}

// Detect boot location
const std::string hdd0_game = vfs::get("/dev_hdd0/game/");
const bool from_hdd0_game = IsPathInsideDir(m_path, hdd0_game);
Expand Down
25 changes: 25 additions & 0 deletions rpcs3/rpcs3qt/camera_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <QMessageBox>
#include <QPushButton>

#if QT_CONFIG(permissions)
#include <QPermissions>
#endif

LOG_CHANNEL(camera_log, "Camera");

template <>
Expand Down Expand Up @@ -226,6 +230,27 @@ void camera_settings_dialog::handle_settings_change(int index)
return;
}

#if QT_CONFIG(permissions)
QCameraPermission permission;
switch (qApp->checkPermission(permission))
{
case Qt::PermissionStatus::Undetermined:
camera_log.notice("Requesting camera permission");
qApp->requestPermission(permission, this, [this, index]()
{
handle_settings_change(index);
});
return;
case Qt::PermissionStatus::Denied:
camera_log.error("RPCS3 has no permissions to access cameras on this device.");
QMessageBox::warning(this, tr("Camera permissions denied!"), tr("RPCS3 has no permissions to access cameras on this device."));
return;
case Qt::PermissionStatus::Granted:
camera_log.notice("Camera permission granted");
break;
}
#endif

if (index >= 0 && ui->combo_settings->itemData(index).canConvert<QCameraFormat>() && ui->combo_camera->currentData().canConvert<QCameraDevice>())
{
const QCameraFormat setting = ui->combo_settings->itemData(index).value<QCameraFormat>();
Expand Down
31 changes: 31 additions & 0 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@

#include "ui_main_window.h"

#if QT_CONFIG(permissions)
#include <QGuiApplication>
#include <QPermissions>
#endif

LOG_CHANNEL(gui_log, "GUI");

extern atomic_t<bool> g_user_asked_for_frame_capture;
Expand All @@ -102,6 +107,32 @@ extern void process_qt_events()
}
}

extern void check_microphone_permissions()
{
#if QT_CONFIG(permissions)
Emu.BlockingCallFromMainThread([]()
{
QMicrophonePermission permission;
switch (qApp->checkPermission(permission))
{
case Qt::PermissionStatus::Undetermined:
gui_log.notice("Requesting microphone permission");
qApp->requestPermission(permission, []()
{
check_microphone_permissions();
});
break;
case Qt::PermissionStatus::Denied:
gui_log.error("RPCS3 has no permissions to access microphones on this device.");
break;
case Qt::PermissionStatus::Granted:
gui_log.notice("Microphone permission granted");
break;
}
});
#endif
}

main_window::main_window(std::shared_ptr<gui_settings> gui_settings, std::shared_ptr<emu_settings> emu_settings, std::shared_ptr<persistent_settings> persistent_settings, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::main_window)
Expand Down
25 changes: 25 additions & 0 deletions rpcs3/rpcs3qt/qt_camera_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

#include <QMediaDevices>

#if QT_CONFIG(permissions)
#include <QGuiApplication>
#include <QPermissions>
#endif

LOG_CHANNEL(camera_log, "Camera");

qt_camera_handler::qt_camera_handler() : camera_handler_base()
Expand Down Expand Up @@ -180,6 +185,26 @@ void qt_camera_handler::start_camera()
return;
}

#if QT_CONFIG(permissions)
QCameraPermission permission;
switch (qApp->checkPermission(permission))
{
case Qt::PermissionStatus::Undetermined:
camera_log.notice("Requesting camera permission");
qApp->requestPermission(permission, [this]()
{
start_camera();
});
return;
case Qt::PermissionStatus::Denied:
camera_log.error("RPCS3 has no permissions to access cameras on this device.");
return;
case Qt::PermissionStatus::Granted:
camera_log.notice("Camera permission granted");
break;
}
#endif

// Start camera. We will start receiving frames now.
m_camera->start();
}
Expand Down