winrt: Show some exceptions
This commit is contained in:
parent
552b2b1315
commit
ec94565cb9
|
@ -21,7 +21,7 @@
|
|||
|
||||
int notification_backend_supported (void);
|
||||
void notification_backend_show (const char *title, const char *text);
|
||||
int notification_backend_init (void);
|
||||
int notification_backend_init (const char **error);
|
||||
void notification_backend_deinit (void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <Windows.h>
|
||||
|
||||
void (*winrt_notification_backend_show) (const char *title, const char *text) = NULL;
|
||||
int (*winrt_notification_backend_init) (void) = NULL;
|
||||
int (*winrt_notification_backend_init) (const char **error) = NULL;
|
||||
void (*winrt_notification_backend_deinit) (void) = NULL;
|
||||
int (*winrt_notification_backend_supported) (void) = NULL;
|
||||
|
||||
|
@ -40,7 +40,7 @@ notification_backend_show (const char *title, const char *text)
|
|||
}
|
||||
|
||||
int
|
||||
notification_backend_init (void)
|
||||
notification_backend_init (const char **error)
|
||||
{
|
||||
UINT original_error_mode;
|
||||
GModule *module;
|
||||
|
@ -53,6 +53,7 @@ notification_backend_init (void)
|
|||
|
||||
if (module == NULL)
|
||||
{
|
||||
*error = "hcnotifications-winrt not found.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ notification_backend_init (void)
|
|||
g_module_symbol (module, "notification_backend_deinit", (gpointer *) &winrt_notification_backend_deinit);
|
||||
g_module_symbol (module, "notification_backend_supported", (gpointer *) &winrt_notification_backend_supported);
|
||||
|
||||
return winrt_notification_backend_init ();
|
||||
return winrt_notification_backend_init (error);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <codecvt>
|
||||
#include <strsafe.h>
|
||||
|
||||
#include <roapi.h>
|
||||
#include <windows.ui.notifications.h>
|
||||
|
@ -38,6 +39,14 @@ widen(const std::string & to_widen)
|
|||
return converter.from_bytes(to_widen);
|
||||
}
|
||||
|
||||
static std::string
|
||||
narrow(const std::wstring & to_narrow)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(to_narrow);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec (dllexport) void
|
||||
|
@ -74,13 +83,34 @@ extern "C"
|
|||
}
|
||||
|
||||
__declspec (dllexport) int
|
||||
notification_backend_init (void)
|
||||
notification_backend_init (const char **error)
|
||||
{
|
||||
if (!notifier)
|
||||
notifier = ToastNotificationManager::CreateToastNotifier (L"HexChat.Desktop.Notify");
|
||||
try
|
||||
{
|
||||
if (!notifier)
|
||||
notifier = ToastNotificationManager::CreateToastNotifier (L"HexChat.Desktop.Notify");
|
||||
}
|
||||
catch (Platform::Exception ^ ex)
|
||||
{
|
||||
static char exc_message[1024];
|
||||
std::string tmp = narrow(std::wstring(ex->Message->Data()));
|
||||
if (SUCCEEDED(StringCchPrintfA(exc_message, _countof(exc_message), "Error (0x%x): %s", ex->HResult, tmp.c_str())))
|
||||
*error = exc_message;
|
||||
else
|
||||
*error = "Exception + error converting exception message.";
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
*error = "Generic c++ exception.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (FAILED (Windows::Foundation::Initialize (RO_INIT_SINGLETHREADED)))
|
||||
{
|
||||
*error = "Error initializing Windows::Foundation.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -176,8 +176,13 @@ tray_cmd_cb (char *word[], char *word_eol[], gpointer userdata)
|
|||
int
|
||||
notification_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
|
||||
{
|
||||
if (!notification_backend_init ())
|
||||
const char* error = NULL;
|
||||
if (!notification_backend_init (&error))
|
||||
{
|
||||
if (error)
|
||||
hexchat_printf(plugin_handle, "Failed loading notification plugin: %s\n", error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ph = plugin_handle;
|
||||
*plugin_name = "";
|
||||
|
|
Loading…
Reference in New Issue