Initial GObject wrapper for WinRT notifications

Still missing a lot of stuff
This commit is contained in:
LAGonauta 2021-02-21 17:03:24 -03:00
parent ce0deed0dc
commit ae9671716f
28 changed files with 609 additions and 406 deletions

View file

@ -20,20 +20,20 @@ CUSTOM_VAPIS
${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
${CMAKE_CURRENT_SOURCE_DIR}/vapi/winrt_windows_ui_notifications.vapi
PACKAGES
${WINDOWS_NOTIFICATION_PACKAGES}
)
set(WINDOWS_API_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/api/src/gobject/winrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/api/src/gobject/winrt-enums.cpp
${CMAKE_CURRENT_SOURCE_DIR}/api/src/gobject/winrt-event-token.cpp
${CMAKE_CURRENT_SOURCE_DIR}/api/src/gobject/winrt-toast-notification.cpp
${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})
@ -41,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}/api/include/gobject
${PROJECT_SOURCE_DIR}/yolort/include
)
@ -66,7 +67,8 @@ 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 ${PROJECT_SOURCE_DIR}/yolort/include/winrt/yolort_impl)
target_compile_definitions(windows-notification PRIVATE WINRT_GLIB_H_INSIDE)
target_compile_options(windows-notification PRIVATE -municode $<$<COMPILE_LANGUAGE:CXX>:-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/)

View file

@ -1,48 +0,0 @@
#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

View file

@ -1,16 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum {
Dismissed_Reason_Activated = 0,
Dismissed_Reason_ApplicationHidden,
Dismissed_Reason_TimedOut
} Dismissed_Reason;
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,30 @@
#ifndef __WINRT_ENUMS_H__
#define __WINRT_ENUMS_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define WINRT_TYPE_DISMISSED_REASON (winrt_dismissed_reason_get_type ())
/**
* WinrtDismissedReason:
* @WINRT_DISMISSED_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
*
* Reasons for a notification dismissal
*
*/
typedef enum {
WINRT_DISMISSED_REASON_ACTIVATED,
WINRT_DISMISSED_REASON_APPLICATION_HIDDEN,
WINRT_DISMISSED_REASON_TIMED_OUT,
} WinrtDismissedReason;
GType winrt_dismissed_reason_get_type (void);
G_END_DECLS
#endif /* __WINRT_ENUMS_H__ */

View file

@ -0,0 +1,12 @@
#ifndef __WINRT_GLIB_EVENTTOKEN_PRIVATE_H__
#define __WINRT_GLIB_EVENTTOKEN_PRIVATE_H__
#include <glib.h>
#include "winrt-headers.h"
#include "winrt-event-token.h"
winrtEventToken* winrt_event_token_new_from_token(winrt::event_token* token);
winrt::event_token* winrt_event_token_get_internal(winrtEventToken* self);
#endif /* __WINRT_GLIB_EVENTTOKEN_PRIVATE_H__ */

View file

@ -0,0 +1,36 @@
#ifndef __WINRT_GLIB_EVENTTOKEN_H__
#define __WINRT_GLIB_EVENTTOKEN_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"
G_BEGIN_DECLS
#define WINRT_TYPE_EVENT_TOKEN (winrt_event_token_get_type())
G_DECLARE_DERIVABLE_TYPE (winrtEventToken, winrt_event_token, WINRT, EVENT_TOKEN, GObject)
struct _winrtEventTokenClass
{
/*< private >*/
GObjectClass parent_class;
};
#ifdef __cplusplus
extern "C"
{
#endif
gint64 winrt_event_token_get_value(winrtEventToken* self);
gboolean winrt_event_token_operator_bool(winrtEventToken* self);
#ifdef __cplusplus
}
#endif
G_END_DECLS
#endif /* __WINRT_GLIB_EVENTTOKEN_H__ */

View file

@ -0,0 +1,7 @@
#ifndef __WINRT_GLIB_TYPES_H__
#define __WINRT_GLIB_TYPES_H__
#include <gio/gio.h>
#include "winrt-enums.h"
#endif /* __WINRT_GLIB_TYPES_H__ */

