Add toastnotifier

This commit is contained in:
LAGonauta 2021-02-22 07:41:39 -03:00
parent 8df226ec29
commit 1d1b00222f
9 changed files with 173 additions and 19 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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 <glib.h>
#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__ */

View file

@ -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 <winrt-glib.h> 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__ */

View file

@ -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 <iostream>
#include <string>
#include <string_view>
@ -51,10 +39,6 @@ typedef struct
Callback<NotificationCallbackSimple> failed;
// Notification_Callback_ActivatedWithActionIndex callback;
// void* context;
// void(*free)(void*);
// Notification_Callback_Dismissed callback;
// void* context;
// void(*free)(void*);

View file

@ -0,0 +1,108 @@
#include <iostream>
#include <string>
#include <string_view>
#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<winrtWindowsUINotificationsToastNotifier*>(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));
}

View file

@ -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"

View file

@ -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());

View file

@ -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);
}
}