config: add locale texts for initial password setup

This commit is contained in:
Stéphane Lepin 2021-01-31 00:58:56 +01:00
parent c02382b6e5
commit c8ca79f00b
2 changed files with 34 additions and 19 deletions

View File

@ -15,3 +15,7 @@ OBSWebsocket.Server.StartFailed.Message="The WebSockets server failed to start,
OBSWebsocket.ProfileChanged.Started="WebSockets server enabled in this profile. Server started." OBSWebsocket.ProfileChanged.Started="WebSockets server enabled in this profile. Server started."
OBSWebsocket.ProfileChanged.Stopped="WebSockets server disabled in this profile. Server stopped." OBSWebsocket.ProfileChanged.Stopped="WebSockets server disabled in this profile. Server stopped."
OBSWebsocket.ProfileChanged.Restarted="WebSockets server port changed in this profile. Server restarted." OBSWebsocket.ProfileChanged.Restarted="WebSockets server port changed in this profile. Server restarted."
OBSWebsocket.InitialPasswordSetup.Title="obs-websocket - Server Password Configuration"
OBSWebsocket.InitialPasswordSetup.Text="It looks like you are running obs-websocket for the first time. Do you want set a password for the WebSockets server now?"
OBSWebsocket.InitialPasswordSetup.SuccessText="Server Password set successfully."
OBSWebsocket.InitialPasswordSetup.DismissedText="You can configure a server password anytime in obs-websocket settings (under the Tools menu of OBS Studio)"

View File

@ -310,6 +310,12 @@ void Config::OnFrontendEvent(enum obs_frontend_event event, void* param)
void Config::FirstRunPasswordSetup() void Config::FirstRunPasswordSetup()
{ {
// check if the password is already set
auto config = GetConfig();
if (!(config->Secret.isEmpty()) && !(config->Salt.isEmpty())) {
return;
}
// check if we already showed the auth setup prompt to the user, independently of the current settings (tied to the current profile) // check if we already showed the auth setup prompt to the user, independently of the current settings (tied to the current profile)
config_t* globalConfig = obs_frontend_get_global_config(); config_t* globalConfig = obs_frontend_get_global_config();
bool alreadyPrompted = config_get_bool(globalConfig, SECTION_NAME, GLOBAL_AUTH_SETUP_PROMPTED); bool alreadyPrompted = config_get_bool(globalConfig, SECTION_NAME, GLOBAL_AUTH_SETUP_PROMPTED);
@ -322,29 +328,34 @@ void Config::FirstRunPasswordSetup()
config_save(globalConfig); config_save(globalConfig);
obs_frontend_push_ui_translation(obs_module_get_string); obs_frontend_push_ui_translation(obs_module_get_string);
QString initialPasswordSetupTitle = QObject::tr("OBSWebsocket.InitialPasswordSetup.Title"); QString dialogTitle = QObject::tr("OBSWebsocket.InitialPasswordSetup.Title");
QString initialPasswordSetupText = QObject::tr("OBSWebsocket.InitialPasswordSetup.Text"); QString dialogText = QObject::tr("OBSWebsocket.InitialPasswordSetup.Text");
QString setupDismissedTitle = QObject::tr("OBSWebsocket.InitialPasswordSetupDismissed.Title"); QString successText = QObject::tr("OBSWebsocket.InitialPasswordSetup.SuccessText");
QString setupDismissedText = QObject::tr("OBSWebsocket.InitialPasswordSetupDismissed.Text"); QString dismissedText = QObject::tr("OBSWebsocket.InitialPasswordSetup.DismissedText");
QString passwordLabel = QObject::tr("OBSWebsocket.Settings.Password");
obs_frontend_pop_ui_translation(); obs_frontend_pop_ui_translation();
// prompt for a password
auto mainWindow = reinterpret_cast<QMainWindow*>( auto mainWindow = reinterpret_cast<QMainWindow*>(
obs_frontend_get_main_window() obs_frontend_get_main_window()
); );
int proceed = QMessageBox::question(mainWindow, dialogTitle, dialogText, QMessageBox::No, QMessageBox::Yes);
if (proceed) {
bool promptAccepted = false; bool promptAccepted = false;
QString newPassword = QInputDialog::getText( QString newPassword = QInputDialog::getText(
mainWindow, mainWindow,
initialPasswordSetupTitle, initialPasswordSetupText, dialogTitle, passwordLabel,
QLineEdit::PasswordEchoOnEdit, QString::Null(), &promptAccepted QLineEdit::PasswordEchoOnEdit, QString::Null(), &promptAccepted
); );
if (promptAccepted) { if (promptAccepted) {
// set new password // set new password
GetConfig()->SetPassword(newPassword); GetConfig()->SetPassword(newPassword);
} else { QMessageBox::information(mainWindow, dialogTitle, successText);
// tell the user they still can set the password later in our settings dialog return;
QMessageBox::information(mainWindow, setupDismissedTitle, setupDismissedText, QMessageBox::Ok); }
}
} // tell the user they still can set the password later in our settings dialog
QMessageBox::information(mainWindow, dialogTitle, dismissedText);
} }