mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 04:42:18 +02:00
Add basic update checking
This commit is contained in:
parent
f801348a33
commit
4e7f076c68
@ -56,6 +56,10 @@ LicenseAgreement.ClickIAgreeToContinue="If you accept the terms of the agreement
|
||||
LicenseAgreement.IAgree="I Agree"
|
||||
LicenseAgreement.Exit="Exit"
|
||||
|
||||
# update dialog
|
||||
UpdateAvailable="New Update Available"
|
||||
UpdateAvailable.Text="Version %1.%2.%3 is now available. <a href='%4'>Click here to download</a>"
|
||||
|
||||
# audio device names
|
||||
Basic.DesktopDevice1="Desktop Audio"
|
||||
Basic.DesktopDevice2="Desktop Audio 2"
|
||||
@ -164,6 +168,7 @@ Basic.MainMenu.Help="&Help"
|
||||
Basic.MainMenu.Help.Logs="&Log Files"
|
||||
Basic.MainMenu.Help.Logs.UploadCurrentLog="Upload &Current Log File"
|
||||
Basic.MainMenu.Help.Logs.UploadLastLog="Upload &Last Log File"
|
||||
Basic.MainMenu.Help.CheckForUpdates="Check For Updates"
|
||||
|
||||
# basic mode settings dialog
|
||||
Basic.Settings.ProgramRestart="The program must be restarted for these settings to take effect."
|
||||
|
@ -468,6 +468,7 @@
|
||||
<addaction name="actionUploadLastLog"/>
|
||||
</widget>
|
||||
<addaction name="menuLogFiles"/>
|
||||
<addaction name="actionCheckForUpdates"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuBasic_MainMenu_Edit">
|
||||
<property name="title">
|
||||
@ -768,6 +769,11 @@
|
||||
<string>Ctrl+End</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCheckForUpdates">
|
||||
<property name="text">
|
||||
<string>Basic.MainMenu.Help.CheckForUpdates</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -16,6 +16,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
#include <time.h>
|
||||
#include <obs.hpp>
|
||||
#include <QMessageBox>
|
||||
#include <QShowEvent>
|
||||
@ -551,6 +552,7 @@ void OBSBasic::OBSInit()
|
||||
Load(savePath);
|
||||
ResetAudioDevices();
|
||||
|
||||
TimedCheckForUpdates();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
@ -831,6 +833,101 @@ bool OBSBasic::QueryRemoveSource(obs_source_t source)
|
||||
return button == QMessageBox::Yes;
|
||||
}
|
||||
|
||||
#define UPDATE_CHECK_INTERVAL (60*60*24*4) /* 4 days */
|
||||
|
||||
void OBSBasic::TimedCheckForUpdates()
|
||||
{
|
||||
long long lastUpdate = config_get_int(App()->GlobalConfig(), "General",
|
||||
"LastUpdateCheck");
|
||||
uint32_t lastVersion = config_get_int(App()->GlobalConfig(), "General",
|
||||
"LastVersion");
|
||||
|
||||
if (lastVersion < LIBOBS_API_VER) {
|
||||
lastUpdate = 0;
|
||||
config_set_int(App()->GlobalConfig(), "General",
|
||||
"LastUpdateCheck", 0);
|
||||
}
|
||||
|
||||
long long t = (long long)time(nullptr);
|
||||
long long secs = t - lastUpdate;
|
||||
|
||||
if (secs > UPDATE_CHECK_INTERVAL)
|
||||
CheckForUpdates();
|
||||
}
|
||||
|
||||
void OBSBasic::CheckForUpdates()
|
||||
{
|
||||
ui->actionCheckForUpdates->setEnabled(false);
|
||||
|
||||
QUrl url("https://obsproject.com/obs2_update/mac_basic.json");
|
||||
updateReply = networkManager.get(QNetworkRequest(url));
|
||||
connect(updateReply, SIGNAL(finished()),
|
||||
this, SLOT(updateFileFinished()));
|
||||
connect(updateReply, SIGNAL(readyRead()),
|
||||
this, SLOT(updateFileRead()));
|
||||
}
|
||||
|
||||
void OBSBasic::updateFileRead()
|
||||
{
|
||||
updateReturnData.push_back(updateReply->readAll());
|
||||
}
|
||||
|
||||
void OBSBasic::updateFileFinished()
|
||||
{
|
||||
ui->actionCheckForUpdates->setEnabled(true);
|
||||
|
||||
if (updateReply->error()) {
|
||||
blog(LOG_WARNING, "Update check failed: %s",
|
||||
QT_TO_UTF8(updateReply->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
const char *jsonReply = updateReturnData.constData();
|
||||
if (!jsonReply || !*jsonReply)
|
||||
return;
|
||||
|
||||
obs_data_t returnData = obs_data_create_from_json(jsonReply);
|
||||
obs_data_t versionData = obs_data_getobj(returnData, "version");
|
||||
const char *description = obs_data_getstring(returnData, "description");
|
||||
const char *download = obs_data_getstring(returnData, "download");
|
||||
|
||||
if (returnData && versionData && description && download) {
|
||||
long major = obs_data_getint(versionData, "major");
|
||||
long minor = obs_data_getint(versionData, "minor");
|
||||
long patch = obs_data_getint(versionData, "patch");
|
||||
long version = MAKE_SEMANTIC_VERSION(major, minor, patch);
|
||||
|
||||
blog(LOG_INFO, "Update check: latest version is: %ld.%ld.%ld",
|
||||
major, minor, patch);
|
||||
|
||||
if (version > LIBOBS_API_VER) {
|
||||
QString str = QTStr("UpdateAvailable.Text");
|
||||
QMessageBox messageBox(this);
|
||||
|
||||
str = str.arg(QString::number(major),
|
||||
QString::number(minor),
|
||||
QString::number(patch),
|
||||
download);
|
||||
|
||||
messageBox.setWindowTitle(QTStr("UpdateAvailable"));
|
||||
messageBox.setTextFormat(Qt::RichText);
|
||||
messageBox.setText(str);
|
||||
messageBox.setInformativeText(QT_UTF8(description));
|
||||
messageBox.exec();
|
||||
|
||||
long long t = (long long)time(nullptr);
|
||||
config_set_int(App()->GlobalConfig(), "General",
|
||||
"LastUpdateCheck", t);
|
||||
config_save(App()->GlobalConfig());
|
||||
}
|
||||
} else {
|
||||
blog(LOG_WARNING, "Bad JSON file received from server");
|
||||
}
|
||||
|
||||
obs_data_release(versionData);
|
||||
obs_data_release(returnData);
|
||||
}
|
||||
|
||||
void OBSBasic::RemoveSelectedScene()
|
||||
{
|
||||
OBSScene scene = GetCurrentScene();
|
||||
@ -1626,6 +1723,11 @@ void OBSBasic::on_actionUploadLastLog_triggered()
|
||||
UploadLog(App()->GetLastLog());
|
||||
}
|
||||
|
||||
void OBSBasic::on_actionCheckForUpdates_triggered()
|
||||
{
|
||||
CheckForUpdates();
|
||||
}
|
||||
|
||||
void OBSBasic::logUploadRead()
|
||||
{
|
||||
logUploadReturnData.push_back(logUploadReply->readAll());
|
||||
|
@ -69,6 +69,10 @@ private:
|
||||
QNetworkReply *logUploadReply = nullptr;
|
||||
QByteArray logUploadReturnData;
|
||||
|
||||
QBuffer updatePostData;
|
||||
QNetworkReply *updateReply = nullptr;
|
||||
QByteArray updateReturnData;
|
||||
|
||||
obs_output_t fileOutput = nullptr;
|
||||
obs_output_t streamOutput = nullptr;
|
||||
obs_service_t service = nullptr;
|
||||
@ -120,6 +124,9 @@ private:
|
||||
|
||||
bool QueryRemoveSource(obs_source_t source);
|
||||
|
||||
void TimedCheckForUpdates();
|
||||
void CheckForUpdates();
|
||||
|
||||
void GetFPSCommon(uint32_t &num, uint32_t &den) const;
|
||||
void GetFPSInteger(uint32_t &num, uint32_t &den) const;
|
||||
void GetFPSFraction(uint32_t &num, uint32_t &den) const;
|
||||
@ -221,6 +228,7 @@ private slots:
|
||||
void on_action_Settings_triggered();
|
||||
void on_actionUploadCurrentLog_triggered();
|
||||
void on_actionUploadLastLog_triggered();
|
||||
void on_actionCheckForUpdates_triggered();
|
||||
|
||||
void on_actionEditTransform_triggered();
|
||||
void on_actionResetTransform_triggered();
|
||||
@ -262,6 +270,9 @@ private slots:
|
||||
void logUploadRead();
|
||||
void logUploadFinished();
|
||||
|
||||
void updateFileRead();
|
||||
void updateFileFinished();
|
||||
|
||||
void AddSourceFromAction();
|
||||
|
||||
void EditSceneName();
|
||||
|
Loading…
Reference in New Issue
Block a user