Преглед изворни кода

UI: Do not display threaded message boxes on startup

The message boxes that tell you that the browser is initializing or that
you're authenticating with twitch are annoying on startup.  It makes
sense to do it in the settings/autoconfig dialogs where you sort of need
to know what's going on while waiting for it to connect, but on startup
it's not really necessary and can be kind of annoying.
jp9000 пре 6 година
родитељ
комит
01c78bffc5

+ 3 - 3
UI/auth-mixer.cpp

@@ -83,7 +83,7 @@ try {
 					5);
 		};
 
-		ExecuteFuncSafeBlockMsgBox(
+		ExecThreadedWithoutBlocking(
 				func,
 				QTStr("Auth.LoadingChannel.Title"),
 				QTStr("Auth.LoadingChannel.Text").arg(service()));
@@ -126,7 +126,7 @@ try {
 				5);
 	};
 
-	ExecuteFuncSafeBlockMsgBox(
+	ExecThreadedWithoutBlocking(
 			func,
 			QTStr("Auth.LoadingChannel.Title"),
 			QTStr("Auth.LoadingChannel.Text").arg(service()));
@@ -205,7 +205,7 @@ void MixerAuth::LoadUI()
 	if (!GetChannelInfo())
 		return;
 
-	OBSBasic::InitBrowserPanelSafeBlock(true);
+	OBSBasic::InitBrowserPanelSafeBlock();
 	OBSBasic *main = OBSBasic::Get();
 
 	std::string url;

+ 2 - 2
UI/auth-oauth.cpp

@@ -34,7 +34,7 @@ OAuthLogin::OAuthLogin(QWidget *parent, const std::string &url, bool token)
 	Qt::WindowFlags helpFlag = Qt::WindowContextHelpButtonHint;
 	setWindowFlags(flags & (~helpFlag));
 
-	OBSBasic::InitBrowserPanelSafeBlock(true);
+	OBSBasic::InitBrowserPanelSafeBlock();
 
 	cefWidget = cef->create_widget(nullptr, url, panel_cookies);
 	if (!cefWidget) {
@@ -216,7 +216,7 @@ try {
 				5);
 	};
 
-	ExecuteFuncSafeBlockMsgBox(
+	ExecThreadedWithoutBlocking(
 			func,
 			QTStr("Auth.Authing.Title"),
 			QTStr("Auth.Authing.Text").arg(service()));

+ 2 - 2
UI/auth-twitch.cpp

@@ -90,7 +90,7 @@ try {
 				5);
 	};
 
-	ExecuteFuncSafeBlockMsgBox(
+	ExecThreadedWithoutBlocking(
 			func,
 			QTStr("Auth.LoadingChannel.Title"),
 			QTStr("Auth.LoadingChannel.Text").arg(service()));
@@ -191,7 +191,7 @@ void TwitchAuth::LoadUI()
 	if (!GetChannelInfo())
 		return;
 
-	OBSBasic::InitBrowserPanelSafeBlock(true);
+	OBSBasic::InitBrowserPanelSafeBlock();
 	OBSBasic *main = OBSBasic::Get();
 
 	QCefWidget *browser;

+ 18 - 0
UI/qt-wrappers.cpp

@@ -263,3 +263,21 @@ void ExecuteFuncSafeBlockMsgBox(
 	dlg.exec();
 	thread->wait();
 }
+
+static bool enable_message_boxes = false;
+
+void EnableThreadedMessageBoxes(bool enable)
+{
+	enable_message_boxes = enable;
+}
+
+void ExecThreadedWithoutBlocking(
+		std::function<void()> func,
+		const QString &title,
+		const QString &text)
+{
+	if (!enable_message_boxes)
+		ExecuteFuncSafeBlock(func);
+	else
+		ExecuteFuncSafeBlockMsgBox(func, title, text);
+}

+ 8 - 0
UI/qt-wrappers.hpp

@@ -73,6 +73,14 @@ void ExecuteFuncSafeBlockMsgBox(
 		const QString &title,
 		const QString &text);
 
+/* allows executing without message boxes if starting up, otherwise with a
+ * message box */
+void EnableThreadedMessageBoxes(bool enable);
+void ExecThreadedWithoutBlocking(
+		std::function<void()> func,
+		const QString &title,
+		const QString &text);
+
 class SignalBlocker {
 	QWidget *widget;
 	bool blocked;

+ 3 - 0
UI/window-basic-auto-config.cpp

@@ -709,6 +709,8 @@ void AutoConfigStreamPage::UpdateCompleted()
 AutoConfig::AutoConfig(QWidget *parent)
 	: QWizard(parent)
 {
+	EnableThreadedMessageBoxes(true);
+
 	calldata_t cd = {0};
 	calldata_set_int(&cd, "seconds", 5);
 
@@ -839,6 +841,7 @@ AutoConfig::~AutoConfig()
 {
 	OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());
 	main->EnableOutputs(true);
+	EnableThreadedMessageBoxes(false);
 }
 
 void AutoConfig::TestHardwareEncoding()

+ 5 - 10
UI/window-basic-main-browser.cpp

@@ -145,7 +145,7 @@ void DuplicateCurrentCookieProfile(ConfigFile &config)
 #endif
 }
 
-void OBSBasic::InitBrowserPanelSafeBlock(bool showDialog)
+void OBSBasic::InitBrowserPanelSafeBlock()
 {
 #ifdef BROWSER_AVAILABLE
 	if (!cef)
@@ -155,15 +155,10 @@ void OBSBasic::InitBrowserPanelSafeBlock(bool showDialog)
 		return;
 	}
 
-	if (showDialog)
-		ExecuteFuncSafeBlockMsgBox(
-				[] {cef->wait_for_browser_init();},
-				QTStr("BrowserPanelInit.Title"),
-				QTStr("BrowserPanelInit.Text"));
-	else
-		ExecuteFuncSafeBlock(
-				[] {cef->wait_for_browser_init();});
-
+	ExecThreadedWithoutBlocking(
+			[] {cef->wait_for_browser_init();},
+			QTStr("BrowserPanelInit.Title"),
+			QTStr("BrowserPanelInit.Text"));
 	InitPanelCookieManager();
 #else
 	UNUSED_PARAMETER(showDialog);

+ 1 - 1
UI/window-basic-main.hpp

@@ -804,7 +804,7 @@ public:
 	virtual int GetProfilePath(char *path, size_t size, const char *file)
 		const override;
 
-	static void InitBrowserPanelSafeBlock(bool showDialog);
+	static void InitBrowserPanelSafeBlock();
 
 private:
 	std::unique_ptr<Ui::OBSBasic> ui;

+ 4 - 0
UI/window-basic-settings.cpp

@@ -280,6 +280,8 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 {
 	string path;
 
+	EnableThreadedMessageBoxes(true);
+
 	ui->setupUi(this);
 
 	setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
@@ -735,6 +737,8 @@ OBSBasicSettings::~OBSBasicSettings()
 	delete ui->filenameFormatting->completer();
 	main->EnableOutputs(true);
 	App()->EnableInFocusHotkeys(!disableHotkeysInFocus);
+
+	EnableThreadedMessageBoxes(false);
 }
 
 void OBSBasicSettings::SaveCombo(QComboBox *widget, const char *section,