Add possibility to set api id and api hash at runtime (#92)

This commit is contained in:
ilya-fedin 2020-07-23 16:51:25 +04:00 committed by GitHub
parent 725e110278
commit 866f83aa17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 58 deletions

View file

@ -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

View file

@ -343,7 +343,7 @@ QString PlatformString() {
void StartCatching(not_null<Core::Launcher*> 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();

View file

@ -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));

View file

@ -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);

View file

@ -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<MTPint>(0)
)).done([=](const MTPauth_LoginToken &result) {
handleTokenResult(result);

View file

@ -189,3 +189,30 @@ rpl::producer<bool> 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

View file

@ -124,3 +124,6 @@ void SetHoverEmojiPanel(bool enabled);
DeclareSetting(bool, ForwardRetainSelection);
DeclareSetting(bool, ForwardChatOnClick);
DeclareSetting(int, ApiId);
DeclareSetting(QString, ApiHash);

View file

@ -638,7 +638,7 @@ void SessionPrivate::tryToSend() {
initWrapper = MTPInitConnection<SerializedRequest>(
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),

View file

@ -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()