Skip to content

Commit

Permalink
Qt: check microphone permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Dec 30, 2023
1 parent 4752ca9 commit 4533da3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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();

fs::file make_file_view(const fs::file& file, u64 offset, u64 size);

Expand Down Expand Up @@ -1630,6 +1631,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
31 changes: 31 additions & 0 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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 @@ -95,6 +100,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

0 comments on commit 4533da3

Please sign in to comment.