diff --git a/plugins/windows-notification/api/include/gobject/winrt-glib.h b/plugins/windows-notification/api/include/gobject/winrt-glib.h index 24f76c32..e520cca1 100644 --- a/plugins/windows-notification/api/include/gobject/winrt-glib.h +++ b/plugins/windows-notification/api/include/gobject/winrt-glib.h @@ -11,6 +11,7 @@ #include "winrt.h" #include "winrt-toast-notification.h" #include "winrt-event-token.h" +#include "winrt-toast-notifier.h" #undef WINRT_GLIB_H_INSIDE diff --git a/plugins/windows-notification/api/include/gobject/winrt-toast-notification.h b/plugins/windows-notification/api/include/gobject/winrt-toast-notification.h index 18874eda..373c0eab 100644 --- a/plugins/windows-notification/api/include/gobject/winrt-toast-notification.h +++ b/plugins/windows-notification/api/include/gobject/winrt-toast-notification.h @@ -27,7 +27,7 @@ extern "C" typedef void(*NotificationCallbackSimple)(void* userdata); typedef void(*NotificationCallbackActivated)(const gchar* arguments, gchar** userInput, gint count, void* userdata); -//typedef void(*Notification_Callback_Dismissed)(Dismissed_Reason reason, void* userdata); +//typedef void(*NotificationCallbackDismissed)(WinrtDismissedReason reason, void* userdata); winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const gchar* doc); @@ -44,7 +44,7 @@ winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(win void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token); winrtEventToken* winrt_windows_ui_notifications_toast_notification_Failed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackSimple callback, void* context, void(*free)(void*)); -//winrtEventToken* winrt_windows_ui_notifications_toast_notification_Dismissed(winrtWindowsUINotificationsToastNotification* self, Notification_Callback_Dismissed callback, void* context, void(*free)(void*)); +//winrtEventToken* winrt_windows_ui_notifications_toast_notification_Dismissed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackDismissed callback, void* context, void(*free)(void*)); #ifdef __cplusplus } diff --git a/plugins/windows-notification/api/include/gobject/winrt-toast-notifier-private.h b/plugins/windows-notification/api/include/gobject/winrt-toast-notifier-private.h new file mode 100644 index 00000000..fb695445 --- /dev/null +++ b/plugins/windows-notification/api/include/gobject/winrt-toast-notifier-private.h @@ -0,0 +1,12 @@ +#ifndef __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_PRIVATE_H__ +#define __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_PRIVATE_H__ + +#include +#include "winrt-headers.h" + +#include "winrt-toast-notifier.h" + +winrt::Windows::UI::Notifications::ToastNotifier* winrt_windows_ui_notifications_toast_notifier_get_internal(winrtWindowsUINotificationsToastNotifier* self); +void winrt_windows_ui_notifications_toast_notifier_set_internal(winrtWindowsUINotificationsToastNotifier *self, winrt::Windows::UI::Notifications::ToastNotifier notification); + +#endif /* __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_PRIVATE_H__ */ diff --git a/plugins/windows-notification/api/include/gobject/winrt-toast-notifier.h b/plugins/windows-notification/api/include/gobject/winrt-toast-notifier.h new file mode 100644 index 00000000..3473c886 --- /dev/null +++ b/plugins/windows-notification/api/include/gobject/winrt-toast-notifier.h @@ -0,0 +1,39 @@ +#ifndef __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_H__ +#define __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_H__ + +#if !defined(WINRT_GLIB_H_INSIDE) && !defined(WINRT_GLIB_COMPILATION) +#error "Only can be included directly." +#endif + +#include "winrt-glib-types.h" +#include "winrt-toast-notification.h" + +G_BEGIN_DECLS + +#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER (winrt_windows_ui_notifications_toast_notifier_get_type()) + +G_DECLARE_DERIVABLE_TYPE (winrtWindowsUINotificationsToastNotifier, winrt_windows_ui_notifications_toast_notifier, WINRT, WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER, GObject) + +struct _winrtWindowsUINotificationsToastNotifierClass +{ + /*< private >*/ + GObjectClass parent_class; +}; + +#ifdef __cplusplus +extern "C" +{ +#endif + +winrtWindowsUINotificationsToastNotifier* winrt_windows_ui_notifications_toast_notifier_new(const gchar* aumid); + +void winrt_windows_ui_notifications_toast_notifier_Show(winrtWindowsUINotificationsToastNotifier* self, winrtWindowsUINotificationsToastNotification* toast_notification); +void winrt_windows_ui_notifications_toast_notifier_Hide(winrtWindowsUINotificationsToastNotifier* self, winrtWindowsUINotificationsToastNotification* toast_notification); + +#ifdef __cplusplus +} +#endif + +G_END_DECLS + +#endif /* __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER_H__ */ diff --git a/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp b/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp index c1623d7c..0b077112 100644 --- a/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp +++ b/plugins/windows-notification/api/src/gobject/winrt-toast-notification.cpp @@ -1,15 +1,3 @@ -/** - * SECTION:winrt-toast-notification-manager - * @Title: winrtWindowsUINotificationsToastNotification - * @short_description: A read-only database - * - * #winrtWindowsUINotificationsToastNotification is a class that allows read-only access to a - * Xapian database at a given path. - * - * Typically, you will use #winrtWindowsUINotificationsToastNotification to open a database for - * querying, by using the #XapianEnquire class. - */ - #include #include #include @@ -51,10 +39,6 @@ typedef struct Callback failed; - // Notification_Callback_ActivatedWithActionIndex callback; - // void* context; - // void(*free)(void*); - // Notification_Callback_Dismissed callback; // void* context; // void(*free)(void*); diff --git a/plugins/windows-notification/api/src/gobject/winrt-toast-notifier.cpp b/plugins/windows-notification/api/src/gobject/winrt-toast-notifier.cpp new file mode 100644 index 00000000..35bb2e6d --- /dev/null +++ b/plugins/windows-notification/api/src/gobject/winrt-toast-notifier.cpp @@ -0,0 +1,108 @@ +#include +#include +#include + +#include "winrt-toast-notifier-private.h" +#include "winrt-toast-notification-private.h" +#include "converter.hpp" + +#define WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFIER_GET_PRIVATE(obj) \ + ((winrtWindowsUINotificationsToastNotifierPrivate*) winrt_windows_ui_notifications_toast_notifier_get_instance_private ((winrtWindowsUINotificationsToastNotifier*) (obj))) + +typedef struct +{ + winrt::Windows::UI::Notifications::ToastNotifier data; +} _winrtWindowsUINotificationsToastNotifierPrivate; + +typedef struct +{ + _winrtWindowsUINotificationsToastNotifierPrivate* notifier; +} winrtWindowsUINotificationsToastNotifierPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (winrtWindowsUINotificationsToastNotifier, winrt_windows_ui_notifications_toast_notifier, G_TYPE_OBJECT) + +static void winrt_windows_ui_notifications_toast_notifier_finalize(GObject* self) +{ + winrtWindowsUINotificationsToastNotifierPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFIER_GET_PRIVATE (self); + + delete priv->notifier; + + G_OBJECT_CLASS(winrt_windows_ui_notifications_toast_notifier_parent_class)->dispose(self); +} + +static void winrt_windows_ui_notifications_toast_notifier_class_init (winrtWindowsUINotificationsToastNotifierClass* klass) +{ + GObjectClass* gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->finalize = winrt_windows_ui_notifications_toast_notifier_finalize; +} + +static void winrt_windows_ui_notifications_toast_notifier_init (winrtWindowsUINotificationsToastNotifier *self) +{ +} + +/*< private > + * winrt_windows_ui_notifications_toast_notifier_get_internal: + * @self: a #winrtWindowsUINotificationsToastNotifier + * + * Retrieves the `winrt::Windows::UI::Notifications::ToastNotifier` object used by @self. + * + * Returns: (transfer none): a pointer to the internal toast notification instance + */ +winrt::Windows::UI::Notifications::ToastNotifier* winrt_windows_ui_notifications_toast_notifier_get_internal(winrtWindowsUINotificationsToastNotifier *self) +{ + winrtWindowsUINotificationsToastNotifierPrivate *priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFIER_GET_PRIVATE (self); + + return &priv->notifier->data; +} + +/*< private > + * winrt_windows_ui_notifications_toast_notifier_set_internal: + * @self: a #winrtWindowsUINotificationsToastNotifier + * @notification: a `winrt::Windows::UI::Notifications::ToastNotifier` instance + * + * Sets the internal database instance wrapped by @self, clearing + * any existing instance if needed. + */ +void winrt_windows_ui_notifications_toast_notifier_set_internal(winrtWindowsUINotificationsToastNotifier* self, winrt::Windows::UI::Notifications::ToastNotifier notifier) +{ + winrtWindowsUINotificationsToastNotifierPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFIER_GET_PRIVATE(self); + + delete priv->notifier; + + priv->notifier = new _winrtWindowsUINotificationsToastNotifierPrivate { notifier }; +} + +/** + * winrt_windows_ui_notifications_toast_notifier_new: + * @doc: the document to be shown + * + * Creates a new toast notifier instance with its aumid set + * + * Returns: (transfer full): the newly created #winrtWindowsUINotificationsToastNotifier instance + */ +winrtWindowsUINotificationsToastNotifier* winrt_windows_ui_notifications_toast_notifier_new(const gchar* aumid) +{ + g_return_val_if_fail (aumid == NULL, NULL); + + auto ret = static_cast(g_object_new (WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION, NULL)); + auto notifier = winrt::Windows::UI::Notifications::ToastNotificationManager::CreateToastNotifier(sview_to_wstr(aumid)); + winrt_windows_ui_notifications_toast_notifier_set_internal(ret, notifier); + return ret; +} + +void winrt_windows_ui_notifications_toast_notifier_Show(winrtWindowsUINotificationsToastNotifier* self, winrtWindowsUINotificationsToastNotification* toast_notification) +{ + g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER (self)); + g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (toast_notification)); + + winrt_windows_ui_notifications_toast_notifier_get_internal(self)->Show(*winrt_windows_ui_notifications_toast_notification_get_internal(toast_notification)); +} + +void winrt_windows_ui_notifications_toast_notifier_Hide(winrtWindowsUINotificationsToastNotifier* self, winrtWindowsUINotificationsToastNotification* toast_notification) +{ + g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFIER (self)); + g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (toast_notification)); + + return winrt_windows_ui_notifications_toast_notifier_get_internal(self)->Hide(*winrt_windows_ui_notifications_toast_notification_get_internal(toast_notification)); +} \ No newline at end of file diff --git a/plugins/windows-notification/api/src/unity.cpp b/plugins/windows-notification/api/src/unity.cpp index d996ab8d..df48867d 100644 --- a/plugins/windows-notification/api/src/unity.cpp +++ b/plugins/windows-notification/api/src/unity.cpp @@ -1,4 +1,5 @@ #include "./gobject/winrt.cpp" +#include "./gobject/winrt-toast-notifier.cpp" #include "./gobject/winrt-toast-notification.cpp" #include "./gobject/winrt-event-token.cpp" #include "./gobject/winrt-enums.cpp" \ No newline at end of file diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala index 3ba8049f..31207e1d 100644 --- a/plugins/windows-notification/src/plugin.vala +++ b/plugins/windows-notification/src/plugin.vala @@ -26,13 +26,13 @@ public class Plugin : RootInterface, Object { } { + var notifier = new winrt.Windows.UI.Notifications.ToastNotifier(AUMID); var m = new winrt.Windows.UI.Notifications.ToastNotification("Test"); var token = m.Activated((c, d) => { var i = 2; }); m.RemoveActivatedAction(token); - var h = m.ExpiresOnReboot; m.ExpiresOnReboot = false; @@ -41,6 +41,8 @@ public class Plugin : RootInterface, Object { a = m.Group; m.Group = "a"; + + notifier.Show(m); } // var provider = new WindowsNotificationProvider(app, Win32Api.SupportsModernNotifications()); diff --git a/plugins/windows-notification/vapi/winrt_windows_ui_notifications.vapi b/plugins/windows-notification/vapi/winrt_windows_ui_notifications.vapi index 42eb1cb6..c3bdc251 100644 --- a/plugins/windows-notification/vapi/winrt_windows_ui_notifications.vapi +++ b/plugins/windows-notification/vapi/winrt_windows_ui_notifications.vapi @@ -18,4 +18,11 @@ namespace winrt.Windows.UI.Notifications { public winrt.EventToken Activated(owned NotificationCallbackActivated handler); public void RemoveActivatedAction(winrt.EventToken token); } + + [CCode (type_id = "winrt_windows_ui_notifications_toast_notifier_get_type ()")] + public class ToastNotifier : GLib.Object { + public ToastNotifier(string aumid); + public void Show(ToastNotification notification); + public void Hide(ToastNotification notification); + } } \ No newline at end of file