浏览代码

UI: Don't show native popup for YouTube auth message box

The native popup has the problem that it doesn't work for links, leaving
us with an unclickable text where a link should be. Qt 6.6 has an option
to disable the native dialog, so let's add this to make the link
clickable again.

Co-authored-by: derrod <[email protected]>
gxalpha 2 年之前
父节点
当前提交
839461dc9b
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      UI/auth-youtube.cpp

+ 15 - 0
UI/auth-youtube.cpp

@@ -278,6 +278,11 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
 	dlg.setText(text);
 	dlg.setText(text);
 	dlg.setTextFormat(Qt::RichText);
 	dlg.setTextFormat(Qt::RichText);
 	dlg.setStandardButtons(QMessageBox::StandardButton::Cancel);
 	dlg.setStandardButtons(QMessageBox::StandardButton::Cancel);
+#if defined(__APPLE__) && QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
+	/* We can't show clickable links with the native NSAlert, so let's
+	 * force the old non-native dialog instead. */
+	dlg.setOption(QMessageBox::Option::DontUseNativeDialog);
+#endif
 
 
 	connect(&dlg, &QMessageBox::buttonClicked, &dlg,
 	connect(&dlg, &QMessageBox::buttonClicked, &dlg,
 		[&](QAbstractButton *) {
 		[&](QAbstractButton *) {
@@ -311,7 +316,17 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
 	QScopedPointer<QThread> thread(CreateQThread(open_external_browser));
 	QScopedPointer<QThread> thread(CreateQThread(open_external_browser));
 	thread->start();
 	thread->start();
 
 
+#if defined(__APPLE__) && QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) && \
+	QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
+	const bool nativeDialogs =
+		qApp->testAttribute(Qt::AA_DontUseNativeDialogs);
+	App()->setAttribute(Qt::AA_DontUseNativeDialogs, true);
+	dlg.exec();
+	App()->setAttribute(Qt::AA_DontUseNativeDialogs, nativeDialogs);
+#else
 	dlg.exec();
 	dlg.exec();
+#endif
+
 	if (dlg.result() == QMessageBox::Cancel ||
 	if (dlg.result() == QMessageBox::Cancel ||
 	    dlg.result() == QDialog::Rejected)
 	    dlg.result() == QDialog::Rejected)
 		return nullptr;
 		return nullptr;