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 <obs.jim@gmail.com>

Closes obsproject/obs-studio#3207
This commit is contained in:
Mike 2021-03-08 18:12:12 +08:00 committed by Jim
parent 1b280e0ac4
commit e6a3d2b8f2
2 changed files with 63 additions and 0 deletions

View File

@ -1170,6 +1170,7 @@ XSplitBroadcaster="XSplit Broadcaster"
# OBS restart
Restart="Restart"
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
ContextBar.NoSelectedSource="No source selected"

View File

@ -214,6 +214,36 @@ static bool CopyProfile(const char *fromPartial, const char *to)
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,
const char *init_text, bool rename)
{
@ -558,6 +588,10 @@ void OBSBasic::on_actionRemoveProfile_triggered(bool skipConfirmation)
newName.c_str());
config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir", newDir);
QString settingsRequiringRestart;
bool needsRestart =
ProfileNeedsRestart(config, settingsRequiringRestart);
Auth::Save();
auth.reset();
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_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()
@ -714,6 +760,10 @@ void OBSBasic::ChangeProfile()
const char *newName = config_get_string(config, "General", "Name");
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", "ProfileDir", newDir);
@ -738,6 +788,18 @@ void OBSBasic::ChangeProfile()
if (api)
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()