Skip to content

Commit

Permalink
Merge pull request obsproject#2408 from cg2121/restart-app
Browse files Browse the repository at this point in the history
UI: Restart program when audio/locale changed
  • Loading branch information
jp9000 authored Feb 18, 2020
2 parents fe092d1 + e013582 commit 4d0b3ef
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1014,4 +1014,8 @@ Importer.AutomaticCollectionText="OBS can automatically find importable scene co
OBSStudio="OBS Studio"
OBSClassic="OBS Classic"
Streamlabs="Streamlabs"
XSplitBroadcaster="XSplit Broadcaster"
XSplitBroadcaster="XSplit Broadcaster"

# OBS restart
Restart="Restart"
NeedsRestart="OBS Studio needs to be restarted. Do you want to restart now?"
13 changes: 10 additions & 3 deletions UI/obs-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QGuiApplication>
#include <QProxyStyle>
#include <QScreen>
#include <QProcess>

#include "qt-wrappers.hpp"
#include "obs-app.hpp"
Expand Down Expand Up @@ -83,6 +84,8 @@ string opt_starting_scene;
bool remuxAfterRecord = false;
string remuxFilename;

bool restart = false;

// GPU hint exports for AMD/NVIDIA laptops
#ifdef _MSC_VER
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 1;
Expand Down Expand Up @@ -1806,7 +1809,7 @@ static int run_program(fstream &logFile, int argc, char *argv[])
}

if (cancel_launch)
return 0;
ret = 0;

if (!created_log) {
create_log_file(logFile);
Expand Down Expand Up @@ -1844,17 +1847,21 @@ static int run_program(fstream &logFile, int argc, char *argv[])
}

if (!program.OBSInit())
return 0;
ret = 0;

prof.Stop();

return program.exec();
ret = program.exec();

} catch (const char *error) {
blog(LOG_ERROR, "%s", error);
OBSErrorBox(nullptr, "%s", error);
}

if (restart)
QProcess::startDetached(qApp->arguments()[0],
qApp->arguments());

return ret;
}

Expand Down
1 change: 1 addition & 0 deletions UI/obs-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,4 @@ extern bool opt_studio_mode;
extern bool opt_allow_opengl;
extern bool opt_always_on_top;
extern std::string opt_starting_scene;
extern bool restart;
11 changes: 11 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,7 @@ void OBSBasic::closeEvent(QCloseEvent *event)

if (button == QMessageBox::No) {
event->ignore();
restart = false;
return;
}
}
Expand Down Expand Up @@ -4046,6 +4047,16 @@ void OBSBasic::on_action_Settings_triggered()
SystemTray(false);

settings_already_executing = false;

if (restart) {
QMessageBox::StandardButton button = OBSMessageBox::question(
this, QTStr("Restart"), QTStr("NeedsRestart"));

if (button == QMessageBox::Yes)
close();
else
restart = false;
}
}

void OBSBasic::on_actionAdvAudioProperties_triggered()
Expand Down
20 changes: 20 additions & 0 deletions UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,11 @@ void OBSBasicSettings::LoadGeneralSettings()
ui->multiviewLayout->setCurrentIndex(config_get_int(
GetGlobalConfig(), "BasicWindow", "MultiviewLayout"));

prevLangIndex = ui->language->currentIndex();

if (obs_video_active())
ui->language->setEnabled(false);

loading = false;
}

Expand Down Expand Up @@ -2121,6 +2126,11 @@ void OBSBasicSettings::LoadAudioDevices()
LoadListValues(ui->desktopAudioDevice2, outputs, 2);
obs_properties_destroy(output_props);
}

if (obs_video_active()) {
ui->sampleRate->setEnabled(false);
ui->channelSetup->setEnabled(false);
}
}

#define NBSP "\xC2\xA0"
Expand Down Expand Up @@ -3514,6 +3524,15 @@ void OBSBasicSettings::SaveSettings()
blog(LOG_INFO, "Settings changed (%s)", changed.c_str());
blog(LOG_INFO, MINOR_SEPARATOR);
}

bool langChanged = (ui->language->currentIndex() != prevLangIndex);
bool audioRestart = (ui->channelSetup->currentIndex() != channelIndex ||
ui->sampleRate->currentIndex() != sampleRateIndex);

if (langChanged || audioRestart)
restart = true;
else
restart = false;
}

bool OBSBasicSettings::QueryChanges()
Expand All @@ -3535,6 +3554,7 @@ bool OBSBasicSettings::QueryChanges()
if (toggleAero)
SetAeroEnabled(!aeroWasDisabled);
#endif
restart = false;
}

ClearChanged();
Expand Down
1 change: 1 addition & 0 deletions UI/window-basic-settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class OBSBasicSettings : public QDialog {
void OnOAuthStreamKeyConnected();
void OnAuthConnected();
QString lastService;
int prevLangIndex;
private slots:
void UpdateServerList();
void UpdateKeyLink();
Expand Down

0 comments on commit 4d0b3ef

Please sign in to comment.