diff --git a/.appveyor/install.bat b/.appveyor/install.bat index c04b4e2a9..e04e29ea8 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -56,10 +56,6 @@ GOTO:EOF call:logInfo "Build version: %BUILD_VERSION%" set TDESKTOP_BUILD_DEFINES= - echo %BUILD_VERSION% | findstr /C:"disable_autoupdate">nul && ( - set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_AUTOUPDATE - ) - echo %BUILD_VERSION% | findstr /C:"disable_register_custom_scheme">nul && ( set TDESKTOP_BUILD_DEFINES=%TDESKTOP_BUILD_DEFINES%,TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME ) diff --git a/.travis.yml b/.travis.yml index 965c188db..7d3f36b6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ cache: env: matrix: - BUILD_VERSION="" - - BUILD_VERSION="disable_autoupdate" - BUILD_VERSION="disable_register_custom_scheme" - BUILD_VERSION="disable_crash_reports" - BUILD_VERSION="disable_network_proxy" diff --git a/.travis/build.sh b/.travis/build.sh index 4a274a8e8..cacd2bd81 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -100,10 +100,6 @@ build() { fi # Configure the build - if [[ $BUILD_VERSION == *"disable_autoupdate"* ]]; then - GYP_DEFINES+=",TDESKTOP_DISABLE_AUTOUPDATE" - fi - if [[ $BUILD_VERSION == *"disable_register_custom_scheme"* ]]; then GYP_DEFINES+=",TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME" fi diff --git a/Telegram/SourceFiles/_other/updater.cpp b/Telegram/SourceFiles/_other/updater.cpp index 47d5c87d0..1679195c1 100644 --- a/Telegram/SourceFiles/_other/updater.cpp +++ b/Telegram/SourceFiles/_other/updater.cpp @@ -339,7 +339,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara LPWSTR *args; int argsCount; - bool needupdate = false, autostart = false, debug = false, writeprotected = false, startintray = false, testmode = false; + bool needupdate = false, autostart = false, debug = false, writeprotected = false, startintray = false, testmode = false, externalupdater = false; args = CommandLineToArgvW(GetCommandLine(), &argsCount); if (args) { for (int i = 1; i < argsCount; ++i) { @@ -355,6 +355,8 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara startintray = true; } else if (equal(args[i], L"-testmode")) { testmode = true; + } else if (equal(args[i], L"-externalupdater")) { + externalupdater = true; } else if (equal(args[i], L"-writeprotected") && ++i < argsCount) { writeLog(std::wstring(L"Argument: ") + args[i]); writeprotected = true; @@ -425,6 +427,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdPara if (debug) targs += L" -debug"; if (startintray) targs += L" -startintray"; if (testmode) targs += L" -testmode"; + if (externalupdater) targs += L" -externalupdater"; if (!customWorkingDir.empty()) { targs += L" -workdir \"" + customWorkingDir + L"\""; } diff --git a/Telegram/SourceFiles/_other/updater_linux.cpp b/Telegram/SourceFiles/_other/updater_linux.cpp index 4dfd8e31e..869e937b8 100644 --- a/Telegram/SourceFiles/_other/updater_linux.cpp +++ b/Telegram/SourceFiles/_other/updater_linux.cpp @@ -337,6 +337,7 @@ int main(int argc, char *argv[]) { bool tosettings = false; bool startintray = false; bool testmode = false; + bool externalupdater = false; bool customWorkingDir = false; char *key = 0; @@ -352,6 +353,8 @@ int main(int argc, char *argv[]) { startintray = true; } else if (equal(argv[i], "-testmode")) { testmode = true; + } else if (equal(argv[i], "-externalupdater")) { + externalupdater = true; } else if (equal(argv[i], "-tosettings")) { tosettings = true; } else if (equal(argv[i], "-workdir_custom")) { @@ -450,6 +453,7 @@ int main(int argc, char *argv[]) { char p_key[] = "-key"; char p_startintray[] = "-startintray"; char p_testmode[] = "-testmode"; + char p_externalupdater[] = "-externalupdater"; char p_workdir[] = "-workdir"; int argIndex = 0; args[argIndex++] = path; @@ -458,6 +462,7 @@ int main(int argc, char *argv[]) { if (debug) args[argIndex++] = p_debug; if (startintray) args[argIndex++] = p_startintray; if (testmode) args[argIndex++] = p_testmode; + if (externalupdater) args[argIndex++] = p_externalupdater; if (tosettings) args[argIndex++] = p_tosettings; if (key) { args[argIndex++] = p_key; diff --git a/Telegram/SourceFiles/_other/updater_osx.m b/Telegram/SourceFiles/_other/updater_osx.m index 0d068948e..7431908f7 100644 --- a/Telegram/SourceFiles/_other/updater_osx.m +++ b/Telegram/SourceFiles/_other/updater_osx.m @@ -75,7 +75,7 @@ int main(int argc, const char * argv[]) { openLog(); pid_t procId = 0; - BOOL update = YES, toSettings = NO, autoStart = NO, startInTray = NO, testMode = NO; + BOOL update = YES, toSettings = NO, autoStart = NO, startInTray = NO, testMode = NO, externalUpdater = NO; BOOL customWorkingDir = NO; NSString *key = nil; for (int i = 0; i < argc; ++i) { @@ -101,6 +101,8 @@ int main(int argc, const char * argv[]) { startInTray = YES; } else if ([@"-testmode" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) { testMode = YES; + } else if ([@"-externalupdater" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) { + externalUpdater = YES; } else if ([@"-workdir_custom" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) { customWorkingDir = YES; } else if ([@"-key" isEqualToString:[NSString stringWithUTF8String:argv[i]]]) { @@ -235,6 +237,7 @@ int main(int argc, const char * argv[]) { if (_debug) [args addObject:@"-debug"]; if (startInTray) [args addObject:@"-startintray"]; if (testMode) [args addObject:@"-testmode"]; + if (externalUpdater) [args addObject:@"-externalupdater"]; if (autoStart) [args addObject:@"-autostart"]; if (key) { [args addObject:@"-key"]; diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 056d24483..3bb639793 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1623,11 +1623,9 @@ namespace App { } void restart() { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - bool updateReady = (Core::UpdateChecker().state() == Core::UpdateChecker::State::Ready); -#else // !TDESKTOP_DISABLE_AUTOUPDATE - bool updateReady = false; -#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE + using namespace Core; + const auto updateReady = !UpdaterDisabled() + && (UpdateChecker().state() == UpdateChecker::State::Ready); if (updateReady) { cSetRestartingUpdate(true); } else { diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 919148700..3b5c5f91e 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -91,10 +91,9 @@ Application::Application( char **argv) : QApplication(argc, argv) , _launcher(launcher) -#ifndef TDESKTOP_DISABLE_AUTOUPDATE -, _updateChecker(std::make_unique()) -#endif // TDESKTOP_DISABLE_AUTOUPDATE -{ +, _updateChecker(Core::UpdaterDisabled() + ? nullptr + : std::make_unique()) { const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath()); char h[33] = { 0 }; hashMd5Hex(d.constData(), d.size(), h); @@ -204,13 +203,13 @@ void Application::socketError(QLocalSocket::LocalSocketError e) { } #endif // !Q_OS_WINRT -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - if (!cNoStartUpdate() && Core::checkReadyUpdate()) { + if (!Core::UpdaterDisabled() + && !cNoStartUpdate() + && Core::checkReadyUpdate()) { cSetRestartingUpdate(true); DEBUG_LOG(("Application Info: installing update instead of starting app...")); return App::quit(); } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE singleInstanceChecked(); } @@ -384,9 +383,7 @@ void Application::closeApplication() { _localSocket.close(); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE _updateChecker = nullptr; -#endif // !TDESKTOP_DISABLE_AUTOUPDATE } inline Application *application() { diff --git a/Telegram/SourceFiles/application.h b/Telegram/SourceFiles/application.h index d3ce02e5a..f047f8bd4 100644 --- a/Telegram/SourceFiles/application.h +++ b/Telegram/SourceFiles/application.h @@ -61,9 +61,7 @@ private: void singleInstanceChecked(); private: -#ifndef TDESKTOP_DISABLE_AUTOUPDATE std::unique_ptr _updateChecker; -#endif // !TDESKTOP_DISABLE_AUTOUPDATE }; diff --git a/Telegram/SourceFiles/core/crash_report_window.cpp b/Telegram/SourceFiles/core/crash_report_window.cpp index c43ab21f1..2baa03ad3 100644 --- a/Telegram/SourceFiles/core/crash_report_window.cpp +++ b/Telegram/SourceFiles/core/crash_report_window.cpp @@ -194,6 +194,11 @@ void NotStartedWindow::resizeEvent(QResizeEvent *e) { _close.setGeometry(width() - padding - _close.width(), height() - padding - _close.height(), _close.width(), _close.height()); } +LastCrashedWindow::UpdaterData::UpdaterData(QWidget *buttonParent) +: check(buttonParent) +, skip(buttonParent, false) { +} + LastCrashedWindow::LastCrashedWindow() : _port(80) , _label(this) @@ -218,11 +223,9 @@ LastCrashedWindow::LastCrashedWindow() , _sendingTotal(0) , _checkReply(0) , _sendReply(0) -#ifndef TDESKTOP_DISABLE_AUTOUPDATE -, _updatingCheck(this) -, _updatingSkip(this, false) -#endif // !TDESKTOP_DISABLE_AUTOUPDATE -{ +, _updaterData(Core::UpdaterDisabled() + ? nullptr + : std::make_unique(this)) { excludeReportUsername(); if (!cAlphaVersion() && !cBetaVersion()) { // currently accept crash reports only from testers @@ -293,49 +296,49 @@ LastCrashedWindow::LastCrashedWindow() _label.setText(qsl("Last time Telegram Desktop crashed :(")); } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - _updatingCheck.setText(qsl("TRY AGAIN")); - connect(&_updatingCheck, SIGNAL(clicked()), this, SLOT(onUpdateRetry())); - _updatingSkip.setText(qsl("SKIP")); - connect(&_updatingSkip, SIGNAL(clicked()), this, SLOT(onUpdateSkip())); + if (_updaterData) { + _updaterData->check.setText(qsl("TRY AGAIN")); + connect(&_updaterData->check, SIGNAL(clicked()), this, SLOT(onUpdateRetry())); + _updaterData->skip.setText(qsl("SKIP")); + connect(&_updaterData->skip, SIGNAL(clicked()), this, SLOT(onUpdateSkip())); - Core::UpdateChecker checker; - using Progress = Core::UpdateChecker::Progress; - checker.checking( - ) | rpl::start_with_next([=] { onUpdateChecking(); }, _lifetime); - checker.isLatest( - ) | rpl::start_with_next([=] { onUpdateLatest(); }, _lifetime); - checker.progress( - ) | rpl::start_with_next([=](const Progress &result) { - onUpdateDownloading(result.already, result.size); - }, _lifetime); - checker.failed( - ) | rpl::start_with_next([=] { onUpdateFailed(); }, _lifetime); - checker.ready( - ) | rpl::start_with_next([=] { onUpdateReady(); }, _lifetime); + Core::UpdateChecker checker; + using Progress = Core::UpdateChecker::Progress; + checker.checking( + ) | rpl::start_with_next([=] { onUpdateChecking(); }, _lifetime); + checker.isLatest( + ) | rpl::start_with_next([=] { onUpdateLatest(); }, _lifetime); + checker.progress( + ) | rpl::start_with_next([=](const Progress &result) { + onUpdateDownloading(result.already, result.size); + }, _lifetime); + checker.failed( + ) | rpl::start_with_next([=] { onUpdateFailed(); }, _lifetime); + checker.ready( + ) | rpl::start_with_next([=] { onUpdateReady(); }, _lifetime); - switch (checker.state()) { - case Core::UpdateChecker::State::Download: - setUpdatingState(UpdatingDownload, true); - setDownloadProgress(checker.already(), checker.size()); - break; - case Core::UpdateChecker::State::Ready: - setUpdatingState(UpdatingReady, true); - break; - default: - setUpdatingState(UpdatingCheck, true); - break; + switch (checker.state()) { + case Core::UpdateChecker::State::Download: + setUpdatingState(UpdatingDownload, true); + setDownloadProgress(checker.already(), checker.size()); + break; + case Core::UpdateChecker::State::Ready: + setUpdatingState(UpdatingReady, true); + break; + default: + setUpdatingState(UpdatingCheck, true); + break; + } + + cSetLastUpdateCheck(0); + checker.start(); + } else { + _updating.setText(qsl("Please check if there is a new version available.")); + if (_sendingState != SendingNoReport) { + _sendingState = SendingNone; + } } - cSetLastUpdateCheck(0); - checker.start(); -#else // !TDESKTOP_DISABLE_AUTOUPDATE - _updating.setText(qsl("Please check if there is a new version available.")); - if (_sendingState != SendingNoReport) { - _sendingState = SendingNone; - } -#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE - _pleaseSendReport.setText(qsl("Please send us a crash report.")); _yourReportName.setText(qsl("Your Report Tag: %1\nYour User Tag: %2").arg(QString(_minidumpName).replace(".dmp", "")).arg(Sandbox::UserTag(), 0, 16)); _yourReportName.setCursor(style::cur_text); @@ -552,69 +555,41 @@ void LastCrashedWindow::updateControls() { int padding = _size, h = padding + _networkSettings.height() + padding; _label.show(); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - h += _networkSettings.height() + padding; - if (_updatingState == UpdatingFail && (_sendingState == SendingNoReport || _sendingState == SendingUpdateCheck)) { - _networkSettings.show(); - _updatingCheck.show(); - _updatingSkip.show(); - _send.hide(); - _sendSkip.hide(); - _continue.hide(); - _pleaseSendReport.hide(); - _yourReportName.hide(); - _includeUsername.hide(); - _getApp.hide(); - _showReport.hide(); - _report.hide(); - _minidump.hide(); - _saveReport.hide(); - h += padding + _updatingCheck.height() + padding; - } else { - if (_updatingState == UpdatingCheck || _sendingState == SendingFail || _sendingState == SendingProgress) { + if (_updaterData) { + h += _networkSettings.height() + padding; + if (_updaterData->state == UpdatingFail && (_sendingState == SendingNoReport || _sendingState == SendingUpdateCheck)) { _networkSettings.show(); + _updaterData->check.show(); + _updaterData->skip.show(); + _send.hide(); + _sendSkip.hide(); + _continue.hide(); + _pleaseSendReport.hide(); + _yourReportName.hide(); + _includeUsername.hide(); + _getApp.hide(); + _showReport.hide(); + _report.hide(); + _minidump.hide(); + _saveReport.hide(); + h += padding + _updaterData->check.height() + padding; } else { - _networkSettings.hide(); - } - if (_updatingState == UpdatingNone || _updatingState == UpdatingLatest || _updatingState == UpdatingFail) { - h += padding + _updatingCheck.height() + padding; - if (_sendingState == SendingNoReport) { - _pleaseSendReport.hide(); - _yourReportName.hide(); - _includeUsername.hide(); - _getApp.hide(); - _showReport.hide(); - _report.hide(); - _minidump.hide(); - _saveReport.hide(); - _send.hide(); - _sendSkip.hide(); - _continue.show(); + if (_updaterData->state == UpdatingCheck + || _sendingState == SendingFail + || _sendingState == SendingProgress) { + _networkSettings.show(); } else { - h += _showReport.height() + padding + _yourReportName.height() + padding; - _pleaseSendReport.show(); - _yourReportName.show(); - if (_reportUsername.isEmpty()) { + _networkSettings.hide(); + } + if (_updaterData->state == UpdatingNone + || _updaterData->state == UpdatingLatest + || _updaterData->state == UpdatingFail) { + h += padding + _updaterData->check.height() + padding; + if (_sendingState == SendingNoReport) { + _pleaseSendReport.hide(); + _yourReportName.hide(); _includeUsername.hide(); - } else { - h += _includeUsername.height() + padding; - _includeUsername.show(); - } - if (_sendingState == SendingTooOld || _sendingState == SendingUnofficial) { - QString verStr = getReportField(qstr("version"), qstr("Version:")); - qint64 ver = verStr.isEmpty() ? 0 : verStr.toLongLong(); - if (!ver || (ver == AppVersion) || (ver < 0 && (-ver / 1000) == AppVersion)) { - h += _getApp.height() + padding; - _getApp.show(); - h -= _yourReportName.height() + padding; // hide report name - _yourReportName.hide(); - if (!_reportUsername.isEmpty()) { - h -= _includeUsername.height() + padding; - _includeUsername.hide(); - } - } else { - _getApp.hide(); - } + _getApp.hide(); _showReport.hide(); _report.hide(); _minidump.hide(); @@ -623,48 +598,104 @@ void LastCrashedWindow::updateControls() { _sendSkip.hide(); _continue.show(); } else { - _getApp.hide(); - if (_reportShown) { - h += (_pleaseSendReport.height() * 12.5) + padding + (_minidumpName.isEmpty() ? 0 : (_minidump.height() + padding)); - _report.show(); - if (_minidumpName.isEmpty()) { - _minidump.hide(); + h += _showReport.height() + padding + _yourReportName.height() + padding; + _pleaseSendReport.show(); + _yourReportName.show(); + if (_reportUsername.isEmpty()) { + _includeUsername.hide(); + } else { + h += _includeUsername.height() + padding; + _includeUsername.show(); + } + if (_sendingState == SendingTooOld || _sendingState == SendingUnofficial) { + QString verStr = getReportField(qstr("version"), qstr("Version:")); + qint64 ver = verStr.isEmpty() ? 0 : verStr.toLongLong(); + if (!ver || (ver == AppVersion) || (ver < 0 && (-ver / 1000) == AppVersion)) { + h += _getApp.height() + padding; + _getApp.show(); + h -= _yourReportName.height() + padding; // hide report name + _yourReportName.hide(); + if (!_reportUsername.isEmpty()) { + h -= _includeUsername.height() + padding; + _includeUsername.hide(); + } } else { - _minidump.show(); - } - if (_reportSaved || _sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { - _saveReport.hide(); - } else { - _saveReport.show(); + _getApp.hide(); } _showReport.hide(); - } else { _report.hide(); _minidump.hide(); _saveReport.hide(); - if (_sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { - _showReport.hide(); - } else { - _showReport.show(); - } - } - if (_sendingState == SendingTooMany || _sendingState == SendingDone) { _send.hide(); _sendSkip.hide(); _continue.show(); } else { - if (_sendingState == SendingProgress || _sendingState == SendingUploading) { - _send.hide(); + _getApp.hide(); + if (_reportShown) { + h += (_pleaseSendReport.height() * 12.5) + padding + (_minidumpName.isEmpty() ? 0 : (_minidump.height() + padding)); + _report.show(); + if (_minidumpName.isEmpty()) { + _minidump.hide(); + } else { + _minidump.show(); + } + if (_reportSaved || _sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { + _saveReport.hide(); + } else { + _saveReport.show(); + } + _showReport.hide(); } else { - _send.show(); + _report.hide(); + _minidump.hide(); + _saveReport.hide(); + if (_sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { + _showReport.hide(); + } else { + _showReport.show(); + } + } + if (_sendingState == SendingTooMany || _sendingState == SendingDone) { + _send.hide(); + _sendSkip.hide(); + _continue.show(); + } else { + if (_sendingState == SendingProgress || _sendingState == SendingUploading) { + _send.hide(); + } else { + _send.show(); + } + _sendSkip.show(); + _continue.hide(); } - _sendSkip.show(); - _continue.hide(); } } + } else { + _getApp.hide(); + _pleaseSendReport.hide(); + _yourReportName.hide(); + _includeUsername.hide(); + _showReport.hide(); + _report.hide(); + _minidump.hide(); + _saveReport.hide(); + _send.hide(); + _sendSkip.hide(); + _continue.hide(); } - } else { - _getApp.hide(); + _updaterData->check.hide(); + if (_updaterData->state == UpdatingCheck + || _updaterData->state == UpdatingDownload) { + h += padding + _updaterData->skip.height() + padding; + _updaterData->skip.show(); + } else { + _updaterData->skip.hide(); + } + } + } else { + h += _networkSettings.height() + padding; + h += padding + _send.height() + padding; + if (_sendingState == SendingNoReport) { _pleaseSendReport.hide(); _yourReportName.hide(); _includeUsername.hide(); @@ -672,91 +703,68 @@ void LastCrashedWindow::updateControls() { _report.hide(); _minidump.hide(); _saveReport.hide(); - _send.hide(); - _sendSkip.hide(); - _continue.hide(); - } - _updatingCheck.hide(); - if (_updatingState == UpdatingCheck || _updatingState == UpdatingDownload) { - h += padding + _updatingSkip.height() + padding; - _updatingSkip.show(); - } else { - _updatingSkip.hide(); - } - } -#else // !TDESKTOP_DISABLE_AUTOUPDATE - h += _networkSettings.height() + padding; - h += padding + _send.height() + padding; - if (_sendingState == SendingNoReport) { - _pleaseSendReport.hide(); - _yourReportName.hide(); - _includeUsername.hide(); - _showReport.hide(); - _report.hide(); - _minidump.hide(); - _saveReport.hide(); - _send.hide(); - _sendSkip.hide(); - _continue.show(); - _networkSettings.hide(); - } else { - h += _showReport.height() + padding + _yourReportName.height() + padding; - _pleaseSendReport.show(); - _yourReportName.show(); - if (_reportUsername.isEmpty()) { - _includeUsername.hide(); - } else { - h += _includeUsername.height() + padding; - _includeUsername.show(); - } - if (_reportShown) { - h += (_pleaseSendReport.height() * 12.5) + padding + (_minidumpName.isEmpty() ? 0 : (_minidump.height() + padding)); - _report.show(); - if (_minidumpName.isEmpty()) { - _minidump.hide(); - } else { - _minidump.show(); - } - _showReport.hide(); - if (_reportSaved || _sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { - _saveReport.hide(); - } else { - _saveReport.show(); - } - } else { - _report.hide(); - _minidump.hide(); - _saveReport.hide(); - if (_sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { - _showReport.hide(); - } else { - _showReport.show(); - } - } - if (_sendingState == SendingDone) { _send.hide(); _sendSkip.hide(); _continue.show(); _networkSettings.hide(); } else { - if (_sendingState == SendingProgress || _sendingState == SendingUploading) { + h += _showReport.height() + padding + _yourReportName.height() + padding; + _pleaseSendReport.show(); + _yourReportName.show(); + if (_reportUsername.isEmpty()) { + _includeUsername.hide(); + } else { + h += _includeUsername.height() + padding; + _includeUsername.show(); + } + if (_reportShown) { + h += (_pleaseSendReport.height() * 12.5) + padding + (_minidumpName.isEmpty() ? 0 : (_minidump.height() + padding)); + _report.show(); + if (_minidumpName.isEmpty()) { + _minidump.hide(); + } else { + _minidump.show(); + } + _showReport.hide(); + if (_reportSaved || _sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { + _saveReport.hide(); + } else { + _saveReport.show(); + } + } else { + _report.hide(); + _minidump.hide(); + _saveReport.hide(); + if (_sendingState == SendingFail || _sendingState == SendingProgress || _sendingState == SendingUploading) { + _showReport.hide(); + } else { + _showReport.show(); + } + } + if (_sendingState == SendingDone) { _send.hide(); - } else { - _send.show(); - } - _sendSkip.show(); - if (_sendingState == SendingFail) { - _networkSettings.show(); - } else { + _sendSkip.hide(); + _continue.show(); _networkSettings.hide(); + } else { + if (_sendingState == SendingProgress || _sendingState == SendingUploading) { + _send.hide(); + } else { + _send.show(); + } + _sendSkip.show(); + if (_sendingState == SendingFail) { + _networkSettings.show(); + } else { + _networkSettings.hide(); + } + _continue.hide(); } - _continue.hide(); } - } - _getApp.show(); - h += _networkSettings.height() + padding; -#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE + _getApp.show(); + h += _networkSettings.height() + padding; + } QRect scr(QApplication::primaryScreen()->availableGeometry()); QSize s(2 * padding + QFontMetrics(_label.font()).width(qsl("Last time Telegram Desktop was not closed properly.")) + padding + _networkSettings.width(), h); @@ -801,24 +809,27 @@ void LastCrashedWindow::onNetworkSettingsSaved( Sandbox::refreshGlobalProxy(); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - if ((_updatingState == UpdatingFail && (_sendingState == SendingNoReport || _sendingState == SendingUpdateCheck)) || (_updatingState == UpdatingCheck)) { + if (_updaterData + && ((_updaterData->state == UpdatingCheck) + || (_updaterData->state == UpdatingFail + && (_sendingState == SendingNoReport + || _sendingState == SendingUpdateCheck)))) { Core::UpdateChecker checker; checker.stop(); cSetLastUpdateCheck(0); checker.start(); - } else -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - if (_sendingState == SendingFail || _sendingState == SendingProgress) { + } else if (_sendingState == SendingFail + || _sendingState == SendingProgress) { onSendReport(); } activate(); } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void LastCrashedWindow::setUpdatingState(UpdatingState state, bool force) { - if (_updatingState != state || force) { - _updatingState = state; + Expects(_updaterData != nullptr); + + if (_updaterData->state != state || force) { + _updaterData->state = state; switch (state) { case UpdatingLatest: _updating.setText(qsl("Latest version is installed.")); @@ -850,29 +861,35 @@ void LastCrashedWindow::setUpdatingState(UpdatingState state, bool force) { } void LastCrashedWindow::setDownloadProgress(qint64 ready, qint64 total) { + Expects(_updaterData != nullptr); + qint64 readyTenthMb = (ready * 10 / (1024 * 1024)), totalTenthMb = (total * 10 / (1024 * 1024)); QString readyStr = QString::number(readyTenthMb / 10) + '.' + QString::number(readyTenthMb % 10); QString totalStr = QString::number(totalTenthMb / 10) + '.' + QString::number(totalTenthMb % 10); QString res = qsl("Downloading update {ready} / {total} MB..").replace(qstr("{ready}"), readyStr).replace(qstr("{total}"), totalStr); - if (_newVersionDownload != res) { - _newVersionDownload = res; - _updating.setText(_newVersionDownload); + if (_updaterData->newVersionDownload != res) { + _updaterData->newVersionDownload = res; + _updating.setText(_updaterData->newVersionDownload); updateControls(); } } void LastCrashedWindow::onUpdateRetry() { + Expects(_updaterData != nullptr); + cSetLastUpdateCheck(0); Core::UpdateChecker checker; checker.start(); } void LastCrashedWindow::onUpdateSkip() { + Expects(_updaterData != nullptr); + if (_sendingState == SendingNoReport) { onContinue(); } else { - if (_updatingState == UpdatingCheck - || _updatingState == UpdatingDownload) { + if (_updaterData->state == UpdatingCheck + || _updaterData->state == UpdatingDownload) { Core::UpdateChecker checker; checker.stop(); setUpdatingState(UpdatingFail); @@ -883,26 +900,35 @@ void LastCrashedWindow::onUpdateSkip() { } void LastCrashedWindow::onUpdateChecking() { + Expects(_updaterData != nullptr); + setUpdatingState(UpdatingCheck); } void LastCrashedWindow::onUpdateLatest() { + Expects(_updaterData != nullptr); + setUpdatingState(UpdatingLatest); } void LastCrashedWindow::onUpdateDownloading(qint64 ready, qint64 total) { + Expects(_updaterData != nullptr); + setUpdatingState(UpdatingDownload); setDownloadProgress(ready, total); } void LastCrashedWindow::onUpdateReady() { + Expects(_updaterData != nullptr); + setUpdatingState(UpdatingReady); } void LastCrashedWindow::onUpdateFailed() { + Expects(_updaterData != nullptr); + setUpdatingState(UpdatingFail); } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE void LastCrashedWindow::onContinue() { if (CrashReports::Restart() == CrashReports::CantOpen) { @@ -973,36 +999,37 @@ void LastCrashedWindow::resizeEvent(QResizeEvent *e) { _updating.move(padding, padding * 2 + _networkSettings.height() + (_networkSettings.height() - _updating.height()) / 2); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - _pleaseSendReport.move(padding, padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + (_showReport.height() - _pleaseSendReport.height()) / 2); - _showReport.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding); - _yourReportName.move(padding, _showReport.y() + _showReport.height() + padding); - _includeUsername.move(padding, _yourReportName.y() + _yourReportName.height() + padding); - _getApp.move((width() - _getApp.width()) / 2, _showReport.y() + _showReport.height() + padding); + if (_updaterData) { + _pleaseSendReport.move(padding, padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + (_showReport.height() - _pleaseSendReport.height()) / 2); + _showReport.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding); + _yourReportName.move(padding, _showReport.y() + _showReport.height() + padding); + _includeUsername.move(padding, _yourReportName.y() + _yourReportName.height() + padding); + _getApp.move((width() - _getApp.width()) / 2, _showReport.y() + _showReport.height() + padding); - if (_sendingState == SendingFail || _sendingState == SendingProgress) { - _networkSettings.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding); + if (_sendingState == SendingFail || _sendingState == SendingProgress) { + _networkSettings.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding); + } else { + _networkSettings.move(padding * 2 + _updating.width(), padding * 2 + _networkSettings.height()); + } + + if (_updaterData->state == UpdatingCheck + || _updaterData->state == UpdatingDownload) { + _updaterData->check.move(width() - padding - _updaterData->check.width(), height() - padding - _updaterData->check.height()); + _updaterData->skip.move(width() - padding - _updaterData->skip.width(), height() - padding - _updaterData->skip.height()); + } else { + _updaterData->check.move(width() - padding - _updaterData->check.width(), height() - padding - _updaterData->check.height()); + _updaterData->skip.move(width() - padding - _updaterData->check.width() - padding - _updaterData->skip.width(), height() - padding - _updaterData->skip.height()); + } } else { - _networkSettings.move(padding * 2 + _updating.width(), padding * 2 + _networkSettings.height()); + _getApp.move((width() - _getApp.width()) / 2, _updating.y() + _updating.height() + padding); + + _pleaseSendReport.move(padding, padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding + (_showReport.height() - _pleaseSendReport.height()) / 2); + _showReport.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding); + _yourReportName.move(padding, _showReport.y() + _showReport.height() + padding); + _includeUsername.move(padding, _yourReportName.y() + _yourReportName.height() + padding); + + _networkSettings.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding); } - - if (_updatingState == UpdatingCheck || _updatingState == UpdatingDownload) { - _updatingCheck.move(width() - padding - _updatingCheck.width(), height() - padding - _updatingCheck.height()); - _updatingSkip.move(width() - padding - _updatingSkip.width(), height() - padding - _updatingSkip.height()); - } else { - _updatingCheck.move(width() - padding - _updatingCheck.width(), height() - padding - _updatingCheck.height()); - _updatingSkip.move(width() - padding - _updatingCheck.width() - padding - _updatingSkip.width(), height() - padding - _updatingSkip.height()); - } -#else // !TDESKTOP_DISABLE_AUTOUPDATE - _getApp.move((width() - _getApp.width()) / 2, _updating.y() + _updating.height() + padding); - - _pleaseSendReport.move(padding, padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding + (_showReport.height() - _pleaseSendReport.height()) / 2); - _showReport.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding); - _yourReportName.move(padding, _showReport.y() + _showReport.height() + padding); - _includeUsername.move(padding, _yourReportName.y() + _yourReportName.height() + padding); - - _networkSettings.move(padding * 2 + _pleaseSendReport.width(), padding * 2 + _networkSettings.height() + _networkSettings.height() + padding + _getApp.height() + padding); -#endif // else for !TDESKTOP_DISABLE_AUTOUPDATE if (_reportUsername.isEmpty()) { _report.setGeometry(padding, _yourReportName.y() + _yourReportName.height() + padding, width() - 2 * padding, _pleaseSendReport.height() * 12.5); } else { diff --git a/Telegram/SourceFiles/core/crash_report_window.h b/Telegram/SourceFiles/core/crash_report_window.h index cde1f6280..1a99ba2b9 100644 --- a/Telegram/SourceFiles/core/crash_report_window.h +++ b/Telegram/SourceFiles/core/crash_report_window.h @@ -95,7 +95,6 @@ public slots: void onSendingFinished(); void onSendingProgress(qint64 uploaded, qint64 total); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void onUpdateRetry(); void onUpdateSkip(); @@ -104,7 +103,6 @@ public slots: void onUpdateDownloading(qint64 ready, qint64 total); void onUpdateReady(); void onUpdateFailed(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE protected: void closeEvent(QCloseEvent *e); @@ -153,8 +151,6 @@ private: QNetworkAccessManager _sendManager; QNetworkReply *_checkReply, *_sendReply; -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - PreLaunchButton _updatingCheck, _updatingSkip; enum UpdatingState { UpdatingNone, UpdatingCheck, @@ -163,12 +159,17 @@ private: UpdatingFail, UpdatingReady }; - UpdatingState _updatingState; - QString _newVersionDownload; + struct UpdaterData { + UpdaterData(QWidget *buttonParent); + + PreLaunchButton check, skip; + UpdatingState state; + QString newVersionDownload; + }; + const std::unique_ptr _updaterData; void setUpdatingState(UpdatingState state, bool force = false); void setDownloadProgress(qint64 ready, qint64 total); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 207885898..0a58df067 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "core/crash_reports.h" #include "core/main_queue_processor.h" +#include "core/update_checker.h" #include "application.h" namespace Core { @@ -61,15 +62,12 @@ int Launcher::exec() { DEBUG_LOG(("Telegram finished, result: %1").arg(result)); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - if (cRestartingUpdate()) { + if (!UpdaterDisabled() && cRestartingUpdate()) { DEBUG_LOG(("Application Info: executing updater to install update...")); if (!launchUpdater(UpdaterLaunch::PerformUpdate)) { psDeleteDir(cWorkingDir() + qsl("tupdates/temp")); } - } else -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - if (cRestarting()) { + } else if (cRestarting()) { DEBUG_LOG(("Application Info: executing Telegram, because of restart...")); launchUpdater(UpdaterLaunch::JustRelaunch); } @@ -178,19 +176,20 @@ void Launcher::processArguments() { AllLeftValues, }; auto parseMap = std::map { - { "-testmode" , KeyFormat::NoValues }, - { "-debug" , KeyFormat::NoValues }, - { "-many" , KeyFormat::NoValues }, - { "-key" , KeyFormat::OneValue }, - { "-autostart" , KeyFormat::NoValues }, - { "-fixprevious", KeyFormat::NoValues }, - { "-cleanup" , KeyFormat::NoValues }, - { "-noupdate" , KeyFormat::NoValues }, - { "-tosettings" , KeyFormat::NoValues }, - { "-startintray", KeyFormat::NoValues }, - { "-sendpath" , KeyFormat::AllLeftValues }, - { "-workdir" , KeyFormat::OneValue }, - { "--" , KeyFormat::OneValue }, + { "-testmode" , KeyFormat::NoValues }, + { "-debug" , KeyFormat::NoValues }, + { "-many" , KeyFormat::NoValues }, + { "-key" , KeyFormat::OneValue }, + { "-autostart" , KeyFormat::NoValues }, + { "-fixprevious" , KeyFormat::NoValues }, + { "-cleanup" , KeyFormat::NoValues }, + { "-noupdate" , KeyFormat::NoValues }, + { "-externalupdater", KeyFormat::NoValues }, + { "-tosettings" , KeyFormat::NoValues }, + { "-startintray" , KeyFormat::NoValues }, + { "-sendpath" , KeyFormat::AllLeftValues }, + { "-workdir" , KeyFormat::OneValue }, + { "--" , KeyFormat::OneValue }, }; auto parseResult = QMap(); auto parsingKey = QByteArray(); @@ -215,6 +214,9 @@ void Launcher::processArguments() { } } + if (parseResult.contains("-externalupdater")) { + SetUpdaterDisabledAtStartup(); + } gTestMode = parseResult.contains("-testmode"); Logs::SetDebugEnabled(parseResult.contains("-debug")); gManyInstance = parseResult.contains("-many"); diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index c797d9001..6b4a32439 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -32,9 +32,6 @@ extern "C" { #endif // else of Q_OS_WIN namespace Core { - -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - namespace { constexpr auto kUpdaterTimeout = 10 * TimeMs(1000); @@ -42,6 +39,12 @@ constexpr auto kMaxResponseSize = 1024 * 1024; constexpr auto kMaxUpdateSize = 256 * 1024 * 1024; constexpr auto kChunkSize = 128 * 1024; +#ifdef TDESKTOP_DISABLE_AUTOUPDATE +bool UpdaterIsDisabled = true; +#else // TDESKTOP_DISABLE_AUTOUPDATE +bool UpdaterIsDisabled = false; +#endif // TDESKTOP_DISABLE_AUTOUPDATE + std::weak_ptr UpdaterInstance; using ErrorSignal = void(QNetworkReply::*)(QNetworkReply::NetworkError); @@ -1560,6 +1563,16 @@ Fn MtpLoader::failHandler() { } // namespace +bool UpdaterDisabled() { + return UpdaterIsDisabled; +} + +void SetUpdaterDisabledAtStartup() { + Expects(UpdaterInstance.lock() == nullptr); + + UpdaterIsDisabled = true; +} + class Updater : public base::has_weak_ptr { public: Updater(); @@ -2099,36 +2112,32 @@ bool checkReadyUpdate() { } void UpdateApplication() { - cSetLastUpdateCheck(0); - Core::UpdateChecker().start(); - if (const auto window = App::wnd()) { - auto settings = Box(); - const auto weak = make_weak(settings.data()); - window->showSpecialLayer(std::move(settings), anim::type::normal); - if (weak) { - weak->scrollToUpdateRow(); + if (UpdaterDisabled()) { + const auto url = [&] { +#ifdef OS_WIN_STORE + return "https://www.microsoft.com/en-us/store/p/telegram-desktop/9nztwsqntd0s"; +#elif defined OS_MAC_STORE // OS_WIN_STORE + return "https://itunes.apple.com/ae/app/telegram-desktop/id946399090"; +#else // OS_WIN_STORE || OS_MAC_STORE + return "https://desktop.telegram.org"; +#endif // OS_WIN_STORE || OS_MAC_STORE + }(); + UrlClickHandler::Open(url); + } else { + cSetLastUpdateCheck(0); + Core::UpdateChecker().start(); + if (const auto window = App::wnd()) { + auto settings = Box(); + const auto weak = make_weak(settings.data()); + window->showSpecialLayer(std::move(settings), anim::type::normal); + if (weak) { + weak->scrollToUpdateRow(); + } + window->showFromTray(); } - window->showFromTray(); } } -#else // !TDESKTOP_DISABLE_AUTOUPDATE - -void UpdateApplication() { - const auto url = [&] { -#ifdef OS_WIN_STORE - return "https://www.microsoft.com/en-us/store/p/telegram-desktop/9nztwsqntd0s"; -#elif defined OS_MAC_STORE // OS_WIN_STORE - return "https://itunes.apple.com/ae/app/telegram-desktop/id946399090"; -#else // OS_WIN_STORE || OS_MAC_STORE - return "https://desktop.telegram.org"; -#endif // OS_WIN_STORE || OS_MAC_STORE - }(); - UrlClickHandler::doOpen(url); -} - -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - QString countBetaVersionSignature(uint64 version) { // duplicated in packer.cpp if (cBetaPrivateKey().isEmpty()) { LOG(("Error: Trying to count beta version signature without beta private key!")); diff --git a/Telegram/SourceFiles/core/update_checker.h b/Telegram/SourceFiles/core/update_checker.h index 656912ba8..b87a09e1a 100644 --- a/Telegram/SourceFiles/core/update_checker.h +++ b/Telegram/SourceFiles/core/update_checker.h @@ -13,7 +13,8 @@ class Instance; namespace Core { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE +bool UpdaterDisabled(); +void SetUpdaterDisabledAtStartup(); class Updater; @@ -53,13 +54,6 @@ private: }; bool checkReadyUpdate(); - -#else // TDESKTOP_DISABLE_AUTOUPDATE -class UpdateChecker { -}; - -#endif // TDESKTOP_DISABLE_AUTOUPDATE - void UpdateApplication(); QString countBetaVersionSignature(uint64 version); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 8f44900bc..ee2b05439 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -120,17 +120,17 @@ DialogsWidget::DialogsWidget(QWidget *parent, not_null cont connect(_filter, SIGNAL(changed()), this, SLOT(onFilterUpdate())); connect(_filter, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(onFilterCursorMoved(int,int))); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Core::UpdateChecker checker; - rpl::merge( - rpl::single(rpl::empty_value()), - checker.isLatest(), - checker.failed(), - checker.ready() - ) | rpl::start_with_next([=] { - checkUpdateStatus(); - }, lifetime()); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE + if (!Core::UpdaterDisabled()) { + Core::UpdateChecker checker; + rpl::merge( + rpl::single(rpl::empty_value()), + checker.isLatest(), + checker.failed(), + checker.ready() + ) | rpl::start_with_next([=] { + checkUpdateStatus(); + }, lifetime()); + } subscribe(Adaptive::Changed(), [this] { updateForwardBar(); }); @@ -181,8 +181,9 @@ void DialogsWidget::setupConnectingWidget() { Window::AdaptiveIsOneColumn()); } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void DialogsWidget::checkUpdateStatus() { + Expects(!Core::UpdaterDisabled()); + using Checker = Core::UpdateChecker; if (Checker().state() == Checker::State::Ready) { if (_updateTelegram) return; @@ -198,7 +199,6 @@ void DialogsWidget::checkUpdateStatus() { } updateControlsGeometry(); } -#endif // TDESKTOP_DISABLE_AUTOUPDATE void DialogsWidget::activate() { _filter->setFocus(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index bc069e279..14dde02b1 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -164,10 +164,7 @@ private: void updateSearchFromVisibility(bool fast = false); void updateControlsGeometry(); void updateForwardBar(); - -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void checkUpdateStatus(); -#endif // TDESKTOP_DISABLE_AUTOUPDATE bool dialogsFailed(const RPCError &error, mtpRequestId req); bool searchFailed(DialogsSearchRequestType type, const RPCError &error, mtpRequestId req); diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index b5a8c8dc1..d7a2b1d7d 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -84,20 +84,20 @@ Widget::Widget(QWidget *parent) : RpWidget(parent) cSetPasswordRecovered(false); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Core::UpdateChecker checker; - checker.isLatest() | rpl::start_with_next([=] { + if (!Core::UpdaterDisabled()) { + Core::UpdateChecker checker; + checker.isLatest() | rpl::start_with_next([=] { + onCheckUpdateStatus(); + }, lifetime()); + checker.failed() | rpl::start_with_next([=] { + onCheckUpdateStatus(); + }, lifetime()); + checker.ready() | rpl::start_with_next([=] { + onCheckUpdateStatus(); + }, lifetime()); + checker.start(); onCheckUpdateStatus(); - }, lifetime()); - checker.failed() | rpl::start_with_next([=] { - onCheckUpdateStatus(); - }, lifetime()); - checker.ready() | rpl::start_with_next([=] { - onCheckUpdateStatus(); - }, lifetime()); - checker.start(); - onCheckUpdateStatus(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE + } } void Widget::setupConnectingWidget() { @@ -148,8 +148,9 @@ void Widget::createLanguageLink() { } } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void Widget::onCheckUpdateStatus() { + Expects(!Core::UpdaterDisabled()); + if (Core::UpdateChecker().state() == Core::UpdateChecker::State::Ready) { if (_update) return; _update.create( @@ -173,7 +174,6 @@ void Widget::onCheckUpdateStatus() { } updateControlsGeometry(); } -#endif // TDESKTOP_DISABLE_AUTOUPDATE void Widget::setInnerFocus() { if (getStep()->animating()) { diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index ef58c1fec..aa20459c6 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -48,10 +48,8 @@ protected: signals: void countryChanged(); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE private slots: void onCheckUpdateStatus(); -#endif // TDESKTOP_DISABLE_AUTOUPDATE // Internal interface. public: diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 0a960aa25..d1fbc143d 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -368,10 +368,10 @@ MainWidget::MainWidget( orderWidgets(); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Core::UpdateChecker checker; - checker.start(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE + if (!Core::UpdaterDisabled()) { + Core::UpdateChecker checker; + checker.start(); + } } void MainWidget::setupConnectingWidget() { diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 49dbda021..074992b89 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -466,9 +466,9 @@ void Messenger::startMtp() { _langCloudManager = std::make_unique( langpack(), mtp()); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Core::UpdateChecker().setMtproto(mtp()); -#endif // TDESKTOP_DISABLE_AUTOUPDATE + if (!Core::UpdaterDisabled()) { + Core::UpdateChecker().setMtproto(mtp()); + } } void Messenger::destroyMtpKeys(MTP::AuthKeysList &&keys) { diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index 494531385..fae2332ca 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/linux/launcher_linux.h" #include "core/crash_reports.h" +#include "core/update_checker.h" #include #include @@ -83,6 +84,11 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (cTestMode()) { argumentsList.push("-testmode"); } +#ifndef TDESKTOP_DISABLE_AUTOUPDATE + if (Core::UpdaterDisabled()) { + argumentsList.push("-externalupdater"); + } +#endif // !TDESKTOP_DISABLE_AUTOUPDATE if (cDataFile() != qsl("data")) { argumentsList.push("-key"); argumentsList.push(QFile::encodeName(cDataFile())); diff --git a/Telegram/SourceFiles/platform/mac/launcher_mac.mm b/Telegram/SourceFiles/platform/mac/launcher_mac.mm index 52b798792..5553d52be 100644 --- a/Telegram/SourceFiles/platform/mac/launcher_mac.mm +++ b/Telegram/SourceFiles/platform/mac/launcher_mac.mm @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/mac/launcher_mac.h" #include "core/crash_reports.h" +#include "core/update_checker.h" #include "platform/mac/mac_utilities.h" #include @@ -125,6 +126,9 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (Logs::DebugEnabled()) [args addObject:@"-debug"]; if (cStartInTray()) [args addObject:@"-startintray"]; if (cTestMode()) [args addObject:@"-testmode"]; +#ifndef TDESKTOP_DISABLE_AUTOUPDATE + if (Core::UpdaterDisabled()) [args addObject:@"-externalupdater"]; +#endif // !TDESKTOP_DISABLE_AUTOUPDATE if (cDataFile() != qsl("data")) { [args addObject:@"-key"]; [args addObject:Q2NSString(cDataFile())]; diff --git a/Telegram/SourceFiles/platform/win/launcher_win.cpp b/Telegram/SourceFiles/platform/win/launcher_win.cpp index 36efd7a40..9297a0f2f 100644 --- a/Telegram/SourceFiles/platform/win/launcher_win.cpp +++ b/Telegram/SourceFiles/platform/win/launcher_win.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/win/launcher_win.h" #include "core/crash_reports.h" +#include "core/update_checker.h" #include "platform/platform_specific.h" #include @@ -89,6 +90,11 @@ bool Launcher::launchUpdater(UpdaterLaunch action) { if (cTestMode()) { pushArgument(qsl("-testmode")); } +#ifndef TDESKTOP_DISABLE_AUTOUPDATE + if (Core::UpdaterDisabled()) { + pushArgument(qsl("-externalupdater")); + } +#endif // !TDESKTOP_DISABLE_AUTOUPDATE if (customWorkingDir()) { pushArgument(qsl("-workdir")); pushArgument('"' + cWorkingDir() + '"'); diff --git a/Telegram/SourceFiles/settings/settings_general_widget.cpp b/Telegram/SourceFiles/settings/settings_general_widget.cpp index d6e286418..9ac1a3b22 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_general_widget.cpp @@ -27,10 +27,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE UpdateStateRow::UpdateStateRow(QWidget *parent) : RpWidget(parent) , _check(this, lang(lng_settings_check_now)) , _restart(this, lang(lng_settings_update_now)) { + Expects(!Core::UpdaterDisabled()); + connect(_check, SIGNAL(clicked()), this, SLOT(onCheck())); connect(_restart, SIGNAL(clicked()), this, SIGNAL(restart())); @@ -160,7 +161,6 @@ void UpdateStateRow::onReady() { void UpdateStateRow::onFailed() { setState(State::Fail); } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_general)) , _changeLanguage(this, lang(lng_settings_change_lang), st::boxLinkButton) { @@ -169,11 +169,8 @@ GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(pare } int GeneralWidget::getUpdateTop() const { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - return 0; // _updateRow->y(); // Just scroll to the top of the whole General widget -#else // !TDESKTOP_DISABLE_AUTOUPDATE - return -1; -#endif // !TDESKTOP_DISABLE_AUTOUPDATE + // Just scroll to the top of the whole General widget + return Core::UpdaterDisabled() ? -1 : 0; } int GeneralWidget::resizeGetHeight(int newWidth) { @@ -187,15 +184,15 @@ void GeneralWidget::refreshControls() { style::margins marginSmall(0, 0, 0, st::settingsSmallSkip); style::margins slidedPadding(0, marginSmall.bottom() / 2, 0, marginSmall.bottom() - (marginSmall.bottom() / 2)); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - createChildRow(_updateAutomatically, marginSub, lang(lng_settings_update_automatically), [this](bool) { onUpdateAutomatically(); }, cAutoUpdate()); - style::margins marginLink(st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip); - createChildRow(_updateRow, marginLink, slidedPadding); - connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart())); - if (!cAutoUpdate()) { - _updateRow->hide(anim::type::instant); + if (!Core::UpdaterDisabled()) { + createChildRow(_updateAutomatically, marginSub, lang(lng_settings_update_automatically), [this](bool) { onUpdateAutomatically(); }, cAutoUpdate()); + style::margins marginLink(st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip); + createChildRow(_updateRow, marginLink, slidedPadding); + connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart())); + if (!cAutoUpdate()) { + _updateRow->hide(anim::type::instant); + } } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE if (cPlatform() == dbipWindows || cSupportTray()) { auto workMode = Global::WorkMode().value(); @@ -237,14 +234,15 @@ void GeneralWidget::onChangeLanguage() { } void GeneralWidget::onRestart() { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Core::checkReadyUpdate(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE + if (!Core::UpdaterDisabled()) { + Core::checkReadyUpdate(); + } App::restart(); } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void GeneralWidget::onUpdateAutomatically() { + Expects(!Core::UpdaterDisabled()); + cSetAutoUpdate(_updateAutomatically->checked()); Local::writeSettings(); _updateRow->toggle( @@ -257,7 +255,6 @@ void GeneralWidget::onUpdateAutomatically() { checker.stop(); } } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE void GeneralWidget::onEnableTrayIcon() { if ((!_enableTrayIcon->checked() || cPlatform() != dbipWindows) && _enableTaskbarIcon && !_enableTaskbarIcon->checked()) { diff --git a/Telegram/SourceFiles/settings/settings_general_widget.h b/Telegram/SourceFiles/settings/settings_general_widget.h index a2a05e540..651737a1b 100644 --- a/Telegram/SourceFiles/settings/settings_general_widget.h +++ b/Telegram/SourceFiles/settings/settings_general_widget.h @@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Settings { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE class UpdateStateRow : public Ui::RpWidget { Q_OBJECT @@ -60,7 +59,6 @@ private: QString _versionText; }; -#endif // !TDESKTOP_DISABLE_AUTOUPDATE class GeneralWidget : public BlockWidget { Q_OBJECT @@ -75,11 +73,7 @@ protected: private slots: void onChangeLanguage(); - -#ifndef TDESKTOP_DISABLE_AUTOUPDATE void onUpdateAutomatically(); -#endif // !TDESKTOP_DISABLE_AUTOUPDATE - void onEnableTrayIcon(); void onEnableTaskbarIcon(); @@ -96,10 +90,8 @@ private: void updateWorkmode(); object_ptr _changeLanguage; -#ifndef TDESKTOP_DISABLE_AUTOUPDATE Ui::Checkbox *_updateAutomatically = nullptr; Ui::SlideWrap *_updateRow = nullptr; -#endif // !TDESKTOP_DISABLE_AUTOUPDATE Ui::Checkbox *_enableTrayIcon = nullptr; Ui::Checkbox *_enableTaskbarIcon = nullptr; Ui::Checkbox *_autoStart = nullptr; diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index 3343a7705..ae495ad97 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -59,11 +59,11 @@ void fillCodes() { Messenger::Instance().onSwitchTestMode(); })); }); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - Codes.insert(qsl("testupdate"), [] { - Core::UpdateChecker().test(); - }); -#endif // TDESKTOP_DISABLE_AUTOUPDATE + if (!Core::UpdaterDisabled()) { + Codes.insert(qsl("testupdate"), [] { + Core::UpdateChecker().test(); + }); + } Codes.insert(qsl("loadlang"), [] { Lang::CurrentCloudManager().switchToLanguage(qsl("custom")); }); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 31ac37237..da635c746 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -1315,11 +1315,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting if (!_checkStreamStatus(stream)) return false; cSetAutoUpdate(v == 1); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE - if (!cAutoUpdate()) { + if (!Core::UpdaterDisabled() && !cAutoUpdate()) { Core::UpdateChecker().stop(); } -#endif // !TDESKTOP_DISABLE_AUTOUPDATE } break; case dbiLastUpdateCheck: { @@ -2560,8 +2558,9 @@ void writeMtpData() { _writeMtpData(); } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE const QString &AutoupdatePrefix(const QString &replaceWith = {}) { + Expects(!Core::UpdaterDisabled()); + static auto value = QString(); if (!replaceWith.isEmpty()) { value = replaceWith; @@ -2570,10 +2569,14 @@ const QString &AutoupdatePrefix(const QString &replaceWith = {}) { } QString autoupdatePrefixFile() { + Expects(!Core::UpdaterDisabled()); + return cWorkingDir() + "tdata/prefix"; } const QString &readAutoupdatePrefixRaw() { + Expects(!Core::UpdaterDisabled()); + const auto &result = AutoupdatePrefix(); if (!result.isEmpty()) { return result; @@ -2587,10 +2590,12 @@ const QString &readAutoupdatePrefixRaw() { } return AutoupdatePrefix("https://updates.tdesktop.com"); } -#endif // TDESKTOP_DISABLE_AUTOUPDATE void writeAutoupdatePrefix(const QString &prefix) { -#ifndef TDESKTOP_DISABLE_AUTOUPDATE + if (Core::UpdaterDisabled()) { + return; + } + const auto current = readAutoupdatePrefixRaw(); if (current != prefix) { AutoupdatePrefix(prefix); @@ -2604,15 +2609,14 @@ void writeAutoupdatePrefix(const QString &prefix) { checker.start(); } } -#endif // TDESKTOP_DISABLE_AUTOUPDATE } -#ifndef TDESKTOP_DISABLE_AUTOUPDATE QString readAutoupdatePrefix() { + Expects(!Core::UpdaterDisabled()); + auto result = readAutoupdatePrefixRaw(); return result.replace(QRegularExpression("/+$"), QString()); } -#endif // TDESKTOP_DISABLE_AUTOUPDATE void reset() { if (_localLoader) { diff --git a/Telegram/SourceFiles/storage/localstorage.h b/Telegram/SourceFiles/storage/localstorage.h index 55b248318..81e5b00bd 100644 --- a/Telegram/SourceFiles/storage/localstorage.h +++ b/Telegram/SourceFiles/storage/localstorage.h @@ -32,9 +32,7 @@ void writeUserSettings(); void writeMtpData(); void writeAutoupdatePrefix(const QString &prefix); -#ifndef TDESKTOP_DISABLE_AUTOUPDATE QString readAutoupdatePrefix(); -#endif // TDESKTOP_DISABLE_AUTOUPDATE void reset(); diff --git a/appveyor.yml b/appveyor.yml index da1d2df46..91e44a86a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,6 @@ deploy: off environment: matrix: - BUILD_VERSION: - - BUILD_VERSION: disable_autoupdate - BUILD_VERSION: disable_register_custom_scheme - BUILD_VERSION: disable_crash_reports - BUILD_VERSION: disable_network_proxy