mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-05-24 00:34:01 +02:00
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
For license and copyright information please follow this link:
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
*/
|
|
#include "core/current_geo_location.h"
|
|
|
|
#include "base/platform/base_platform_info.h"
|
|
#include "data/raw/raw_countries_bounds.h"
|
|
#include "platform/platform_current_geo_location.h"
|
|
|
|
namespace Core {
|
|
|
|
GeoLocation ResolveCurrentCountryLocation() {
|
|
const auto iso2 = Platform::SystemCountry().toUpper();
|
|
const auto &bounds = Raw::CountryBounds();
|
|
const auto i = bounds.find(iso2);
|
|
if (i == end(bounds)) {
|
|
return {
|
|
.accuracy = GeoLocationAccuracy::Failed,
|
|
};
|
|
}
|
|
return {
|
|
.point = {
|
|
(i->second.minLat + i->second.maxLat) / 2.,
|
|
(i->second.minLon + i->second.maxLon) / 2.,
|
|
},
|
|
.bounds = {
|
|
i->second.minLat,
|
|
i->second.minLon,
|
|
i->second.maxLat - i->second.minLat,
|
|
i->second.maxLon - i->second.minLon,
|
|
},
|
|
.accuracy = GeoLocationAccuracy::Country,
|
|
};
|
|
}
|
|
|
|
void ResolveCurrentGeoLocation(Fn<void(GeoLocation)> callback) {
|
|
using namespace Platform;
|
|
return ResolveCurrentExactLocation([done = std::move(callback)](
|
|
GeoLocation result) {
|
|
done(result.accuracy != GeoLocationAccuracy::Failed
|
|
? result
|
|
: ResolveCurrentCountryLocation());
|
|
});
|
|
}
|
|
|
|
} // namespace Core
|