diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index ecc8d1c47..ca59a340e 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -83,35 +83,6 @@ v1/0UnkegO4jNkSY3ycDqn+T3NjxNxnL0EsKh7MjinyMUe3ZISzaIyrdq/8v4bvB\n\ -----END RSA PUBLIC KEY-----\ "; -#if defined TDESKTOP_API_ID && defined TDESKTOP_API_HASH - -constexpr auto ApiId = TDESKTOP_API_ID; -constexpr auto ApiHash = MACRO_TO_STRING(TDESKTOP_API_HASH); - -#else // TDESKTOP_API_ID && TDESKTOP_API_HASH - -// To build your version of Telegram Desktop you're required to provide -// your own 'api_id' and 'api_hash' for the Telegram API access. -// -// How to obtain your 'api_id' and 'api_hash' is described here: -// https://core.telegram.org/api/obtaining_api_id -// -// If you're building the application not for deployment, -// but only for test purposes you can comment out the error below. -// -// This will allow you to use TEST ONLY 'api_id' and 'api_hash' which are -// very limited by the Telegram API server. -// -// Your users will start getting internal server errors on login -// if you deploy an app using those 'api_id' and 'api_hash'. - -#error You are required to provide API_ID and API_HASH. - -constexpr auto ApiId = 17349; -constexpr auto ApiHash = "344583e45741c457fe1862106095a5eb"; - -#endif // TDESKTOP_API_ID && TDESKTOP_API_HASH - #if Q_BYTE_ORDER == Q_BIG_ENDIAN #error "Only little endian is supported!" #endif // Q_BYTE_ORDER == Q_BIG_ENDIAN diff --git a/Telegram/SourceFiles/core/crash_reports.cpp b/Telegram/SourceFiles/core/crash_reports.cpp index 8b3a8932f..99749c39a 100644 --- a/Telegram/SourceFiles/core/crash_reports.cpp +++ b/Telegram/SourceFiles/core/crash_reports.cpp @@ -343,7 +343,7 @@ QString PlatformString() { void StartCatching(not_null launcher) { #ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS ProcessAnnotations["Binary"] = cExeName().toUtf8().constData(); - ProcessAnnotations["ApiId"] = QString::number(ApiId).toUtf8().constData(); + ProcessAnnotations["ApiId"] = QString::number(cApiId()).toUtf8().constData(); ProcessAnnotations["Version"] = (cAlphaVersion() ? qsl("%1 alpha").arg(cAlphaVersion()) : (AppBetaVersion ? qsl("%1 beta") : qsl("%1")).arg(AppVersion)).toUtf8().constData(); ProcessAnnotations["Launched"] = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss").toUtf8().constData(); ProcessAnnotations["Platform"] = PlatformString().toUtf8().constData(); diff --git a/Telegram/SourceFiles/core/launcher.cpp b/Telegram/SourceFiles/core/launcher.cpp index 37b8effcd..bbe6aff82 100644 --- a/Telegram/SourceFiles/core/launcher.cpp +++ b/Telegram/SourceFiles/core/launcher.cpp @@ -20,6 +20,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Core { namespace { +constexpr auto kApiIdVarName = "KTGDESKTOP_API_ID"_cs; +constexpr auto kApiHashVarName = "KTGDESKTOP_API_HASH"_cs; + uint64 InstallationTag = 0; class FilteredCommandLineArguments { @@ -332,6 +335,12 @@ int Launcher::exec() { Platform::start(); Ui::DisableCustomScaling(); + if (qEnvironmentVariableIsSet(kApiIdVarName.utf8()) + && qEnvironmentVariableIsSet(kApiHashVarName.utf8())) { + cSetApiId(qgetenv(kApiIdVarName.utf8()).toInt()); + cSetApiHash(QString::fromLatin1(qgetenv(kApiHashVarName.utf8()))); + } + auto result = executeApplication(); DEBUG_LOG(("Kotatogram finished, result: %1").arg(result)); diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index 13aae8323..373dfd9fe 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -171,8 +171,8 @@ void PhoneWidget::submit() { api().instance().setUserPhone(_sentPhone); _sentRequest = api().request(MTPauth_SendCode( MTP_string(_sentPhone), - MTP_int(ApiId), - MTP_string(ApiHash), + MTP_int(cApiId()), + MTP_string(cApiHash()), MTP_codeSettings(MTP_flags(0)) )).done([=](const MTPauth_SentCode &result) { phoneSubmitDone(result); diff --git a/Telegram/SourceFiles/intro/intro_qr.cpp b/Telegram/SourceFiles/intro/intro_qr.cpp index 99d168b29..a76e63b0e 100644 --- a/Telegram/SourceFiles/intro/intro_qr.cpp +++ b/Telegram/SourceFiles/intro/intro_qr.cpp @@ -311,8 +311,8 @@ void QrWidget::refreshCode() { return; } _requestId = api().request(MTPauth_ExportLoginToken( - MTP_int(ApiId), - MTP_string(ApiHash), + MTP_int(cApiId()), + MTP_string(cApiHash()), MTP_vector(0) )).done([=](const MTPauth_LoginToken &result) { handleTokenResult(result); diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index 63cd09c0c..2dde00a75 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -189,3 +189,30 @@ rpl::producer HoverEmojiPanelChanges() { bool gForwardRetainSelection = false; bool gForwardChatOnClick = false; + +#if defined TDESKTOP_API_ID && defined TDESKTOP_API_HASH + +int gApiId = TDESKTOP_API_ID; +QString gApiHash = MACRO_TO_STRING(TDESKTOP_API_HASH); + +#else // TDESKTOP_API_ID && TDESKTOP_API_HASH + +// To build your version of Telegram Desktop you're required to provide +// your own 'api_id' and 'api_hash' for the Telegram API access. +// +// How to obtain your 'api_id' and 'api_hash' is described here: +// https://core.telegram.org/api/obtaining_api_id +// +// If you're building the application not for deployment, +// but only for test purposes you can comment out the error below. +// +// This will allow you to use TEST ONLY 'api_id' and 'api_hash' which are +// very limited by the Telegram API server. +// +// Your users will start getting internal server errors on login +// if you deploy an app using those 'api_id' and 'api_hash'. + +int gApiId = 0; +QString gApiHash; + +#endif // TDESKTOP_API_ID && TDESKTOP_API_HASH diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index 3c0424814..623aa8a2b 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -124,3 +124,6 @@ void SetHoverEmojiPanel(bool enabled); DeclareSetting(bool, ForwardRetainSelection); DeclareSetting(bool, ForwardChatOnClick); + +DeclareSetting(int, ApiId); +DeclareSetting(QString, ApiHash); diff --git a/Telegram/SourceFiles/mtproto/session_private.cpp b/Telegram/SourceFiles/mtproto/session_private.cpp index 5be847ced..bcaa2c181 100644 --- a/Telegram/SourceFiles/mtproto/session_private.cpp +++ b/Telegram/SourceFiles/mtproto/session_private.cpp @@ -638,7 +638,7 @@ void SessionPrivate::tryToSend() { initWrapper = MTPInitConnection( MTP_flags(Flag::f_params | (mtprotoProxy ? Flag::f_proxy : Flag(0))), - MTP_int(ApiId), + MTP_int(cApiId()), MTP_string(deviceModel), MTP_string(systemVersion), MTP_string(appVersion), diff --git a/Telegram/cmake/telegram_options.cmake b/Telegram/cmake/telegram_options.cmake index 7ba7e9f82..53b0ee444 100644 --- a/Telegram/cmake/telegram_options.cmake +++ b/Telegram/cmake/telegram_options.cmake @@ -22,29 +22,6 @@ if (TDESKTOP_API_TEST) set(TDESKTOP_API_HASH 344583e45741c457fe1862106095a5eb) endif() -if (TDESKTOP_API_ID STREQUAL "0" OR TDESKTOP_API_HASH STREQUAL "") - message(FATAL_ERROR - " \n" - " PROVIDE: -D TDESKTOP_API_ID=[API_ID] -D TDESKTOP_API_HASH=[API_HASH]\n" - " \n" - " > To build your version of Telegram Desktop you're required to provide\n" - " > your own 'api_id' and 'api_hash' for the Telegram API access.\n" - " >\n" - " > How to obtain your 'api_id' and 'api_hash' is described here:\n" - " > https://core.telegram.org/api/obtaining_api_id\n" - " >\n" - " > If you're building the application not for deployment,\n" - " > but only for test purposes you can use TEST ONLY credentials,\n" - " > which are very limited by the Telegram API server:\n" - " >\n" - " > api_id: 17349\n" - " > api_hash: 344583e45741c457fe1862106095a5eb\n" - " >\n" - " > Your users will start getting internal server errors on login\n" - " > if you deploy an app using those 'api_id' and 'api_hash'.\n" - " ") -endif() - if (NOT DESKTOP_APP_USE_PACKAGED) set(TDESKTOP_USE_GTK_FILE_DIALOG ON) endif()