From ce0deed0dc079bb5c355aafd4ea461a39b98998b Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Thu, 18 Feb 2021 06:24:53 -0300 Subject: [PATCH] Initial callback support --- plugins/windows-notification/CMakeLists.txt | 12 +- .../api/include/callbacks.h | 48 ++++++++ .../windows-notification/api/include/enums.h | 16 +++ .../api/include/notificationhandler.hpp | 18 +++ .../api/include/shortcutcreator.h | 2 +- .../api/include/toastnotification.h | 52 +++++++++ .../api/include/win32.hpp | 2 +- .../api/src/callbacks.cpp | 37 ++++++ .../api/src/shortcutcreator.cpp | 2 +- .../api/src/toastnotification.cpp | 106 ++++++++++++++++++ .../windows-notification/api/src/win32.cpp | 2 +- .../windows-notification/api/src/winrt.cpp | 6 + .../src/DinoWinToastDllExport.h | 11 -- .../src/DinoWinToastLib.h | 46 -------- .../src/DinoWinToastTemplate.h | 54 --------- plugins/windows-notification/src/plugin.vala | 59 +++++++--- .../windows-notification/vapi/callbacks.vapi | 43 +++++++ plugins/windows-notification/vapi/enums.vapi | 9 ++ .../vapi/shortcutcreator.vapi | 2 +- .../vapi/toastnotification.vapi | 36 ++++++ plugins/windows-notification/vapi/win32.vapi | 5 +- plugins/windows-notification/vapi/winrt.vapi | 2 +- 22 files changed, 437 insertions(+), 133 deletions(-) create mode 100644 plugins/windows-notification/api/include/callbacks.h create mode 100644 plugins/windows-notification/api/include/enums.h create mode 100644 plugins/windows-notification/api/include/notificationhandler.hpp create mode 100644 plugins/windows-notification/api/include/toastnotification.h create mode 100644 plugins/windows-notification/api/src/callbacks.cpp create mode 100644 plugins/windows-notification/api/src/toastnotification.cpp delete mode 100644 plugins/windows-notification/src/DinoWinToastDllExport.h delete mode 100644 plugins/windows-notification/src/DinoWinToastLib.h delete mode 100644 plugins/windows-notification/src/DinoWinToastTemplate.h create mode 100644 plugins/windows-notification/vapi/callbacks.vapi create mode 100644 plugins/windows-notification/vapi/enums.vapi create mode 100644 plugins/windows-notification/vapi/toastnotification.vapi diff --git a/plugins/windows-notification/CMakeLists.txt b/plugins/windows-notification/CMakeLists.txt index 4d569394..71a989c7 100644 --- a/plugins/windows-notification/CMakeLists.txt +++ b/plugins/windows-notification/CMakeLists.txt @@ -12,20 +12,28 @@ vala_precompile(WINDOWS_NOTIFICATION_VALA_C SOURCES src/plugin.vala src/register_plugin.vala + # src/win_notification_provider.vala CUSTOM_VAPIS ${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi ${CMAKE_BINARY_DIR}/exports/dino.vapi ${CMAKE_BINARY_DIR}/exports/qlite.vapi ${CMAKE_CURRENT_SOURCE_DIR}/vapi/win32.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/winrt.vapi ${CMAKE_CURRENT_SOURCE_DIR}/vapi/shortcutcreator.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/toastnotification.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/enums.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/callbacks.vapi PACKAGES ${WINDOWS_NOTIFICATION_PACKAGES} ) set(WINDOWS_API_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/api/src/win32.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/api/src/winrt.cpp ${CMAKE_CURRENT_SOURCE_DIR}/api/src/converter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/api/src/shortcutcreator.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/api/src/toastnotification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/api/src/callbacks.cpp ) add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} ${WINDOWS_API_SOURCES}) @@ -33,6 +41,7 @@ add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} ${WINDOWS target_include_directories(windows-notification PRIVATE ${PROJECT_SOURCE_DIR}/api/include + ${PROJECT_SOURCE_DIR}/yolort/include ) find_library(shlwapi_LIBRARY shlwapi libshlwapi libshlwapi.a HINTS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}) @@ -57,8 +66,7 @@ endif(NOT mincore_LIBRARY) target_link_libraries(windows-notification libdino ${shlwapi_LIBRARY} ${propsys_LIBRARY} ${ntdll_LIBRARY} ${mincore_LIBRARY} ${WINDOWS_NOTIFICATION_PACKAGES}) target_compile_features(windows-notification PRIVATE cxx_std_20) -# target_compile_options(windows-notification PRIVATE -municode -DUNICODE -fcoroutines -iquote ../../include/winrt/yolort_impl) -target_compile_options(windows-notification PRIVATE -municode -DUNICODE -fcoroutines) +target_compile_options(windows-notification PRIVATE -municode -DUNICODE -fcoroutines -iquote ${PROJECT_SOURCE_DIR}/yolort/include/winrt/yolort_impl) set_target_properties(windows-notification PROPERTIES PREFIX "") set_target_properties(windows-notification PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) diff --git a/plugins/windows-notification/api/include/callbacks.h b/plugins/windows-notification/api/include/callbacks.h new file mode 100644 index 00000000..736c8ffd --- /dev/null +++ b/plugins/windows-notification/api/include/callbacks.h @@ -0,0 +1,48 @@ +#pragma once + +#include "enums.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + // simple + typedef void(*Notification_Callback_Simple)(void* userdata); + + typedef struct { + Notification_Callback_Simple callback; + void* context; + void(*free)(void*); + } SimpleNotificationCallback; + + SimpleNotificationCallback* NewSimpleNotificationCallback(); + void DestroySimpleNotificationCallback(SimpleNotificationCallback* callback); + + // with index + typedef void(*Notification_Callback_ActivatedWithActionIndex)(int action_id, void* userdata); + + typedef struct { + Notification_Callback_ActivatedWithActionIndex callback; + void* context; + void(*free)(void*); + } ActivatedWithActionIndexNotificationCallback; + + ActivatedWithActionIndexNotificationCallback* NewActivatedWithActionIndexNotificationCallback(); + void DestroyActivatedWithActionIndexNotificationCallback(ActivatedWithActionIndexNotificationCallback* callback); + + // with dismissed reason + typedef void(*Notification_Callback_Dismissed)(Dismissed_Reason reason, void* userdata); + + typedef struct { + Notification_Callback_Dismissed callback; + void* context; + void(*free)(void*); + } DismissedNotificationCallback; + + DismissedNotificationCallback* NewDismissedNotificationCallback(); + void DestroyDismissedNotificationCallback(DismissedNotificationCallback* callback); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/plugins/windows-notification/api/include/enums.h b/plugins/windows-notification/api/include/enums.h new file mode 100644 index 00000000..61a53568 --- /dev/null +++ b/plugins/windows-notification/api/include/enums.h @@ -0,0 +1,16 @@ +#pragma once + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum { + Dismissed_Reason_Activated = 0, + Dismissed_Reason_ApplicationHidden, + Dismissed_Reason_TimedOut + } Dismissed_Reason; + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/plugins/windows-notification/api/include/notificationhandler.hpp b/plugins/windows-notification/api/include/notificationhandler.hpp new file mode 100644 index 00000000..1f961c6b --- /dev/null +++ b/plugins/windows-notification/api/include/notificationhandler.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "typedefinitions.h" + +class NotificationHandler { +private: + dinoWinToastLib_Notification_Callbacks callbacks{}; + +public: + WinToastHandler(dinoWinToastLib_Notification_Callbacks callbacks); + ~WinToastHandler(); + + // Public interfaces + void toastActivated() const; + void toastActivated(int actionIndex) const; + void toastDismissed(WinToastLib::IWinToastHandler::WinToastDismissalReason state) const; + void toastFailed() const; +}; \ No newline at end of file diff --git a/plugins/windows-notification/api/include/shortcutcreator.h b/plugins/windows-notification/api/include/shortcutcreator.h index 1c6c950b..b9259f18 100644 --- a/plugins/windows-notification/api/include/shortcutcreator.h +++ b/plugins/windows-notification/api/include/shortcutcreator.h @@ -7,7 +7,7 @@ extern "C" { #endif - gboolean TryCreateShortcut(gchar* aumid); + gboolean TryCreateShortcut(const gchar* aumid); #ifdef __cplusplus } diff --git a/plugins/windows-notification/api/include/toastnotification.h b/plugins/windows-notification/api/include/toastnotification.h new file mode 100644 index 00000000..705b061a --- /dev/null +++ b/plugins/windows-notification/api/include/toastnotification.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include "callbacks.h" + +#ifdef __cplusplus + #include + + class DinoToastNotification { + private: + SimpleNotificationCallback activated; + ActivatedWithActionIndexNotificationCallback activatedWithIndex; + DismissedNotificationCallback dismissed; + SimpleNotificationCallback failed; + + public: + DinoToastNotification() = default; + ~DinoToastNotification(); + + void SetActivated(const SimpleNotificationCallback& callback); + void SetActivatedWithIndex(const ActivatedWithActionIndexNotificationCallback& callback); + void SetDismissed(const DismissedNotificationCallback& callback); + void SetFailed(const SimpleNotificationCallback& callback); + + // default move + DinoToastNotification(DinoToastNotification&& other) = default; + DinoToastNotification& operator=(DinoToastNotification&& other) = default; + + // delete copy + DinoToastNotification(const DinoToastNotification& other) = delete; + DinoToastNotification& operator=(const DinoToastNotification& other) = delete; + }; + +extern "C" { +#endif + #ifdef __cplusplus + typedef std::shared_ptr* DinoToastNotification_t; + #else + typedef void* DinoToastNotification_t; + #endif + + DinoToastNotification_t NewNotification(); + void DestroyNotification(DinoToastNotification_t notification); + DinoToastNotification_t CopyNotification(); + + void set_Activated(DinoToastNotification_t notification, const SimpleNotificationCallback* callback); + void set_ActivatedWithIndex(DinoToastNotification_t notification, const ActivatedWithActionIndexNotificationCallback* callback); + void set_Dismissed(DinoToastNotification_t notification, const DismissedNotificationCallback* callback); + void set_Failed(DinoToastNotification_t notification, const SimpleNotificationCallback* callback); +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/plugins/windows-notification/api/include/win32.hpp b/plugins/windows-notification/api/include/win32.hpp index 5619335e..1ee8872a 100644 --- a/plugins/windows-notification/api/include/win32.hpp +++ b/plugins/windows-notification/api/include/win32.hpp @@ -19,7 +19,7 @@ extern "C" { #endif gboolean SupportsModernNotifications(); - gboolean SetAppModelID(gchar* aumid); + gboolean SetAppModelID(const gchar* aumid); #ifdef __cplusplus } #endif diff --git a/plugins/windows-notification/api/src/callbacks.cpp b/plugins/windows-notification/api/src/callbacks.cpp new file mode 100644 index 00000000..0a1d7859 --- /dev/null +++ b/plugins/windows-notification/api/src/callbacks.cpp @@ -0,0 +1,37 @@ +#include "callbacks.h" + +SimpleNotificationCallback* NewSimpleNotificationCallback() +{ + return new SimpleNotificationCallback(); +} +void DestroySimpleNotificationCallback(SimpleNotificationCallback* callback) +{ + if (callback != nullptr) + { + delete callback; + } +} + +ActivatedWithActionIndexNotificationCallback* NewActivatedWithActionIndexNotificationCallback() +{ + return new ActivatedWithActionIndexNotificationCallback(); +} +void DestroyActivatedWithActionIndexNotificationCallback(ActivatedWithActionIndexNotificationCallback* callback) +{ + if (callback != nullptr) + { + delete callback; + } +} + +DismissedNotificationCallback* NewDismissedNotificationCallback() +{ + return new DismissedNotificationCallback(); +} +void DestroyDismissedNotificationCallback(DismissedNotificationCallback* callback) +{ + if (callback != nullptr) + { + delete callback; + } +} \ No newline at end of file diff --git a/plugins/windows-notification/api/src/shortcutcreator.cpp b/plugins/windows-notification/api/src/shortcutcreator.cpp index 1469785d..356fea48 100644 --- a/plugins/windows-notification/api/src/shortcutcreator.cpp +++ b/plugins/windows-notification/api/src/shortcutcreator.cpp @@ -148,7 +148,7 @@ int32_t TryCreateShortcutInternal(const std::wstring& aumid) extern "C" { - gboolean TryCreateShortcut(gchar* aumid) + gboolean TryCreateShortcut(const gchar* aumid) { auto result = char_to_wstr(aumid); if (result.empty()) diff --git a/plugins/windows-notification/api/src/toastnotification.cpp b/plugins/windows-notification/api/src/toastnotification.cpp new file mode 100644 index 00000000..45eb0945 --- /dev/null +++ b/plugins/windows-notification/api/src/toastnotification.cpp @@ -0,0 +1,106 @@ +#include "toastnotification.h" + +DinoToastNotification_t NewNotification() { + return new std::shared_ptr(); +} + +void DestroyNotification(DinoToastNotification_t notification) { + if (notification != nullptr) { + delete notification; + } +} + +DinoToastNotification_t CopyNotification(DinoToastNotification_t notification) +{ + if (notification == nullptr) { + return nullptr; + } + return new std::shared_ptr(*notification); +} + +void set_Activated(DinoToastNotification_t notification, const SimpleNotificationCallback* callback) +{ + (*notification)->SetActivated(*callback); +} + +void set_ActivatedWithIndex(DinoToastNotification_t notification, const ActivatedWithActionIndexNotificationCallback* callback) +{ + (*notification)->SetActivatedWithIndex(*callback); +} + +void set_Dismissed(DinoToastNotification_t notification, const DismissedNotificationCallback* callback) +{ + (*notification)->SetDismissed(*callback); +} + +void set_Failed(DinoToastNotification_t notification, const SimpleNotificationCallback* callback) +{ + (*notification)->SetFailed(*callback); +} + +void DinoToastNotification::SetActivated(const SimpleNotificationCallback& callback) +{ + if (activated.callback != nullptr) + { + activated.free(activated.context); + activated = SimpleNotificationCallback { 0 }; + } + + activated = callback; +} + +void DinoToastNotification::SetActivatedWithIndex(const ActivatedWithActionIndexNotificationCallback& callback) +{ + if (activatedWithIndex.callback != nullptr) + { + activatedWithIndex.free(activatedWithIndex.context); + activatedWithIndex = ActivatedWithActionIndexNotificationCallback { 0 }; + } + + activatedWithIndex = callback; +} + +void DinoToastNotification::SetDismissed(const DismissedNotificationCallback& callback) +{ + if (dismissed.callback != nullptr) + { + dismissed.free(dismissed.context); + dismissed = DismissedNotificationCallback { 0 }; + } + + dismissed = callback; +} + +void DinoToastNotification::SetFailed(const SimpleNotificationCallback& callback) +{ + if (failed.callback != nullptr) + { + failed.free(failed.context); + failed = SimpleNotificationCallback { 0 }; + } + + failed = callback; +} + +DinoToastNotification::~DinoToastNotification() +{ + if (activated.context != nullptr && + activated.free != nullptr) { + activated.free(activated.context); + } + + if (activatedWithIndex.context != nullptr && + activatedWithIndex.free != nullptr) { + activatedWithIndex.free(activatedWithIndex.context); + } + + if (dismissed.context != nullptr && + dismissed.free != nullptr) { + dismissed.free(dismissed.context); + } + + if (failed.context != nullptr && + failed.free != nullptr) { + failed.free(failed.context); + } +} \ No newline at end of file diff --git a/plugins/windows-notification/api/src/win32.cpp b/plugins/windows-notification/api/src/win32.cpp index 9d68737d..840d3416 100644 --- a/plugins/windows-notification/api/src/win32.cpp +++ b/plugins/windows-notification/api/src/win32.cpp @@ -47,7 +47,7 @@ extern "C" return FALSE; } - gboolean SetAppModelID(gchar* aumid) + gboolean SetAppModelID(const gchar* aumid) { auto result = char_to_wstr(aumid); if (result.empty()) diff --git a/plugins/windows-notification/api/src/winrt.cpp b/plugins/windows-notification/api/src/winrt.cpp index 6eafe395..fbcada2e 100644 --- a/plugins/windows-notification/api/src/winrt.cpp +++ b/plugins/windows-notification/api/src/winrt.cpp @@ -1,2 +1,8 @@ +#include + #include "winrt.h" +gboolean Initialize() +{ + winrt::init_apartment(); +} \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastDllExport.h b/plugins/windows-notification/src/DinoWinToastDllExport.h deleted file mode 100644 index ee777aaa..00000000 --- a/plugins/windows-notification/src/DinoWinToastDllExport.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef _WIN32 -#ifdef DINOWINTOASTLIB_EXPORTS -#define DINOWINTOASTLIB_API __declspec(dllexport) -#else -#define DINOWINTOASTLIB_API __declspec(dllimport) -#endif -#else -#define DINOWINTOASTLIB_API -#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastLib.h b/plugins/windows-notification/src/DinoWinToastLib.h deleted file mode 100644 index bb66ae51..00000000 --- a/plugins/windows-notification/src/DinoWinToastLib.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "DinoWinToastDllExport.h" -#include "DinoWinToastTemplate.h" - -#ifdef __cplusplus -extern "C" { -#endif - typedef enum { - Reason_Activated = 0, - Reason_ApplicationHidden, - Reason_TimedOut - } dinoWinToastLib_Notification_Reason; - - typedef void(*dinoWinToastLib_Notification_Callback_Simple)(void* userdata); - typedef void(*dinoWinToastLib_Notification_Callback_ActivatedWithActionIndex)(int action_id, void* userdata); - typedef void(*dinoWinToastLib_Notification_Callback_Dismissed)(dinoWinToastLib_Notification_Reason reason, void* userdata); - - typedef struct { - dinoWinToastLib_Notification_Callback_Simple activated; - void* activated_context; - void(*activated_free)(void*); - - dinoWinToastLib_Notification_Callback_ActivatedWithActionIndex activatedWithIndex; - void* activatedWithIndex_context; - void(*activatedWithIndex_free)(void*); - - dinoWinToastLib_Notification_Callback_Dismissed dismissed; - void* dismissed_context; - void(*dismissed_free)(void*); - - dinoWinToastLib_Notification_Callback_Simple failed; - void* failed_context; - void(*failed_free)(void*); - - } dinoWinToastLib_Notification_Callbacks; - - DINOWINTOASTLIB_API dinoWinToastLib_Notification_Callbacks* dinoWinToastLib_NewCallbacks(); - DINOWINTOASTLIB_API void dinoWinToastLib_DestroyCallbacks(dinoWinToastLib_Notification_Callbacks* callbacks); - - DINOWINTOASTLIB_API int dinoWinToastLib_Init(); - DINOWINTOASTLIB_API int64_t dinoWinToastLib_ShowMessage(dino_wintoasttemplate templ, dinoWinToastLib_Notification_Callbacks* callbacks); - DINOWINTOASTLIB_API int dinoWinToastLib_RemoveNotification(int64_t notification_id); -#ifdef __cplusplus -} // extern "C" -#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastTemplate.h b/plugins/windows-notification/src/DinoWinToastTemplate.h deleted file mode 100644 index b4253961..00000000 --- a/plugins/windows-notification/src/DinoWinToastTemplate.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include -#include "DinoWinToastDllExport.h" - -#ifdef __cplusplus -extern "C" { -#endif - typedef void* dino_wintoasttemplate; - - typedef enum { - Duration_System, - Duration_Short, - Duration_Long - } dino_wintoasttemplate_duration; - - typedef enum { - AudioOption_Default = 0, - AudioOption_Silent = 1, - AudioOption_Loop = 2 - } dino_wintoasttemplate_audiooption; - - typedef enum { - TextField_FirstLine = 0, - TextField_SecondLine, - TextField_ThirdLine - } dino_wintoasttemplate_textfield; - - typedef enum { - TemplateType_ImageAndText01 = 0, - TemplateType_ImageAndText02, - TemplateType_ImageAndText03, - TemplateType_ImageAndText04, - TemplateType_Text01, - TemplateType_Text02, - TemplateType_Text03, - TemplateType_Text04, - TemplateType_WinToastTemplateTypeCount - } dino_wintoasttemplate_wintoasttemplatetype; - - DINOWINTOASTLIB_API dino_wintoasttemplate dino_wintoasttemplate_new(dino_wintoasttemplate_wintoasttemplatetype templ); - DINOWINTOASTLIB_API void dino_wintoasttemplate_destroy(dino_wintoasttemplate templ); - - DINOWINTOASTLIB_API void dino_wintoasttemplate_setTextField(dino_wintoasttemplate templ, const char* txt, dino_wintoasttemplate_textfield pos); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setImagePath(dino_wintoasttemplate templ, const char* imgPath); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setAudioPath(dino_wintoasttemplate templ, const char* audioPath); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setAttributionText(dino_wintoasttemplate templ, const char* attributionText); - DINOWINTOASTLIB_API void dino_wintoasttemplate_addAction(dino_wintoasttemplate templ, const char* label); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setAudioOption(dino_wintoasttemplate templ, dino_wintoasttemplate_audiooption audioOption); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setDuration(dino_wintoasttemplate templ, dino_wintoasttemplate_duration duration); - DINOWINTOASTLIB_API void dino_wintoasttemplate_setExpiration(dino_wintoasttemplate templ, int64_t millisecondsFromNow); -#ifdef __cplusplus -} // extern C -#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala index ceaf0234..7ef8c2a2 100644 --- a/plugins/windows-notification/src/plugin.vala +++ b/plugins/windows-notification/src/plugin.vala @@ -1,29 +1,62 @@ using Gee; using Dino.Entities; -using Win32Api; -using ShortcutCreator; +using Dino.Plugins.WindowsNotification.Vapi; namespace Dino.Plugins.WindowsNotification { public class Plugin : RootInterface, Object { + private static string AUMID = "org.dino.Dino"; + + public int m { get; set; } + public void registered(Dino.Application app) { - var created = ShortcutCreator.TryCreateShortcut("org.dino.Dino"); - if (!created) + if (!WinRTApi.Initialize()) { - // log somewhere, return + // log error, return } - var initialized = - - if (!Win32Api.SupportsModernNotifications()) + if (!Win32Api.SetAppModelID(AUMID)) { - // limit types of notifications on template builder + // log error, return } - // var provider = WindowsNotificationProvider.try_create(app); - // if (provider != null) { - // app.stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(provider); - // } + if (!ShortcutCreator.TryCreateShortcut(AUMID)) + { + // log error, return + } + + var notification = new ToastNotification.ToastNotification(); + int test = 2; + notification.Activated = new Callbacks.SimpleNotificationCallback() + { + callback = () => { + test = 3; + } + }; + + notification.ActivatedWithIndex = new Callbacks.ActivatedWithActionIndexNotificationCallback() + { + callback = (index) => { + test = index; + } + }; + + notification.Dismissed = new Callbacks.DismissedNotificationCallback() + { + callback = (reason) => { + var m = reason; + } + }; + + notification.Failed = new Callbacks.SimpleNotificationCallback() + { + callback = () => { + var m = 2; + } + }; + + // var provider = new WindowsNotificationProvider(app, Win32Api.SupportsModernNotifications()); + // app.stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(provider); } public void shutdown() { diff --git a/plugins/windows-notification/vapi/callbacks.vapi b/plugins/windows-notification/vapi/callbacks.vapi new file mode 100644 index 00000000..0e3baea5 --- /dev/null +++ b/plugins/windows-notification/vapi/callbacks.vapi @@ -0,0 +1,43 @@ +using Dino.Plugins.WindowsNotification.Vapi.Enums; + +[CCode (cheader_filename = "callbacks.h")] +namespace Dino.Plugins.WindowsNotification.Vapi.Callbacks { + [CCode (cname = "Notification_Callback_Simple", has_target = true)] + public delegate void NotificationCallbackSimple(); + + [CCode (cname = "Notification_Callback_ActivatedWithActionIndex", has_target = true)] + public delegate void NotificationCallbackWithActionIndex(int actionId); + + [CCode (cname = "Notification_Callback_Dismissed", has_target = true)] + public delegate void NotificationCallbackDismissed(DismissedReason reason); + + [CCode (cname = "SimpleNotificationCallback", free_function = "DestroySimpleNotificationCallback")] + [Compact] + public class SimpleNotificationCallback { + [CCode (cname = "NewSimpleNotificationCallback")] + public SimpleNotificationCallback(); + + [CCode (delegate_target_cname = "context", destroy_notify_cname = "free")] + public NotificationCallbackSimple callback; + } + + [CCode (cname = "ActivatedWithActionIndexNotificationCallback", free_function = "DestroyActivatedWithActionIndexNotificationCallback")] + [Compact] + public class ActivatedWithActionIndexNotificationCallback { + [CCode (cname = "NewActivatedWithActionIndexNotificationCallback")] + public ActivatedWithActionIndexNotificationCallback(); + + [CCode (delegate_target_cname = "context", destroy_notify_cname = "free")] + public NotificationCallbackWithActionIndex callback; + } + + [CCode (cname = "DismissedNotificationCallback", free_function = "DestroyDismissedNotificationCallback")] + [Compact] + public class DismissedNotificationCallback { + [CCode (cname = "NewDismissedNotificationCallback")] + public DismissedNotificationCallback(); + + [CCode (delegate_target_cname = "context", destroy_notify_cname = "free")] + public NotificationCallbackDismissed callback; + } +} \ No newline at end of file diff --git a/plugins/windows-notification/vapi/enums.vapi b/plugins/windows-notification/vapi/enums.vapi new file mode 100644 index 00000000..ae2baee5 --- /dev/null +++ b/plugins/windows-notification/vapi/enums.vapi @@ -0,0 +1,9 @@ +[CCode (cheader_filename = "enums.h")] +namespace Dino.Plugins.WindowsNotification.Vapi.Enums { + [CCode (cname = "Dismissed_Reason", cprefix = "Dismissed_Reason_")] + public enum DismissedReason { + Activated, + ApplicationHidden, + TimedOut + } +} \ No newline at end of file diff --git a/plugins/windows-notification/vapi/shortcutcreator.vapi b/plugins/windows-notification/vapi/shortcutcreator.vapi index 110f7eaa..6bffe133 100644 --- a/plugins/windows-notification/vapi/shortcutcreator.vapi +++ b/plugins/windows-notification/vapi/shortcutcreator.vapi @@ -1,5 +1,5 @@ [CCode (cheader_filename = "shortcutcreator.h")] -namespace ShortcutCreator { +namespace Dino.Plugins.WindowsNotification.Vapi.ShortcutCreator { [CCode (cname = "TryCreateShortcut")] public bool TryCreateShortcut(string aumid); } \ No newline at end of file diff --git a/plugins/windows-notification/vapi/toastnotification.vapi b/plugins/windows-notification/vapi/toastnotification.vapi new file mode 100644 index 00000000..66dfe051 --- /dev/null +++ b/plugins/windows-notification/vapi/toastnotification.vapi @@ -0,0 +1,36 @@ +using Dino.Plugins.WindowsNotification.Vapi.Callbacks; + +[CCode (cheader_filename = "toastnotification.h")] +namespace Dino.Plugins.WindowsNotification.Vapi.ToastNotification { + [CCode (cname = "DinoToastNotification_t", copy_function = "CopyNotification", free_function = "DestroyNotification")] + [Compact] + public class ToastNotification { + [CCode (cname = "NewNotification")] + public ToastNotification(); + + public SimpleNotificationCallback Activated + { + [CCode (cname = "set_Activated")] + set; + } + + public ActivatedWithActionIndexNotificationCallback ActivatedWithIndex + { + [CCode (cname = "set_ActivatedWithIndex")] + set; + } + + public DismissedNotificationCallback Dismissed + { + [CCode (cname = "set_Dismissed")] + set; + } + + public SimpleNotificationCallback Failed + { + [CCode (cname = "set_Failed")] + set; + } + } +} + diff --git a/plugins/windows-notification/vapi/win32.vapi b/plugins/windows-notification/vapi/win32.vapi index 27f7e65c..7bfcc2fc 100644 --- a/plugins/windows-notification/vapi/win32.vapi +++ b/plugins/windows-notification/vapi/win32.vapi @@ -1,6 +1,9 @@ [CCode (cheader_filename = "win32.h")] -namespace Win32Api { +namespace Dino.Plugins.WindowsNotification.Vapi.Win32Api { [CCode (cname = "SupportsModernNotifications")] public bool SupportsModernNotifications(); + + [CCode (cname = "SetAppModelID")] + public bool SetAppModelID(string aumid); } diff --git a/plugins/windows-notification/vapi/winrt.vapi b/plugins/windows-notification/vapi/winrt.vapi index c32acb43..50642013 100644 --- a/plugins/windows-notification/vapi/winrt.vapi +++ b/plugins/windows-notification/vapi/winrt.vapi @@ -1,5 +1,5 @@ [CCode (cheader_filename = "winrt.h")] -namespace WinRTApi { +namespace Dino.Plugins.WindowsNotification.Vapi.WinRTApi { [CCode (cname = "Initialize")] public bool Initialize(); } \ No newline at end of file