View file

@ -0,0 +1,17 @@
#ifndef __WINRT_GLIB_H__
#define __WINRT_GLIB_H__
#ifndef WINRT_GLIB_H_INSIDE
#define WINRT_GLIB_H_INSIDE
#endif
#include "winrt-enums.h"
#include "winrt-glib-types.h"
#include "winrt.h"
#include "winrt-toast-notification.h"
#include "winrt-event-token.h"
#undef WINRT_GLIB_H_INSIDE
#endif /* __`WINRT_GLIB_H__ */

View file

@ -0,0 +1,8 @@
#ifndef __WINRT_HEADERS_H__
#define __WINRT_HEADERS_H__
#include <winrt/Windows.UI.Notifications.h>
#include <winrt/Windows.Data.Xml.Dom.h>
#include <winrt/Windows.Foundation.h>
#endif /* __WINRT_HEADERS_H__ */

View file

@ -0,0 +1,8 @@
#ifndef __WINRT_GLIB_H_PRIVATE__
#define __WINRT_GLIB_H_PRIVATE__
#include <glib.h>
#include "winrt.h"
//#include "gobject/winrt-headers.h"
#endif // __WINRT_GLIB_H_PRIVATE__

View file

@ -0,0 +1,12 @@
#ifndef __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_PRIVATE_H__
#define __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_PRIVATE_H__
#include <glib.h>
#include "winrt-headers.h"
#include "winrt-toast-notification.h"
winrt::Windows::UI::Notifications::ToastNotification* winrt_windows_ui_notifications_toast_notification_get_internal(winrtWindowsUINotificationsToastNotification* self);
void winrt_windows_ui_notifications_toast_notification_set_internal(winrtWindowsUINotificationsToastNotification *self, winrt::Windows::UI::Notifications::ToastNotification notification);
#endif /* __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_PRIVATE_H__ */

View file

@ -0,0 +1,55 @@
#ifndef __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_H__
#define __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_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-event-token.h"
G_BEGIN_DECLS
#define WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (winrt_windows_ui_notifications_toast_notification_get_type())
G_DECLARE_DERIVABLE_TYPE (winrtWindowsUINotificationsToastNotification, winrt_windows_ui_notifications_toast_notification, WINRT, WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION, GObject)
struct _winrtWindowsUINotificationsToastNotificationClass
{
/*< private >*/
GObjectClass parent_class;
};
#ifdef __cplusplus
extern "C"
{
#endif
typedef void(*Notification_Callback_Simple)(void* userdata);
typedef void(*Notification_Callback_ActivatedWithActionIndex)(int action_id, void* userdata);
//typedef void(*Notification_Callback_Dismissed)(Dismissed_Reason reason, void* userdata);
winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const char* doc);
void winrt_windows_ui_notifications_toast_notification_set_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self, gboolean value);
gboolean winrt_windows_ui_notifications_toast_notification_get_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self);
void winrt_windows_ui_notifications_toast_notification_set_Tag(winrtWindowsUINotificationsToastNotification* self, const char* value);
char* winrt_windows_ui_notifications_toast_notification_get_Tag(winrtWindowsUINotificationsToastNotification* self);
void winrt_windows_ui_notifications_toast_notification_set_Group(winrtWindowsUINotificationsToastNotification* self, const char* value);
char* winrt_windows_ui_notifications_toast_notification_get_Group(winrtWindowsUINotificationsToastNotification* self);
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(winrtWindowsUINotificationsToastNotification* self, Notification_Callback_Simple callback, void* context, void(*free)(void*));
void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token);
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Failed(winrtWindowsUINotificationsToastNotification* self, Notification_Callback_Simple 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*));
#ifdef __cplusplus
}
#endif
G_END_DECLS
#endif /* __WINRT_GLIB_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION_H__ */

View file

