diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 07:45:19 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-08-31 07:45:19 +0000 |
commit | 291d2b6a67bf9501c5427758092805b66aa44dcf (patch) | |
tree | 079076be3a220a78fdc5e2b63077adcb407d0ef9 /plugins/Toaster | |
parent | 081f1880ea898bba1bfd2ba2ff79b5e4de929b86 (diff) |
Toaster: more fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@15124 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster')
-rw-r--r-- | plugins/Toaster/src/main.cpp | 8 | ||||
-rw-r--r-- | plugins/Toaster/src/services.cpp | 34 | ||||
-rw-r--r-- | plugins/Toaster/src/stdafx.h | 12 | ||||
-rw-r--r-- | plugins/Toaster/src/toast_notification.cpp | 1 |
4 files changed, 26 insertions, 29 deletions
diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp index 39f4c549b7..004cec4734 100644 --- a/plugins/Toaster/src/main.cpp +++ b/plugins/Toaster/src/main.cpp @@ -22,7 +22,6 @@ PLUGININFOEX pluginInfo = DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
{
g_hInstance = hInstance;
-
return TRUE;
}
@@ -34,15 +33,12 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) return NULL;
}
return &pluginInfo;
-
}
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
- CoInitialize(NULL);
-
HookEvent(ME_SYSTEM_PRESHUTDOWN, &OnPreShutdown);
InitServices();
@@ -59,13 +55,11 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void)
{
- CoUninitialize();
-
return 0;
}
int OnPreShutdown(WPARAM, LPARAM)
{
- HideAllToasts();
+ CallFunctionAsync(&HideAllToasts, NULL);
return 0;
}
\ No newline at end of file diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp index 689dabae4a..c5eaf84f6a 100644 --- a/plugins/Toaster/src/services.cpp +++ b/plugins/Toaster/src/services.cpp @@ -63,22 +63,24 @@ static void __cdecl OnToastNotificationClicked(void* arg) }
}
-static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact)
+void __stdcall ShowToastNotification(void* p)
{
+ std::unique_ptr<ToastData> td((ToastData*)p);
+
if (!db_get_b(0, "Popup", "ModuleIsEnabled", 1))
return;
ptrT imagePath;
callbackArg *arg = (callbackArg*)mir_calloc(sizeof(callbackArg));
- if (hContact)
+ if (td->hContact)
{
- arg->hContact = hContact;
- const char* szProto = GetContactProto(hContact);
+ arg->hContact = td->hContact;
+ const char* szProto = GetContactProto(td->hContact);
if (ProtoServiceExists(szProto, PS_GETAVATARINFO))
{
PROTO_AVATAR_INFORMATION pai = { 0 };
- pai.hContact = hContact;
+ pai.hContact = td->hContact;
if (CallProtoService(szProto, PS_GETAVATARINFO, 0, (LPARAM)&pai) == GAIR_SUCCESS)
{
imagePath = mir_tstrdup(pai.filename);
@@ -94,7 +96,7 @@ static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact) }
}
- arg->notification = new ToastNotification(text, title, imagePath);
+ arg->notification = new ToastNotification(td->tszText, td->tszTitle, imagePath);
HRESULT hr = arg->notification->Initialize();
if (SUCCEEDED(hr))
@@ -104,12 +106,6 @@ static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact) }
else
{
- OutputDebugStringA(CMStringA(FORMAT, "Toaster error: HRESULT = %lld", hr));
-#ifdef _DEBUG
- DebugBreak();
-#else
- Netlib_Logf(NULL, "Toaster: " __FUNCTION__ " failed: HRESULT = %lld", hr);
-#endif
delete arg->notification;
}
}
@@ -120,7 +116,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) ptrW text(mir_a2u(ppd->lpzText));
ptrW contactName(mir_a2u(ppd->lpzContactName));
- ShowToastNotification(text, contactName, ppd->lchContact);
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, contactName, text));
return 0;
}
@@ -128,9 +124,7 @@ static INT_PTR CreatePopup(WPARAM wParam, LPARAM) static INT_PTR CreatePopupW(WPARAM wParam, LPARAM)
{
POPUPDATAW *ppd = (POPUPDATAW*)wParam;
-
- ShowToastNotification(ppd->lpwzText, ppd->lpwzContactName, ppd->lchContact);
-
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, ppd->lpwzContactName, ppd->lpwzText));
return 0;
}
@@ -150,7 +144,7 @@ static INT_PTR CreatePopup2(WPARAM wParam, LPARAM) title = mir_a2u(ppd->lpzTitle);
}
- ShowToastNotification(text, title, ppd->lchContact);
+ CallFunctionAsync(&ShowToastNotification, new ToastData(ppd->lchContact, title, text));
return 0;
}
@@ -169,7 +163,7 @@ static INT_PTR PopupQuery(WPARAM wParam, LPARAM) {
bool enabled = db_get_b(0, "Popup", "ModuleIsEnabled", 1) != 0;
if (enabled) db_set_b(0, "Popup", "ModuleIsEnabled", 0);
- HideAllToasts();
+ CallFunctionAsync(&HideAllToasts, NULL);
return enabled;
}
break;
@@ -182,7 +176,7 @@ static INT_PTR PopupQuery(WPARAM wParam, LPARAM) }
}
-void HideAllToasts()
+void __stdcall HideAllToasts(void*)
{
mir_cslock lck(csNotifications);
while (lstNotifications.getCount())
@@ -198,4 +192,4 @@ void InitServices() CreateServiceFunction(MS_POPUP_ADDPOPUPW, CreatePopupW);
CreateServiceFunction(MS_POPUP_ADDPOPUP2, CreatePopup2);
CreateServiceFunction(MS_POPUP_QUERY, PopupQuery);
-}
+}
\ No newline at end of file diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h index ac22e2cf5a..3fce653263 100644 --- a/plugins/Toaster/src/stdafx.h +++ b/plugins/Toaster/src/stdafx.h @@ -7,6 +7,7 @@ #include <windows.ui.notifications.h>
#include <ShObjIdl.h>
#include <propvarutil.h>
+#include <memory>
#include <newpluginapi.h>
#include <m_system_cpp.h>
@@ -44,7 +45,16 @@ struct callbackArg ToastNotification* notification;
};
+struct ToastData
+{
+ MCONTACT hContact;
+ TCHAR *tszTitle;
+ TCHAR *tszText;
+
+ ToastData(MCONTACT _hContact, TCHAR *_tszTitle, TCHAR *_tszText) : hContact(_hContact), tszTitle(_tszTitle), tszText(_tszText) {}
+};
+
void InitServices();
int OnPreShutdown(WPARAM, LPARAM);
-void HideAllToasts();
+void __stdcall HideAllToasts(void*);
#endif //_COMMON_H_
diff --git a/plugins/Toaster/src/toast_notification.cpp b/plugins/Toaster/src/toast_notification.cpp index 8c2eebf32b..b681d3ce85 100644 --- a/plugins/Toaster/src/toast_notification.cpp +++ b/plugins/Toaster/src/toast_notification.cpp @@ -204,7 +204,6 @@ HRESULT ToastNotification::Create(_Outptr_ ABI::Windows::UI::Notifications::IToa hr = Windows::Foundation::GetActivationFactory(StringReferenceWrapper(RuntimeClass_Windows_UI_Notifications_ToastNotification).Get(), &factory);
if (FAILED(hr))
return hr;
-
return hr = factory->CreateToastNotification(xml.Get(), _notification);
}
|