protect GetTemplateContent callers from exceptions

This commit is contained in:
mjk 2021-03-20 03:15:29 +00:00 committed by LAGonauta
parent ed7c23c8d2
commit c855d5e7cb
2 changed files with 18 additions and 10 deletions

View file

@ -8,15 +8,17 @@
#include "winrt-enums.h" #include "winrt-enums.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" #define EXTERN extern "C"
{ #define NOEXCEPT noexcept
#else
#define EXTERN
#define NOEXCEPT
#endif #endif
gboolean winrt_InitApartment(); EXTERN gboolean winrt_InitApartment();
char* winrt_windows_ui_notifications_toast_notification_manager_GetTemplateContent(winrtWindowsUINotificationsToastTemplateType type); EXTERN char* winrt_windows_ui_notifications_toast_notification_manager_GetTemplateContent(winrtWindowsUINotificationsToastTemplateType type) NOEXCEPT;
#ifdef __cplusplus #undef EXTERN
} #undef NOEXCEPT
#endif
#endif // __WINRT_GLIB_2_H__ #endif // __WINRT_GLIB_2_H__

View file

@ -2,6 +2,7 @@
#include "gobject/winrt-private.h" #include "gobject/winrt-private.h"
#include "converter.hpp" #include "converter.hpp"
#include "ginvoke.hpp"
gboolean winrt_InitApartment() gboolean winrt_InitApartment()
{ {
@ -24,8 +25,13 @@ gboolean winrt_InitApartment()
return false; return false;
} }
char* winrt_windows_ui_notifications_toast_notification_manager_GetTemplateContent(winrtWindowsUINotificationsToastTemplateType type) static char* ImplGetTemplateContent(winrtWindowsUINotificationsToastTemplateType type)
{ {
using namespace winrt::Windows::UI::Notifications; using namespace winrt::Windows::UI::Notifications;
return wsview_to_char(ToastNotificationManager::GetTemplateContent(static_cast<ToastTemplateType>(type)).GetXml()); return wsview_to_char(ToastNotificationManager::GetTemplateContent(static_cast<ToastTemplateType>(type)).GetXml());
} }
char* winrt_windows_ui_notifications_toast_notification_manager_GetTemplateContent(winrtWindowsUINotificationsToastTemplateType type) noexcept
{
return g_try_invoke(ImplGetTemplateContent, type).value_or(nullptr);
}