@ -0,0 +1,15 @@
#ifndef __WINRT_GLIB_H__
#define __WINRT_GLIB_H__
#ifdef __cplusplus
extern "C"
{
#endif
gboolean winrt_InitApartment();
#ifdef __cplusplus
}
#endif
#endif // __WINRT_GLIB_H__

View file

@ -1,52 +0,0 @@
#pragma once
#include <glib.h>
#include "callbacks.h"
#ifdef __cplusplus
#include <memory>
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>* 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

View file

@ -1,14 +0,0 @@
#pragma once
#include <glib.h>
#ifdef __cplusplus
extern "C"
{
#endif
gboolean Initialize();
#ifdef __cplusplus
}
#endif

View file

@ -1,37 +0,0 @@
#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;
}
}

View file

@ -0,0 +1,26 @@
#include "winrt-enums.h"
#define WINRT_GLIB_DEFINE_ENUM_VALUE(value,nick) \
{ value, #value, nick },
#define WINRT_GLIB_DEFINE_ENUM_TYPE(TypeName,type_name,values) \
GType \
type_name ## _get_type (void) \
{ \
static volatile gsize g_define_id__volatile = 0; \
if (g_once_init_enter (&g_define_id__volatile)) \
{ \
static const GEnumValue v[] = { \
values \
{ 0, NULL, NULL }, \
}; \
GType g_define_id = g_enum_register_static (g_intern_static_string (#TypeName), v); \
g_once_init_leave (&g_define_id__volatile, g_define_id); \
} \
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"))

View file

@ -0,0 +1,77 @@
#include "winrt-event-token-private.h"
#define WINRT_EVENT_TOKEN_GET_PRIVATE(obj) \
((winrtEventTokenPrivate*) winrt_event_token_get_instance_private ((winrtEventToken*) (obj)))
typedef struct
{
winrt::event_token* token;
} winrtEventTokenPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (winrtEventToken, winrt_event_token, G_TYPE_OBJECT)
static void winrt_event_token_finalize(GObject* self)
{
winrtEventTokenPrivate* priv = WINRT_EVENT_TOKEN_GET_PRIVATE (self);
delete priv->token;
G_OBJECT_CLASS(winrt_event_token_parent_class)->dispose(self);
}
static void winrt_event_token_class_init (winrtEventTokenClass* klass)
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = winrt_event_token_finalize;
}
static void winrt_event_token_init (winrtEventToken *self)
{
}
/*< private >
* winrt_event_token_get_internal:
* @self: a #winrtEventToken
*
* Retrieves the `winrt::Windows::UI::Notifications::ToastNotification` object used by @self.
*
* Returns: (transfer none): a pointer to the internal toast notification instance
*/
winrt::event_token* winrt_event_token_get_internal(winrtEventToken *self)
{
winrtEventTokenPrivate *priv = WINRT_EVENT_TOKEN_GET_PRIVATE(self);
return priv->token;
}
/*< private >
* winrt_event_token_new:
* @doc: the document to be shown
*
* Creates a new toast notification with a document already set.
*
* Returns: (transfer full): the newly created #winrtEventToken instance
*/
winrtEventToken* winrt_event_token_new_from_token(winrt::event_token* token)
{
auto ret = static_cast<winrtEventToken*>(g_object_new (WINRT_TYPE_EVENT_TOKEN, NULL));
// winrtEventTokenPrivate* priv = WINRT_EVENT_TOKEN_GET_PRIVATE(ret);
// priv->token = new winrt::event_token(*token);
return ret;
}
gboolean winrt_event_token_operator_bool(winrtEventToken* self)
{
g_return_val_if_fail(WINRT_IS_EVENT_TOKEN(self), FALSE);
return winrt_event_token_get_internal(self)->operator bool();
}
gint64 winrt_event_token_create_toast_notifier_get_value(winrtEventToken* self)
{
g_return_val_if_fail (WINRT_IS_EVENT_TOKEN (self), 0);
//return winrt_event_token_get_internal(self)->value;
return 0;
}

View file

@ -0,0 +1,230 @@
/**
* 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 "winrt-toast-notification-private.h"
#include "winrt-event-token-private.h"
#include "converter.hpp"
#define WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(obj) \
((winrtWindowsUINotificationsToastNotificationPrivate*) winrt_windows_ui_notifications_toast_notification_get_instance_private ((winrtWindowsUINotificationsToastNotification*) (obj)))
typedef struct
{
winrt::Windows::UI::Notifications::ToastNotification data;
} _winrtWindowsUINotificationsToastNotificationPrivate;
typedef struct
{
Notification_Callback_Simple activated;
void* activated_context;
void(*activated_free)(void*);
Notification_Callback_Simple failed;
void* failed_context;
void(*failed_free)(void*);
// Notification_Callback_ActivatedWithActionIndex callback;
// void* context;
// void(*free)(void*);
// Notification_Callback_Dismissed callback;
// void* context;
// void(*free)(void*);
_winrtWindowsUINotificationsToastNotificationPrivate* notification;
} winrtWindowsUINotificationsToastNotificationPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (winrtWindowsUINotificationsToastNotification, winrt_windows_ui_notifications_toast_notification, G_TYPE_OBJECT)
static void winrt_windows_ui_notifications_toast_notification_finalize(GObject* self)
{
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE (self);
delete priv->notification;
// TODO: save token to remove the notification
if (priv->activated && priv->activated_context && priv->activated_free)
{
priv->activated_free(priv->activated_context);
}
if (priv->failed && priv->failed_context && priv->failed_free)
{
priv->failed_free(priv->failed_context);
}
G_OBJECT_CLASS(winrt_windows_ui_notifications_toast_notification_parent_class)->dispose(self);
}
static void winrt_windows_ui_notifications_toast_notification_class_init (winrtWindowsUINotificationsToastNotificationClass* klass)
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
gobject_class->finalize = winrt_windows_ui_notifications_toast_notification_finalize;
}
static void winrt_windows_ui_notifications_toast_notification_init (winrtWindowsUINotificationsToastNotification *self)
{
}
/*< private >
* winrt_windows_ui_notifications_toast_notification_get_internal:
* @self: a #winrtWindowsUINotificationsToastNotification
*
* Retrieves the `winrt::Windows::UI::Notifications::ToastNotification` object used by @self.
*
* Returns: (transfer none): a pointer to the internal toast notification instance
*/
winrt::Windows::UI::Notifications::ToastNotification* winrt_windows_ui_notifications_toast_notification_get_internal(winrtWindowsUINotificationsToastNotification *self)
{
winrtWindowsUINotificationsToastNotificationPrivate *priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE (self);
return &priv->notification->data;
}
/*< private >
* winrt_windows_ui_notifications_toast_notification_set_internal:
* @self: a #winrtWindowsUINotificationsToastNotification
* @notification: a `winrt::Windows::UI::Notifications::ToastNotification` instance
*
* Sets the internal database instance wrapped by @self, clearing
* any existing instance if needed.
*/
void winrt_windows_ui_notifications_toast_notification_set_internal(winrtWindowsUINotificationsToastNotification* self, winrt::Windows::UI::Notifications::ToastNotification notification)
{
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
delete priv->notification;
priv->notification = new _winrtWindowsUINotificationsToastNotificationPrivate { notification };
}
/**
* winrt_windows_ui_notifications_toast_notification_new:
* @doc: the document to be shown
*
* Creates a new toast notification with a document already set.
*
* Returns: (transfer full): the newly created #winrtWindowsUINotificationsToastNotification instance
*/
winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const char* doc)
{
g_return_val_if_fail (doc == NULL, NULL);
auto ret = static_cast<winrtWindowsUINotificationsToastNotification*>(g_object_new (WINRT_TYPE_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION, NULL));
winrt::Windows::Data::Xml::Dom::XmlDocument xmlDoc;
xmlDoc.LoadXml(char_to_wstr(doc));
winrt_windows_ui_notifications_toast_notification_set_internal(ret, winrt::Windows::UI::Notifications::ToastNotification{ xmlDoc });
return ret;
}
void winrt_windows_ui_notifications_toast_notification_set_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self, gboolean value)
{
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
winrt_windows_ui_notifications_toast_notification_get_internal(self)->ExpiresOnReboot(value);
}
gboolean winrt_windows_ui_notifications_toast_notification_get_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self)
{
g_return_val_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self), FALSE);
return winrt_windows_ui_notifications_toast_notification_get_internal(self)->ExpiresOnReboot();
}
void winrt_windows_ui_notifications_toast_notification_set_Tag(winrtWindowsUINotificationsToastNotification* self, const char* value)
{
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
winrt_windows_ui_notifications_toast_notification_get_internal(self)->Tag(char_to_wstr(value));
}
/**
* winrt_windows_ui_notifications_toast_notification_get_Tag:
* @manager: a #winrtWindowsUINotificationsToastNotification
*
* Returns the value of the tag
*
* Returns: (transfer full): the value
*/
char* winrt_windows_ui_notifications_toast_notification_get_Tag(winrtWindowsUINotificationsToastNotification* self)
{
g_return_val_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self), FALSE);
return wstr_to_char(std::wstring(winrt_windows_ui_notifications_toast_notification_get_internal(self)->Tag()));
}
void winrt_windows_ui_notifications_toast_notification_set_Group(winrtWindowsUINotificationsToastNotification* self, const char* value)
{
g_return_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self));
winrt_windows_ui_notifications_toast_notification_get_internal(self)->Group(char_to_wstr(value));
}
/**
* winrt_windows_ui_notifications_toast_notification_get_Group:
* @manager: a #winrtWindowsUINotificationsToastNotification
*
* Returns the value of the group
*
* Returns: (transfer full): the value
*/
char* winrt_windows_ui_notifications_toast_notification_get_Group(winrtWindowsUINotificationsToastNotification* self)
{
g_return_val_if_fail (WINRT_IS_WINDOWS_UI_NOTIFICATIONS_TOAST_NOTIFICATION (self), FALSE);
return wstr_to_char(std::wstring(winrt_windows_ui_notifications_toast_notification_get_internal(self)->Group()));
}
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(winrtWindowsUINotificationsToastNotification* self, Notification_Callback_Simple callback, void* context, void(*free)(void*))
{
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
if (priv->activated && priv->activated_context && priv->activated_free)
{
// TODO: should also save token to unregister it
priv->activated_free(priv->activated_context);
}
priv->activated = callback;
priv->activated_context = context;
priv->activated_free = free;
auto token = priv->notification->data.Activated([&](auto sender, winrt::Windows::Foundation::IInspectable inspectable)
{
std::cout << "Notification activated!" << std::endl;
priv->activated(priv->activated_context);
});
return winrt_event_token_new_from_token(&token);
return nullptr;
}
void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token)
{
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
if (winrt_event_token_operator_bool(token))
{
priv->notification->data.Activated(*winrt_event_token_get_internal(token));
}
if (priv->activated && priv->activated_context && priv->activated_free)
{
priv->activated_free(priv->activated_context);
priv->activated = nullptr;
priv->activated_context = nullptr;
priv->activated_free = nullptr;
}
}

