macos: warn if no permission to start camera

This commit is contained in:
tobtoht 2024-01-02 21:21:34 +01:00
parent 7971d0043f
commit 3c4b01d021
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
5 changed files with 32 additions and 1 deletions

View file

@ -68,6 +68,7 @@ $(package)_config_opts += -DINPUT_libudev=no
$(package)_config_opts += -DINPUT_mtdev=no $(package)_config_opts += -DINPUT_mtdev=no
$(package)_config_opts += -DINPUT_openssl=linked $(package)_config_opts += -DINPUT_openssl=linked
$(package)_config_opts += -DINPUT_openvg=no $(package)_config_opts += -DINPUT_openvg=no
$(package)_config_opts += -DINPUT_permissions=yes
$(package)_config_opts += -DINPUT_reduce_relocations=no $(package)_config_opts += -DINPUT_reduce_relocations=no
$(package)_config_opts += -DINPUT_schannel=no $(package)_config_opts += -DINPUT_schannel=no
$(package)_config_opts += -DINPUT_sctp=no $(package)_config_opts += -DINPUT_sctp=no

View file

@ -299,6 +299,10 @@ if (WITH_SCANNER)
) )
endif() endif()
if(STATIC AND APPLE)
target_link_libraries(feather Qt6::QDarwinCameraPermissionPlugin)
endif()
if(STATIC AND UNIX AND NOT APPLE) if(STATIC AND UNIX AND NOT APPLE)
target_link_libraries(feather Qt6::QComposePlatformInputContextPlugin) target_link_libraries(feather Qt6::QComposePlatformInputContextPlugin)
endif() endif()

View file

@ -34,6 +34,10 @@ Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin) // Needed for dead keys on Linux Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin) // Needed for dead keys on Linux
#endif #endif
#if defined(Q_OS_MAC) && defined(STATIC)
Q_IMPORT_PLUGIN(QDarwinCameraPermissionPlugin)
#endif
#if defined(Q_OS_LINUX) && defined(STACK_TRACE) #if defined(Q_OS_LINUX) && defined(STACK_TRACE)
void signal_handler(int signum) { void signal_handler(int signum) {
::signal(signum, SIG_DFL); ::signal(signum, SIG_DFL);

View file

@ -4,6 +4,7 @@
#include "QrCodeScanWidget.h" #include "QrCodeScanWidget.h"
#include "ui_QrCodeScanWidget.h" #include "ui_QrCodeScanWidget.h"
#include <QPermission>
#include <QMediaDevices> #include <QMediaDevices>
#include <QComboBox> #include <QComboBox>
@ -69,6 +70,12 @@ void QrCodeScanWidget::startCapture(bool scan_ur) {
ui->progressBar_UR->setVisible(m_scan_ur); ui->progressBar_UR->setVisible(m_scan_ur);
ui->progressBar_UR->setFormat("Progress: %v%"); ui->progressBar_UR->setFormat("Progress: %v%");
if (!getPermission()) {
ui->frame_error->setText("No permission to start camera.");
ui->frame_error->show();
return;
}
if (ui->combo_camera->count() < 1) { if (ui->combo_camera->count() < 1) {
ui->frame_error->setText("No cameras found. Attach a camera and press 'Refresh'."); ui->frame_error->setText("No cameras found. Attach a camera and press 'Refresh'.");
ui->frame_error->show(); ui->frame_error->show();
@ -82,6 +89,20 @@ void QrCodeScanWidget::startCapture(bool scan_ur) {
} }
} }
bool QrCodeScanWidget::getPermission() {
QCameraPermission cameraPermission;
switch (qApp->checkPermission(cameraPermission)) {
case Qt::PermissionStatus::Undetermined:
qApp->requestPermission(cameraPermission, this,
&QrCodeScanWidget::getPermission);
return false;
case Qt::PermissionStatus::Denied:
return false;
case Qt::PermissionStatus::Granted:
return true;
}
}
void QrCodeScanWidget::reset() { void QrCodeScanWidget::reset() {
this->decodedString = ""; this->decodedString = "";
m_done = false; m_done = false;

View file

@ -49,6 +49,7 @@ private:
void refreshCameraList(); void refreshCameraList();
QImage videoFrameToImage(const QVideoFrame &videoFrame); QImage videoFrameToImage(const QVideoFrame &videoFrame);
void handleFrameCaptured(const QVideoFrame &videoFrame); void handleFrameCaptured(const QVideoFrame &videoFrame);
bool getPermission();
QScopedPointer<Ui::QrCodeScanWidget> ui; QScopedPointer<Ui::QrCodeScanWidget> ui;