Improved blocked mods dialog permissions prompt

Targeted to macOS (where `~/Downloads` is considered a sensitive location that the system protects behind a prompt even from non-sandboxed apps)

Signed-off-by: Kenneth Chew <79120643+kthchew@users.noreply.github.com>
This commit is contained in:
Kenneth Chew
2024-05-07 18:22:23 -04:00
parent 5ce8cd6b84
commit 4787141698
2 changed files with 14 additions and 2 deletions

View File

@ -40,6 +40,7 @@
#include <QMimeData>
#include <QPushButton>
#include <QStandardPaths>
#include <QTimer>
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods, QString hash_type)
: QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods), m_hash_type(hash_type)
@ -60,8 +61,13 @@ BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, cons
qDebug() << "[Blocked Mods Dialog] Mods List: " << mods;
setupWatch();
scanPaths();
// defer setup of file system watchers until after the dialog is shown
// this allows OS (namely macOS) permission prompts to show after the relevant dialog appears
QTimer::singleShot(0, this, [this] {
setupWatch();
scanPaths();
update();
});
this->setWindowTitle(title);
ui->labelDescription->setText(text);
@ -194,6 +200,10 @@ void BlockedModsDialog::setupWatch()
void BlockedModsDialog::watchPath(QString path, bool watch_recursive)
{
auto to_watch = QFileInfo(path);
if (!to_watch.isReadable()) {
qWarning() << "[Blocked Mods Dialog] Failed to add Watch Path (unable to read):" << path;
return;
}
auto to_watch_path = to_watch.canonicalFilePath();
if (m_watcher.directories().contains(to_watch_path))
return; // don't watch the same path twice (no loops!)