View file

@ -0,0 +1,18 @@
#include <iostream>
#include "gobject/winrt-private.h"
gboolean winrt_InitApartment()
{
try
{
//winrt::init_apartment(); // TODO: FIXME
return true;
}
catch(const std::exception& e)
{
std::cerr << e.what() << '\n';
}
return false;
}

View file

@ -1,106 +0,0 @@
#include "toastnotification.h"
DinoToastNotification_t NewNotification() {
return new std::shared_ptr<DinoToastNotification>();
}
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);
}
}

View file

@ -1,8 +0,0 @@
#include <winrt/base.h>
#include "winrt.h"
gboolean Initialize()
{
winrt::init_apartment();
}

View file

@ -10,7 +10,7 @@ public class Plugin : RootInterface, Object {
public int m { get; set; }
public void registered(Dino.Application app) {
if (!WinRTApi.Initialize())
if (!winrt.InitApartment())
{
// log error, return
}
@ -25,35 +25,23 @@ public class Plugin : RootInterface, Object {
// log error, return
}
var notification = new ToastNotification.ToastNotification();
int test = 2;
notification.Activated = new Callbacks.SimpleNotificationCallback()
{
callback = () => {
test = 3;
}
};
var m = new winrt.Windows.UI.Notifications.ToastNotification("Test");
var token = m.Activated(() => {
var i = 2;
});
m.RemoveActivatedAction(token);
notification.ActivatedWithIndex = new Callbacks.ActivatedWithActionIndexNotificationCallback()
{
callback = (index) => {
test = index;
}
};
notification.Dismissed = new Callbacks.DismissedNotificationCallback()
{
callback = (reason) => {
var m = reason;
}
};
var h = m.ExpiresOnReboot;
m.ExpiresOnReboot = false;
notification.Failed = new Callbacks.SimpleNotificationCallback()
{
callback = () => {
var m = 2;
var a = m.Tag;
m.Tag = "a";
a = m.Group;
m.Group = "a";
}
};
// var provider = new WindowsNotificationProvider(app, Win32Api.SupportsModernNotifications());
// app.stream_interactor.get_module(NotificationEvents.IDENTITY).register_notification_provider(provider);

View file

@ -12,12 +12,14 @@ namespace Dino.Plugins.WindowsNotification {
private Gee.List<int64?> marked_for_removal;
private Gee.List<int64?> content_notifications;
private HashMap<Conversation, Gee.List<int64?>> conversation_notifications;
private bool supportsModernNotifications;
private class Notification {
public int64? id;
}
private WindowsNotificationProvider(Dino.Application app) {
public WindowsNotificationProvider(Dino.Application app, bool supportsModernNotifications) {
this.supportsModernNotifications = supportsModernNotifications;
this.stream_interactor = app.stream_interactor;
this.app = app;
this.marked_for_removal = new Gee.ArrayList<int64?>();
@ -25,15 +27,6 @@ namespace Dino.Plugins.WindowsNotification {
this.conversation_notifications = new HashMap<Conversation, Gee.List<int64?>>(Conversation.hash_func, Conversation.equals_func);
}
public static WindowsNotificationProvider? try_create(Dino.Application app) {
var valid = Init() == 0;
if (valid) {
return new WindowsNotificationProvider(app);
}
warning("Unable to initialize Windows notification provider");
return null;
}
public double get_priority() {
return 2;
}

View file

@ -1,43 +0,0 @@
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;
}
}

View file

@ -1,36 +0,0 @@
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;
}
}
}

View file

@ -1,5 +1,13 @@
[CCode (cheader_filename = "winrt.h")]
namespace Dino.Plugins.WindowsNotification.Vapi.WinRTApi {
[CCode (cname = "Initialize")]
public bool Initialize();
[CCode (cheader_filename = "gobject/winrt-glib.h")]
namespace winrt {
public bool InitApartment();
[CCode (type_id = "winrt_event_token_get_type ()")]
public class EventToken : GLib.Object {
[CCode (has_construct_function = false)]
public EventToken();
public int64 value { get; }
[CCode(cname = "winrt_event_token_operator_bool")]
public bool IsValid();
}
}

View file

@ -0,0 +1,21 @@
[CCode (cheader_filename = "gobject/winrt-glib.h")]
namespace winrt.Windows.UI.Notifications {
[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 (type_id = "winrt_windows_ui_notifications_toast_notification_get_type ()")]
public class ToastNotification : GLib.Object {
public ToastNotification(string doc);
public bool ExpiresOnReboot { get; set; }
public string Tag { get; set; } // TODO: check if valac is cleaning this string
public string Group { get; set; }
public winrt.EventToken Activated(owned NotificationCallbackSimple handler);
public void RemoveActivatedAction(winrt.EventToken token);
}
}