mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Handle foreign instance in COM toast activator.
This commit is contained in:
parent
8d0ff1b61d
commit
8cca75da5c
3 changed files with 26 additions and 12 deletions
|
@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "platform/win/windows_toast_activator.h"
|
#include "platform/win/windows_toast_activator.h"
|
||||||
#include "platform/win/windows_event_filter.h"
|
#include "platform/win/windows_event_filter.h"
|
||||||
#include "platform/win/windows_dlls.h"
|
#include "platform/win/windows_dlls.h"
|
||||||
|
#include "platform/win/specific_win.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/core_settings.h"
|
#include "core/core_settings.h"
|
||||||
|
@ -549,17 +550,34 @@ void Manager::Private::clearNotification(NotificationId id) {
|
||||||
|
|
||||||
void Manager::Private::handleActivation(const ToastActivation &activation) {
|
void Manager::Private::handleActivation(const ToastActivation &activation) {
|
||||||
const auto parsed = qthelp::url_parse_params(activation.args);
|
const auto parsed = qthelp::url_parse_params(activation.args);
|
||||||
|
const auto pid = parsed.value("pid").toULong();
|
||||||
|
const auto my = GetCurrentProcessId();
|
||||||
|
if (pid != my) {
|
||||||
|
DEBUG_LOG(("Toast Info: "
|
||||||
|
"Got activation \"%1\", my %2, activating %3."
|
||||||
|
).arg(activation.args
|
||||||
|
).arg(my
|
||||||
|
).arg(pid));
|
||||||
|
psActivateProcess(pid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto action = parsed.value("action");
|
const auto action = parsed.value("action");
|
||||||
const auto id = NotificationId{
|
const auto id = NotificationId{
|
||||||
.full = FullPeer{
|
.full = FullPeer{
|
||||||
.sessionId = parsed.value("s").toULongLong(),
|
.sessionId = parsed.value("session").toULongLong(),
|
||||||
.peerId = PeerId(parsed.value("p").toULongLong()),
|
.peerId = PeerId(parsed.value("peer").toULongLong()),
|
||||||
},
|
},
|
||||||
.msgId = MsgId(parsed.value("m").toLongLong()),
|
.msgId = MsgId(parsed.value("msg").toLongLong()),
|
||||||
};
|
};
|
||||||
if (!id.full.sessionId || !id.full.peerId || !id.msgId) {
|
if (!id.full.sessionId || !id.full.peerId || !id.msgId) {
|
||||||
|
DEBUG_LOG(("Toast Info: Got activation \"%1\", my %1, skipping."
|
||||||
|
).arg(activation.args
|
||||||
|
).arg(pid));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DEBUG_LOG(("Toast Info: Got activation \"%1\", my %1, handling."
|
||||||
|
).arg(activation.args
|
||||||
|
).arg(pid));
|
||||||
auto text = TextWithTags();
|
auto text = TextWithTags();
|
||||||
for (const auto &entry : activation.input) {
|
for (const auto &entry : activation.input) {
|
||||||
if (entry.key == "fastReply") {
|
if (entry.key == "fastReply") {
|
||||||
|
@ -633,7 +651,8 @@ bool Manager::Private::showNotificationInTryCatch(
|
||||||
.full = key,
|
.full = key,
|
||||||
.msgId = msgId
|
.msgId = msgId
|
||||||
};
|
};
|
||||||
const auto idString = u"s=%1&p=%2&m=%3"_q
|
const auto idString = u"pid=%1&session=%2&peer=%3&msg=%4"_q
|
||||||
|
.arg(GetCurrentProcessId())
|
||||||
.arg(key.sessionId)
|
.arg(key.sessionId)
|
||||||
.arg(key.peerId.value)
|
.arg(key.peerId.value)
|
||||||
.arg(msgId.bare);
|
.arg(msgId.bare);
|
||||||
|
|
|
@ -146,14 +146,6 @@ void DeleteMyModules() {
|
||||||
void psActivateProcess(uint64 pid) {
|
void psActivateProcess(uint64 pid) {
|
||||||
if (pid) {
|
if (pid) {
|
||||||
::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid);
|
::EnumWindows((WNDENUMPROC)_ActivateProcess, (LPARAM)&pid);
|
||||||
} else if (Core::IsAppLaunched()) {
|
|
||||||
if (const auto window = Core::App().activeWindow()) {
|
|
||||||
if (const auto handle = window->widget()->windowHandle()) {
|
|
||||||
if (const auto id = handle->winId()) {
|
|
||||||
SetForegroundWindow(HWND(id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,9 @@ HRESULT ToastActivator::Activate(
|
||||||
_In_ LPCWSTR invokedArgs,
|
_In_ LPCWSTR invokedArgs,
|
||||||
_In_reads_(dataCount) const NOTIFICATION_USER_INPUT_DATA *data,
|
_In_reads_(dataCount) const NOTIFICATION_USER_INPUT_DATA *data,
|
||||||
ULONG dataCount) {
|
ULONG dataCount) {
|
||||||
|
DEBUG_LOG(("Toast Info: COM Activated \"%1\" with args \"%2\"."
|
||||||
|
).arg(QString::fromWCharArray(appUserModelId)
|
||||||
|
).arg(QString::fromWCharArray(invokedArgs)));
|
||||||
const auto string = &ToastActivation::String;
|
const auto string = &ToastActivation::String;
|
||||||
auto input = std::vector<ToastActivation::UserInput>();
|
auto input = std::vector<ToastActivation::UserInput>();
|
||||||
input.reserve(dataCount);
|
input.reserve(dataCount);
|
||||||
|
|
Loading…
Add table
Reference in a new issue