Add failed and dimissed actions
This commit is contained in:
parent
6cdaad315a
commit
898470ed23
|
@ -5,25 +5,25 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define WINRT_TYPE_DISMISSED_REASON (winrt_dismissed_reason_get_type ())
|
||||
#define WINRT_TYPE_DISMISSED_REASON (winrt_windows_ui_notifications_toast_dismissal_reason_get_type ())
|
||||
|
||||
/**
|
||||
* WinrtDismissedReason:
|
||||
* @WINRT_DISMISSED_REASON_ACTIVATED: Notification was activated, clicked or through
|
||||
* @WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_ACTIVATED: Notification was activated, clicked or through
|
||||
* a button
|
||||
* @WINRT_DISMISSED_REASON_APPLICATION_HIDDEN: Application was hidden
|
||||
* @WINRT_DISMISSED_REASON_TIMED_OUT: Notification timed out
|
||||
* @WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_APPLICATION_HIDDEN: Application was hidden
|
||||
* @WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TIMED_OUT: Notification timed out
|
||||
*
|
||||
* Reasons for a notification dismissal
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
WINRT_DISMISSED_REASON_ACTIVATED,
|
||||
WINRT_DISMISSED_REASON_APPLICATION_HIDDEN,
|
||||
WINRT_DISMISSED_REASON_TIMED_OUT,
|
||||
} WinrtDismissedReason;
|
||||
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_ACTIVATED,
|
||||
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_APPLICATION_HIDDEN,
|
||||
WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TIMED_OUT,
|
||||
} winrt_Windows_UI_Notifications_Toast_Dismissal_Reason;
|
||||
|
||||
GType winrt_dismissed_reason_get_type (void);
|
||||
GType winrt_windows_ui_notifications_toast_dismissal_reason_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
typedef void(*NotificationCallbackSimple)(void* userdata);
|
||||
typedef void(*NotificationCallbackFailed)(void* userdata);
|
||||
typedef void(*NotificationCallbackActivated)(const gchar* arguments, gchar** userInput, gint count, void* userdata);
|
||||
//typedef void(*NotificationCallbackDismissed)(WinrtDismissedReason reason, void* userdata);
|
||||
typedef void(*NotificationCallbackDismissed)(winrt_Windows_UI_Notifications_Toast_Dismissal_Reason reason, void* userdata);
|
||||
|
||||
winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const gchar* doc);
|
||||
|
||||
|
@ -43,8 +43,11 @@ gchar* winrt_windows_ui_notifications_toast_notification_get_Group(winrtWindowsU
|
|||
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackActivated callback, void* context, void(*free)(void*));
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveActivated(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, NotificationCallbackDismissed callback, void* context, void(*free)(void*));
|
||||
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Failed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackFailed callback, void* context, void(*free)(void*));
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveFailed(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token);
|
||||
|
||||
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Dismissed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackDismissed callback, void* context, void(*free)(void*));
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveDismissed(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ type_name ## _get_type (void) \
|
|||
return g_define_id__volatile; \
|
||||
}
|
||||
|
||||
WINRT_GLIB_DEFINE_ENUM_TYPE (WinrtDismissedReason, winrt_dismissed_reason,
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_DISMISSED_REASON_ACTIVATED, "activated")
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_DISMISSED_REASON_APPLICATION_HIDDEN, "application-hidden")
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_DISMISSED_REASON_TIMED_OUT, "timed-out"))
|
||||
WINRT_GLIB_DEFINE_ENUM_TYPE (winrt_Windows_UI_Notifications_Toast_Dismissal_Reason, winrt_windows_ui_notifications_toast_dismissal_reason,
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_ACTIVATED, "activated")
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_APPLICATION_HIDDEN, "application-hidden")
|
||||
WINRT_GLIB_DEFINE_ENUM_VALUE (WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_TIMED_OUT, "timed-out"))
|
||||
|
|
|
@ -60,8 +60,8 @@ struct _winrtWindowsUINotificationsToastNotificationPrivate
|
|||
winrt::Windows::UI::Notifications::ToastNotification data;
|
||||
|
||||
std::list<std::shared_ptr<Callback<NotificationCallbackActivated>>> activated;
|
||||
std::list<std::shared_ptr<Callback<NotificationCallbackSimple>>> failed;
|
||||
std::list<std::shared_ptr<Callback<NotificationCallbackSimple>>> dismissed;
|
||||
std::list<std::shared_ptr<Callback<NotificationCallbackFailed>>> failed;
|
||||
std::list<std::shared_ptr<Callback<NotificationCallbackDismissed>>> dismissed;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
|
@ -251,7 +251,6 @@ winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(win
|
|||
}
|
||||
}
|
||||
|
||||
std::cout << "Notification activated!" << std::endl;
|
||||
callback(wsview_to_char(arguments), nullptr /* user_input */ , 0 /* user_input.size() */, context);
|
||||
});
|
||||
auto new_token = winrt_event_token_new_from_token(&token);
|
||||
|
@ -261,6 +260,46 @@ winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(win
|
|||
return new_token;
|
||||
}
|
||||
|
||||
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Failed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackFailed callback, void* context, void(*free)(void*))
|
||||
{
|
||||
g_return_val_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self), NULL);
|
||||
g_return_val_if_fail (callback != nullptr && context != nullptr && free != nullptr, NULL);
|
||||
|
||||
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||
|
||||
auto token = priv->notification->data.Failed([=](auto sender, auto toastFailedEventArgs)
|
||||
{
|
||||
callback(context);
|
||||
});
|
||||
|
||||
auto new_token = winrt_event_token_new_from_token(&token);
|
||||
g_object_ref(new_token);
|
||||
|
||||
priv->notification->failed.push_back(std::make_shared<Callback<NotificationCallbackFailed>>(callback, context, free, new_token));
|
||||
return new_token;
|
||||
}
|
||||
|
||||
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Dismissed(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackDismissed callback, void* context, void(*free)(void*))
|
||||
{
|
||||
g_return_val_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self), NULL);
|
||||
g_return_val_if_fail (callback != nullptr && context != nullptr && free != nullptr, NULL);
|
||||
|
||||
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||
|
||||
auto token = priv->notification->data.Dismissed([=](auto sender, winrt::Windows::UI::Notifications::ToastDismissedEventArgs dismissed)
|
||||
{
|
||||
auto reason = dismissed.Reason();
|
||||
callback(static_cast<winrt_Windows_UI_Notifications_Toast_Dismissal_Reason>(reason), context);
|
||||
});
|
||||
|
||||
auto new_token = winrt_event_token_new_from_token(&token);
|
||||
g_object_ref(new_token);
|
||||
|
||||
priv->notification->dismissed.push_back(std::make_shared<Callback<NotificationCallbackDismissed>>(callback, context, free, new_token));
|
||||
return new_token;
|
||||
}
|
||||
|
||||
// TODO: refactor `Remove{Activated,Failed,Dismissed}` methods into one to deduplicate code
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveActivated(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token)
|
||||
{
|
||||
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
|
||||
|
@ -279,4 +318,44 @@ void winrt_windows_ui_notifications_toast_notification_RemoveActivated(winrtWind
|
|||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveFailed(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token)
|
||||
{
|
||||
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
|
||||
|
||||
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||
|
||||
priv->notification->failed.remove_if([&](const auto& callback) {
|
||||
if (winrt_event_token_get_value(token) == winrt_event_token_get_value(callback->token))
|
||||
{
|
||||
if (winrt_event_token_operator_bool(callback->token))
|
||||
{
|
||||
priv->notification->data.Failed(*winrt_event_token_get_internal(callback->token));
|
||||
}
|
||||
g_object_unref(callback->token);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void winrt_windows_ui_notifications_toast_notification_RemoveDismissed(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token)
|
||||
{
|
||||
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
|
||||
|
||||
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||
|
||||
priv->notification->dismissed.remove_if([&](const auto& callback) {
|
||||
if (winrt_event_token_get_value(token) == winrt_event_token_get_value(callback->token))
|
||||
{
|
||||
if (winrt_event_token_operator_bool(callback->token))
|
||||
{
|
||||
priv->notification->data.Dismissed(*winrt_event_token_get_internal(callback->token));
|
||||
}
|
||||
g_object_unref(callback->token);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
|
@ -2,14 +2,23 @@ using winrt;
|
|||
|
||||
[CCode (cheader_filename = "gobject/winrt-glib.h")]
|
||||
namespace winrt.Windows.UI.Notifications {
|
||||
[CCode (cname = "NotificationCallbackSimple", has_target = true)]
|
||||
public delegate void NotificationCallbackSimple();
|
||||
|
||||
[CCode (cname = "winrt_Windows_UI_Notifications_Toast_Dismissal_Reason", cprefix = "WINRT_WINDOWS_UI_NOTIFICATIONS_TOAST_DISMISSAL_REASON_", type_id = "winrt_windows_ui_notifications_toast_dismissal_reason_get_type ()")]
|
||||
public enum ToastDismissalReason
|
||||
{
|
||||
Activated,
|
||||
ApplicationHidden,
|
||||
TimedOut
|
||||
}
|
||||
|
||||
[CCode (cname = "NotificationCallbackFailed", has_target = true)]
|
||||
public delegate void NotificationCallbackFailed();
|
||||
|
||||
[CCode (cname = "NotificationCallbackActivated", has_target = true)]
|
||||
public delegate void NotificationCallbackActivated(string? arguments, string[]? userInput);
|
||||
|
||||
// [CCode (cname = "Notification_Callback_Dismissed", has_target = true)]
|
||||
// public delegate void NotificationCallbackDismissed(DismissedReason reason);
|
||||
[CCode (cname = "NotificationCallbackDismissed", has_target = true)]
|
||||
public delegate void NotificationCallbackDismissed(ToastDismissalReason reason);
|
||||
|
||||
[CCode (type_id = "winrt_windows_ui_notifications_toast_notification_get_type ()")]
|
||||
public class ToastNotification : GLib.Object {
|
||||
|
@ -17,8 +26,15 @@ namespace winrt.Windows.UI.Notifications {
|
|||
public bool ExpiresOnReboot { get; set; }
|
||||
public string Tag { get; set; } // TODO: check if valac is cleaning this string
|
||||
public string Group { get; set; }
|
||||
|
||||
public EventToken Activated(owned NotificationCallbackActivated handler);
|
||||
public void RemoveActivated(EventToken token);
|
||||
|
||||
public EventToken Failed(owned NotificationCallbackFailed handler);
|
||||
public void RemoveFailed(EventToken token);
|
||||
|
||||
public EventToken Dismissed(owned NotificationCallbackDismissed handler);
|
||||
public void RemoveDismissed(EventToken token);
|
||||
}
|
||||
|
||||
[CCode (type_id = "winrt_windows_ui_notifications_toast_notifier_get_type ()")]
|
||||
|
|
Loading…
Reference in a new issue