Initial code to allow buttons and text
This commit is contained in:
parent
ae9671716f
commit
ca0cab0e36
|
@ -27,10 +27,7 @@ PACKAGES
|
||||||
)
|
)
|
||||||
|
|
||||||
set(WINDOWS_API_SOURCES
|
set(WINDOWS_API_SOURCES
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/api/src/gobject/winrt.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/api/src/unity.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/win32.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/api/src/converter.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/api/src/converter.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/api/src/shortcutcreator.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/api/src/shortcutcreator.cpp
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
#include <winrt/Windows.UI.Notifications.h>
|
#include <winrt/Windows.UI.Notifications.h>
|
||||||
#include <winrt/Windows.Data.Xml.Dom.h>
|
#include <winrt/Windows.Data.Xml.Dom.h>
|
||||||
#include <winrt/Windows.Foundation.h>
|
#include <winrt/Windows.Foundation.h>
|
||||||
|
#include <winrt/Windows.Foundation.Collections.h>
|
||||||
|
|
||||||
#endif /* __WINRT_HEADERS_H__ */
|
#endif /* __WINRT_HEADERS_H__ */
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "winrt.h"
|
#include "winrt.h"
|
||||||
//#include "gobject/winrt-headers.h"
|
#include "gobject/winrt-headers.h"
|
||||||
|
|
||||||
#endif // __WINRT_GLIB_H_PRIVATE__
|
#endif // __WINRT_GLIB_H_PRIVATE__
|
|
@ -25,25 +25,25 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void(*Notification_Callback_Simple)(void* userdata);
|
typedef void(*NotificationCallbackSimple)(void* userdata);
|
||||||
typedef void(*Notification_Callback_ActivatedWithActionIndex)(int action_id, 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(*Notification_Callback_Dismissed)(Dismissed_Reason reason, void* userdata);
|
||||||
|
|
||||||
winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const char* doc);
|
winrtWindowsUINotificationsToastNotification* winrt_windows_ui_notifications_toast_notification_new(const gchar* doc);
|
||||||
|
|
||||||
void winrt_windows_ui_notifications_toast_notification_set_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self, gboolean value);
|
void winrt_windows_ui_notifications_toast_notification_set_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self, gboolean value);
|
||||||
gboolean winrt_windows_ui_notifications_toast_notification_get_ExpiresOnReboot(winrtWindowsUINotificationsToastNotification* self);
|
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);
|
void winrt_windows_ui_notifications_toast_notification_set_Tag(winrtWindowsUINotificationsToastNotification* self, const gchar* value);
|
||||||
char* winrt_windows_ui_notifications_toast_notification_get_Tag(winrtWindowsUINotificationsToastNotification* self);
|
gchar* winrt_windows_ui_notifications_toast_notification_get_Tag(winrtWindowsUINotificationsToastNotification* self);
|
||||||
|
|
||||||
void winrt_windows_ui_notifications_toast_notification_set_Group(winrtWindowsUINotificationsToastNotification* self, const char* value);
|
void winrt_windows_ui_notifications_toast_notification_set_Group(winrtWindowsUINotificationsToastNotification* self, const gchar* value);
|
||||||
char* winrt_windows_ui_notifications_toast_notification_get_Group(winrtWindowsUINotificationsToastNotification* self);
|
gchar* 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*));
|
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackActivated callback, void* context, void(*free)(void*));
|
||||||
void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token);
|
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_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, Notification_Callback_Dismissed callback, void* context, void(*free)(void*));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __WINRT_GLIB_H__
|
#ifndef __WINRT_GLIB_2_H__
|
||||||
#define __WINRT_GLIB_H__
|
#define __WINRT_GLIB_2_H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -12,4 +12,4 @@ gboolean winrt_InitApartment();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // __WINRT_GLIB_H__
|
#endif // __WINRT_GLIB_2_H__
|
|
@ -68,10 +68,9 @@ gboolean winrt_event_token_operator_bool(winrtEventToken* self)
|
||||||
return winrt_event_token_get_internal(self)->operator bool();
|
return winrt_event_token_get_internal(self)->operator bool();
|
||||||
}
|
}
|
||||||
|
|
||||||
gint64 winrt_event_token_create_toast_notifier_get_value(winrtEventToken* self)
|
gint64 winrt_event_token_get_value(winrtEventToken* self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (WINRT_IS_EVENT_TOKEN (self), 0);
|
g_return_val_if_fail (WINRT_IS_EVENT_TOKEN (self), 0);
|
||||||
|
|
||||||
//return winrt_event_token_get_internal(self)->value;
|
return winrt_event_token_get_internal(self)->value;
|
||||||
return 0;
|
|
||||||
}
|
}
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
#include "winrt-toast-notification-private.h"
|
#include "winrt-toast-notification-private.h"
|
||||||
#include "winrt-event-token-private.h"
|
#include "winrt-event-token-private.h"
|
||||||
|
@ -25,15 +27,28 @@ typedef struct
|
||||||
winrt::Windows::UI::Notifications::ToastNotification data;
|
winrt::Windows::UI::Notifications::ToastNotification data;
|
||||||
} _winrtWindowsUINotificationsToastNotificationPrivate;
|
} _winrtWindowsUINotificationsToastNotificationPrivate;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class Callback {
|
||||||
|
public:
|
||||||
|
T callback;
|
||||||
|
void* context;
|
||||||
|
void(*free)(void*);
|
||||||
|
winrtEventToken* token;
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
callback = nullptr;
|
||||||
|
context = nullptr;
|
||||||
|
free = nullptr;
|
||||||
|
g_clear_object(&token);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Notification_Callback_Simple activated;
|
Callback<NotificationCallbackActivated> activated;
|
||||||
void* activated_context;
|
|
||||||
void(*activated_free)(void*);
|
|
||||||
|
|
||||||
Notification_Callback_Simple failed;
|
Callback<NotificationCallbackSimple> failed;
|
||||||
void* failed_context;
|
|
||||||
void(*failed_free)(void*);
|
|
||||||
|
|
||||||
// Notification_Callback_ActivatedWithActionIndex callback;
|
// Notification_Callback_ActivatedWithActionIndex callback;
|
||||||
// void* context;
|
// void* context;
|
||||||
|
@ -52,17 +67,24 @@ static void winrt_windows_ui_notifications_toast_notification_finalize(GObject*
|
||||||
{
|
{
|
||||||
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE (self);
|
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE (self);
|
||||||
|
|
||||||
delete priv->notification;
|
if (winrt_event_token_operator_bool(priv->activated.token))
|
||||||
|
|
||||||
// TODO: save token to remove the notification
|
|
||||||
if (priv->activated && priv->activated_context && priv->activated_free)
|
|
||||||
{
|
{
|
||||||
priv->activated_free(priv->activated_context);
|
priv->notification->data.Activated(*winrt_event_token_get_internal(priv->activated.token));
|
||||||
|
g_clear_object(&priv->activated.token);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->failed && priv->failed_context && priv->failed_free)
|
delete priv->notification;
|
||||||
|
|
||||||
|
if (priv->activated.callback && priv->activated.context && priv->activated.free)
|
||||||
{
|
{
|
||||||
priv->failed_free(priv->failed_context);
|
priv->activated.free(priv->activated.context);
|
||||||
|
priv->activated.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->failed.callback && priv->failed.context && priv->failed.free)
|
||||||
|
{
|
||||||
|
priv->failed.free(priv->failed.context);
|
||||||
|
priv->failed.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS(winrt_windows_ui_notifications_toast_notification_parent_class)->dispose(self);
|
G_OBJECT_CLASS(winrt_windows_ui_notifications_toast_notification_parent_class)->dispose(self);
|
||||||
|
@ -188,43 +210,67 @@ char* winrt_windows_ui_notifications_toast_notification_get_Group(winrtWindowsUI
|
||||||
return wstr_to_char(std::wstring(winrt_windows_ui_notifications_toast_notification_get_internal(self)->Group()));
|
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*))
|
winrtEventToken* winrt_windows_ui_notifications_toast_notification_Activated(winrtWindowsUINotificationsToastNotification* self, NotificationCallbackActivated 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);
|
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||||
|
|
||||||
if (priv->activated && priv->activated_context && priv->activated_free)
|
winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(self, priv->activated.token);
|
||||||
{
|
|
||||||
// TODO: should also save token to unregister it
|
|
||||||
priv->activated_free(priv->activated_context);
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->activated = callback;
|
priv->activated.callback = callback;
|
||||||
priv->activated_context = context;
|
priv->activated.context = context;
|
||||||
priv->activated_free = free;
|
priv->activated.free = free;
|
||||||
|
|
||||||
auto token = priv->notification->data.Activated([&](auto sender, winrt::Windows::Foundation::IInspectable inspectable)
|
auto token = priv->notification->data.Activated([&](auto sender, winrt::Windows::Foundation::IInspectable inspectable)
|
||||||
{
|
{
|
||||||
|
std::wstring arguments;
|
||||||
|
std::vector<std::tuple<std::wstring, std::wstring>> user_input;
|
||||||
|
{
|
||||||
|
auto args = inspectable.try_as<winrt::Windows::UI::Notifications::IToastActivatedEventArgs>();
|
||||||
|
if (args != nullptr)
|
||||||
|
{
|
||||||
|
arguments = std::wstring(args.Arguments());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto args = inspectable.try_as<winrt::Windows::UI::Notifications::IToastActivatedEventArgs2>();
|
||||||
|
if (args != nullptr)
|
||||||
|
{
|
||||||
|
for (const auto& item : args.UserInput())
|
||||||
|
{
|
||||||
|
auto value = winrt::unbox_value_or<winrt::hstring>(item.Value(), winrt::hstring());
|
||||||
|
user_input.emplace_back(std::make_tuple(std::wstring(item.Key()), std::wstring(value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Notification activated!" << std::endl;
|
std::cout << "Notification activated!" << std::endl;
|
||||||
priv->activated(priv->activated_context);
|
priv->activated.callback(wstr_to_char(arguments.data()), nullptr, user_input.size(), priv->activated.context);
|
||||||
});
|
});
|
||||||
return winrt_event_token_new_from_token(&token);
|
priv->activated.token = winrt_event_token_new_from_token(&token);
|
||||||
return nullptr;
|
return priv->activated.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(winrtWindowsUINotificationsToastNotification* self, winrtEventToken* token)
|
void winrt_windows_ui_notifications_toast_notification_RemoveActivatedAction(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);
|
winrtWindowsUINotificationsToastNotificationPrivate* priv = WINRT_WINDOWS_UI_NOTIFICATION_TOAST_NOTIFICATION_GET_PRIVATE(self);
|
||||||
|
|
||||||
|
if (winrt_event_token_get_value(token) == winrt_event_token_get_value(priv->activated.token))
|
||||||
|
{
|
||||||
if (winrt_event_token_operator_bool(token))
|
if (winrt_event_token_operator_bool(token))
|
||||||
{
|
{
|
||||||
priv->notification->data.Activated(*winrt_event_token_get_internal(token));
|
priv->notification->data.Activated(*winrt_event_token_get_internal(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->activated && priv->activated_context && priv->activated_free)
|
if (priv->activated.callback && priv->activated.context && priv->activated.free)
|
||||||
{
|
{
|
||||||
priv->activated_free(priv->activated_context);
|
priv->activated.free(priv->activated.context);
|
||||||
priv->activated = nullptr;
|
priv->activated.Clear();
|
||||||
priv->activated_context = nullptr;
|
}
|
||||||
priv->activated_free = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ gboolean winrt_InitApartment()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//winrt::init_apartment(); // TODO: FIXME
|
winrt::init_apartment(); // TODO: FIXME, header only works with unity build
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
|
|
4
plugins/windows-notification/api/src/unity.cpp
Normal file
4
plugins/windows-notification/api/src/unity.cpp
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#include "./gobject/winrt.cpp"
|
||||||
|
#include "./gobject/winrt-toast-notification.cpp"
|
||||||
|
#include "./gobject/winrt-event-token.cpp"
|
||||||
|
#include "./gobject/winrt-enums.cpp"
|
|
@ -1,10 +1,10 @@
|
||||||
[CCode (cheader_filename = "gobject/winrt-glib.h")]
|
[CCode (cheader_filename = "gobject/winrt-glib.h")]
|
||||||
namespace winrt.Windows.UI.Notifications {
|
namespace winrt.Windows.UI.Notifications {
|
||||||
[CCode (cname = "Notification_Callback_Simple", has_target = true)]
|
[CCode (cname = "NotificationCallbackSimple", has_target = true)]
|
||||||
public delegate void NotificationCallbackSimple();
|
public delegate void NotificationCallbackSimple();
|
||||||
|
|
||||||
// [CCode (cname = "Notification_Callback_ActivatedWithActionIndex", has_target = true)]
|
[CCode (cname = "NotificationCallbackActivated", has_target = true)]
|
||||||
// public delegate void NotificationCallbackWithActionIndex(int actionId);
|
public delegate void NotificationCallbackActivated(string? arguments, string[]? userInput);
|
||||||
|
|
||||||
// [CCode (cname = "Notification_Callback_Dismissed", has_target = true)]
|
// [CCode (cname = "Notification_Callback_Dismissed", has_target = true)]
|
||||||
// public delegate void NotificationCallbackDismissed(DismissedReason reason);
|
// public delegate void NotificationCallbackDismissed(DismissedReason reason);
|
||||||
|
@ -15,7 +15,7 @@ namespace winrt.Windows.UI.Notifications {
|
||||||
public bool ExpiresOnReboot { get; set; }
|
public bool ExpiresOnReboot { get; set; }
|
||||||
public string Tag { get; set; } // TODO: check if valac is cleaning this string
|
public string Tag { get; set; } // TODO: check if valac is cleaning this string
|
||||||
public string Group { get; set; }
|
public string Group { get; set; }
|
||||||
public winrt.EventToken Activated(owned NotificationCallbackSimple handler);
|
public winrt.EventToken Activated(owned NotificationCallbackActivated handler);
|
||||||
public void RemoveActivatedAction(winrt.EventToken token);
|
public void RemoveActivatedAction(winrt.EventToken token);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue