Rewrite bingmaps check to C++/WinRT.

This commit is contained in:
John Preston 2021-09-26 17:17:57 +04:00
parent d5c6d9a231
commit 8759ca4577
2 changed files with 25 additions and 22 deletions

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/win/windows_app_user_model_id.h" #include "platform/win/windows_app_user_model_id.h"
#include "platform/win/windows_dlls.h" #include "platform/win/windows_dlls.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/platform/win/base_windows_winrt.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -547,27 +548,29 @@ void psSendToMenu(bool send, bool silent) {
} }
bool psLaunchMaps(const Data::LocationPoint &point) { bool psLaunchMaps(const Data::LocationPoint &point) {
IApplicationAssociationRegistration *aar = nullptr; const auto aar = base::WinRT::TryCreateInstance<
IApplicationAssociationRegistration
const auto hr = CoCreateInstance( >(CLSID_ApplicationAssociationRegistration);
CLSID_ApplicationAssociationRegistration, if (!aar) {
nullptr, return false;
CLSCTX_INPROC,
__uuidof(IApplicationAssociationRegistration),
reinterpret_cast<void**>(&aar));
if (SUCCEEDED(hr && aar)) {
LPWSTR current_app = nullptr;
const auto result = aar->QueryCurrentDefault(
L"bingmaps",
AT_URLPROTOCOL,
AL_EFFECTIVE,
&current_app);
if (FAILED(result)) {
return false;
}
} }
return QDesktopServices::openUrl(qsl("bingmaps:?lvl=16&collection=point.%1_%2_Point").arg(point.latAsString()).arg(point.lonAsString())); auto handler = (LPWSTR)nullptr;
const auto guard = gsl::finally([&] {
if (handler) {
::CoTaskMemFree(handler);
}
});
const auto result = aar->QueryCurrentDefault(
L"bingmaps",
AT_URLPROTOCOL,
AL_EFFECTIVE,
&handler);
if (FAILED(result) || !handler) {
return false;
}
const auto url = u"bingmaps:?lvl=16&collection=point.%1_%2_Point"_q;
return QDesktopServices::openUrl(
url.arg(point.latAsString()).arg(point.lonAsString()));
} }

@ -1 +1 @@
Subproject commit dae9570be294027a6ca4a4f2e9100077ef2c5e55 Subproject commit 5f1c3cb09c1d9e6728090146c66ba34202e6aba6