Browse Source

UI: Add restart message on profile change

When a profile changes settings that require a restart, show a dialog to
ask the user whether they'd like to restart.

Co-authored-by: Jim <[email protected]>

Closes obsproject/obs-studio#3207
Mike 4 years ago
parent
commit
e6a3d2b8f2
2 changed files with 63 additions and 0 deletions
  1. 1 0
      UI/data/locale/en-US.ini
  2. 62 0
      UI/window-basic-main-profiles.cpp

+ 1 - 0
UI/data/locale/en-US.ini

@@ -1170,6 +1170,7 @@ XSplitBroadcaster="XSplit Broadcaster"
 # OBS restart
 # OBS restart
 Restart="Restart"
 Restart="Restart"
 NeedsRestart="OBS Studio needs to be restarted. Do you want to restart now?"
 NeedsRestart="OBS Studio needs to be restarted. Do you want to restart now?"
+LoadProfileNeedsRestart="Profile contains settings that require restarting OBS:\n%1\n\nDo you want to restart OBS for these settings to take effect?"
 
 
 # Context Bar
 # Context Bar
 ContextBar.NoSelectedSource="No source selected"
 ContextBar.NoSelectedSource="No source selected"

+ 62 - 0
UI/window-basic-main-profiles.cpp

@@ -214,6 +214,36 @@ static bool CopyProfile(const char *fromPartial, const char *to)
 	return true;
 	return true;
 }
 }
 
 
+static bool ProfileNeedsRestart(config_t *newConfig, QString &settings)
+{
+	OBSBasic *main = OBSBasic::Get();
+
+	const char *oldSpeakers =
+		config_get_string(main->Config(), "Audio", "ChannelSetup");
+	uint oldSampleRate =
+		config_get_uint(main->Config(), "Audio", "SampleRate");
+
+	const char *newSpeakers =
+		config_get_string(newConfig, "Audio", "ChannelSetup");
+	uint newSampleRate = config_get_uint(newConfig, "Audio", "SampleRate");
+
+	auto appendSetting = [&settings](const char *name) {
+		settings += QStringLiteral("\n") + QTStr(name);
+	};
+
+	bool result = false;
+	if (oldSpeakers != NULL && newSpeakers != NULL) {
+		result = strcmp(oldSpeakers, newSpeakers) != 0;
+		appendSetting("Basic.Settings.Audio.Channels");
+	}
+	if (oldSampleRate != 0 && newSampleRate != 0) {
+		result |= oldSampleRate != newSampleRate;
+		appendSetting("Basic.Settings.Audio.SampleRate");
+	}
+
+	return result;
+}
+
 bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
 bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
 			  const char *init_text, bool rename)
 			  const char *init_text, bool rename)
 {
 {
@@ -558,6 +588,10 @@ void OBSBasic::on_actionRemoveProfile_triggered(bool skipConfirmation)
 			  newName.c_str());
 			  newName.c_str());
 	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
 	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
 
 
+	QString settingsRequiringRestart;
+	bool needsRestart =
+		ProfileNeedsRestart(config, settingsRequiringRestart);
+
 	Auth::Save();
 	Auth::Save();
 	auth.reset();
 	auth.reset();
 	DeleteCookies();
 	DeleteCookies();
@@ -583,6 +617,18 @@ void OBSBasic::on_actionRemoveProfile_triggered(bool skipConfirmation)
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
 	}
 	}
+
+	if (needsRestart) {
+		QMessageBox::StandardButton button = OBSMessageBox::question(
+			this, QTStr("Restart"),
+			QTStr("LoadProfileNeedsRestart")
+				.arg(settingsRequiringRestart));
+
+		if (button == QMessageBox::Yes) {
+			restart = true;
+			close();
+		}
+	}
 }
 }
 
 
 void OBSBasic::on_actionImportProfile_triggered()
 void OBSBasic::on_actionImportProfile_triggered()
@@ -714,6 +760,10 @@ void OBSBasic::ChangeProfile()
 	const char *newName = config_get_string(config, "General", "Name");
 	const char *newName = config_get_string(config, "General", "Name");
 	const char *newDir = strrchr(path.c_str(), '/') + 1;
 	const char *newDir = strrchr(path.c_str(), '/') + 1;
 
 
+	QString settingsRequiringRestart;
+	bool needsRestart =
+		ProfileNeedsRestart(config, settingsRequiringRestart);
+
 	config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName);
 	config_set_string(App()->GlobalConfig(), "Basic", "Profile", newName);
 	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
 	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
 
 
@@ -738,6 +788,18 @@ void OBSBasic::ChangeProfile()
 
 
 	if (api)
 	if (api)
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
 		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
+
+	if (needsRestart) {
+		QMessageBox::StandardButton button = OBSMessageBox::question(
+			this, QTStr("Restart"),
+			QTStr("LoadProfileNeedsRestart")
+				.arg(settingsRequiringRestart));
+
+		if (button == QMessageBox::Yes) {
+			restart = true;
+			close();
+		}
+	}
 }
 }
 
 
 void OBSBasic::CheckForSimpleModeX264Fallback()
 void OBSBasic::CheckForSimpleModeX264Fallback()