diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala index 43e76be0..ba275ef0 100644 --- a/plugins/windows-notification/src/plugin.vala +++ b/plugins/windows-notification/src/plugin.vala @@ -16,11 +16,14 @@ public class Plugin : RootInterface, Object { [CCode (has_target = false)] private delegate void notification_callback(void* conv); - [CCode (cname = "init", cheader_filename = "wintoast.h")] - private static extern int init(notification_callback callback); + [CCode (cname = "load_library", cheader_filename = "wintoast.h")] + private static extern int load_library(); - [CCode (cname = "uninit", cheader_filename = "wintoast.h")] - private static extern void uninit(); + [CCode (cname = "init_library", cheader_filename = "wintoast.h")] + private static extern int init_library(notification_callback callback); + + [CCode (cname = "uninit_library", cheader_filename = "wintoast.h")] + private static extern void uninit_library(); [CCode (cname = "show_message", cheader_filename = "wintoast.h")] private static extern int show_message(char* sender, char* message, char* imagePath, char* protocolName, void *conv); @@ -36,8 +39,10 @@ public class Plugin : RootInterface, Object { public void registered(Dino.Application app) { this.app = app; - - init(onclick_callback); + if (load_library() != 1 || + init_library(onclick_callback) != 1) { + return; + } app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((item, conversation) => { if (item.type_ == "message") { @@ -52,13 +57,15 @@ public class Plugin : RootInterface, Object { //var message = item.encryption == Encryption.NONE ? message_item.message.body : "*encrypted*"; var message = message_item.message.body; var sender = conversation.nickname != null ? conversation.nickname : conversation.counterpart.to_string(); - show_message(sender, message + "\n", "", "", this); + if (show_message(sender, message, "", "", this) != 0) { + stderr.printf("Error sending notification."); + }; } }); } public void shutdown() { - uninit(); + uninit_library(); } } diff --git a/plugins/windows-notification/src/wintoast.c b/plugins/windows-notification/src/wintoast.c index f05aaddd..262d8ed3 100644 --- a/plugins/windows-notification/src/wintoast.c +++ b/plugins/windows-notification/src/wintoast.c @@ -3,47 +3,48 @@ #include "wintoast.h" -void(*callback)(void*) = NULL; +static HMODULE library_handle = NULL; +static PidginWinToastLibInitType library_init = NULL; +static PidginWinToastLibShowMessageType library_show_message = NULL; -HMODULE library_handle = NULL; - -typedef void(*ClickCallbackType)(void*); -typedef int(*PidginWinToastLibInitType)(ClickCallbackType); -typedef int(*PidginWinToastLibShowMessageType)(const char*, const char*, const char*, const char*, void*); - -PidginWinToastLibInitType library_init = NULL; -PidginWinToastLibShowMessageType library_show_message = NULL; - -void init(ClickCallbackType notification_click_callback) { - printf("Inicializando\n"); - - callback = notification_click_callback; +int load_library() { library_handle = LoadLibrary("PidginWinToastLib.dll"); - if (library_handle) { - FARPROC function = GetProcAddress(library_handle, "pidginWinToastLibInit"); - if (function) { - library_init = (PidginWinToastLibInitType)function; - } - - function = GetProcAddress(library_handle, "pidginWinToastLibShowMessage"); - if (function) { - library_show_message = (PidginWinToastLibShowMessageType)function; - } + if (!library_handle) { + return FALSE; } - - if (library_init) { - library_init(notification_click_callback); + + FARPROC function = GetProcAddress(library_handle, "pidginWinToastLibInit"); + if (!function) { + return FALSE; } + library_init = (PidginWinToastLibInitType)function; + + function = GetProcAddress(library_handle, "pidginWinToastLibShowMessage"); + if (!function) { + return FALSE; + } + library_show_message = (PidginWinToastLibShowMessageType)function; + return TRUE; } -void uninit() { +int init_library(ClickCallbackType notification_click_callback) { + if (!library_init) { + return FALSE; + } + library_init(notification_click_callback); + return TRUE; +} + +void uninit_library() { if (library_handle) { FreeLibrary(library_handle); } } -void show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv) { +int show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv) { if (library_show_message) { - library_show_message(sender, message, imagePath, protocolName, conv); + return library_show_message(sender, message, imagePath, protocolName, conv); } + + return -1; } \ No newline at end of file diff --git a/plugins/windows-notification/src/wintoast.h b/plugins/windows-notification/src/wintoast.h index 568d4bbc..73d2a436 100644 --- a/plugins/windows-notification/src/wintoast.h +++ b/plugins/windows-notification/src/wintoast.h @@ -1,8 +1,13 @@ #ifndef WINTOAST #define WINTOAST 1 -void init(void(*notification_click_callback)(void *conv)); -void uninit(); -void show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv); +typedef void(*ClickCallbackType)(void*); +typedef int(*PidginWinToastLibInitType)(ClickCallbackType); +typedef int(*PidginWinToastLibShowMessageType)(const char*, const char*, const char*, const char*, void*); + +int load_library(); +int init_library(ClickCallbackType click_callback); +void uninit_library(); +int show_message(const char * sender, const char * message, const char * imagePath, const char * protocolName, void *conv); #endif \ No newline at end of file