diff --git a/plugins/windows-notification/CMakeLists.txt b/plugins/windows-notification/CMakeLists.txt index 3be2a506..ee2115c1 100644 --- a/plugins/windows-notification/CMakeLists.txt +++ b/plugins/windows-notification/CMakeLists.txt @@ -20,9 +20,18 @@ PACKAGES ${WINDOWS_NOTIFICATION_PACKAGES} ) +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/DinoWinToastLib.h" +COMMAND + cp "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib.h" "${CMAKE_BINARY_DIR}/exports/DinoWinToastLib.h" +DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib.h" +COMMENT + Copy header file DinoWinToastLib.h +) + add_definitions(${VALA_CFLAGS}) -add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} src/wintoast.c) -target_link_libraries(windows-notification libdino ${WINDOWS_NOTIFICATION_PACKAGES}) +add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} ${CMAKE_BINARY_DIR}/exports/DinoWinToastLib.h) +target_link_libraries(windows-notification libdino ${WINDOWS_NOTIFICATION_PACKAGES} "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib.lib") set_target_properties(windows-notification PROPERTIES PREFIX "") set_target_properties(windows-notification PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/) diff --git a/plugins/windows-notification/src/DinoWinToastLib.h b/plugins/windows-notification/src/DinoWinToastLib.h new file mode 100644 index 00000000..b0fe9ace --- /dev/null +++ b/plugins/windows-notification/src/DinoWinToastLib.h @@ -0,0 +1,27 @@ +#pragma once + +#ifdef _WIN32 +#ifdef DINOWINTOASTLIB_EXPORTS +#define DINOWINTOASTLIB_API __declspec(dllexport) +#else +#define DINOWINTOASTLIB_API __declspec(dllimport) +#endif +#else +#define DINOWINTOASTLIB_API +#endif + +#ifdef __cplusplus +extern "C" { +#endif + int DINOWINTOASTLIB_API dinoWinToastLibInit(); +#ifdef __cplusplus +} // extern "C" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + int DINOWINTOASTLIB_API dinoWinToastLibShowMessage(const char* sender, const char* message, const char* imagePath, int conv_id, void(*click_callback)(int conv_id, void* callback_target), void* callback_target); +#ifdef __cplusplus +} // extern "C" +#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastLib.lib b/plugins/windows-notification/src/DinoWinToastLib.lib new file mode 100644 index 00000000..bca01f66 Binary files /dev/null and b/plugins/windows-notification/src/DinoWinToastLib.lib differ diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala index d7203758..428f462d 100644 --- a/plugins/windows-notification/src/plugin.vala +++ b/plugins/windows-notification/src/plugin.vala @@ -59,7 +59,7 @@ public class Plugin : RootInterface, Object { } var avatar_manager = app.stream_interactor.get_module(AvatarManager.IDENTITY); var avatar = avatar_manager.get_avatar_filepath(conversation.account, conversation.counterpart); - if (!toaster.show_message(display_name, text, avatar, conversation.id, this, onclick_callback)) { + if (!toaster.show_message(display_name, text, avatar, conversation.id, onclick_callback)) { stderr.printf("Error sending notification."); }; } diff --git a/plugins/windows-notification/src/wintoast.vala b/plugins/windows-notification/src/wintoast.vala index 050d8d73..73c44d70 100644 --- a/plugins/windows-notification/src/wintoast.vala +++ b/plugins/windows-notification/src/wintoast.vala @@ -1,70 +1,25 @@ namespace Dino.Plugins.WindowsNotification { public class WinToast { - [CCode (has_target = false)] - private delegate void FunctionPointer(); - [CCode (has_target = true)] public delegate void NotificationCallback(int conv_id); - [CCode (has_target = false)] - private delegate int DinoWinToastLibInitType(); + [CCode (cname = "dinoWinToastLibInit", cheader_filename = "DinoWinToastLib.h")] + private static extern int DinoWinToastLibInit(); - [CCode (has_target = false)] - private delegate int DinoWinToastLibShowMessageType(char* sender, char* message, char* image_path, int conv_id, void* class_obj, NotificationCallback callback); - - [CCode (cname = "LoadLibrary", cheader_filename = "libloaderapi.h")] - private static extern void* load_library(char* lib_name); - - [CCode (cname = "FreeLibrary", cheader_filename = "libloaderapi.h")] - private static extern int free_library(void* handle); - - [CCode (cname = "GetProcAddress", cheader_filename = "libloaderapi.h")] - private static extern FunctionPointer get_proc_address(void* lib_handle, char* func_name); - - private void* library_handle = null; - private DinoWinToastLibInitType library_init = null; - private DinoWinToastLibShowMessageType library_show_message = null; + [CCode (cname = "dinoWinToastLibShowMessage", cheader_filename = "DinoWinToastLib.h")] + private static extern int DinoWinToastLibShowMessage(char* sender, char* message, char* image_path, int conv_id, NotificationCallback callback); public bool valid { get; private set; } public WinToast() { - valid = load(); + valid = DinoWinToastLibInit() == 0; + } + + public bool show_message(string sender, string message, string? image_path, int conv_id, NotificationCallback callback) { if (valid) { - valid = library_init() == 0; - } - } - - ~WinToast() { - if (library_handle != null) { - free_library(library_handle); - } - } - - public bool show_message(string sender, string message, string? image_path, int conv_id, void* class_obj, NotificationCallback callback) { - if (valid && library_show_message != null) { - return library_show_message(sender, message, image_path, conv_id, class_obj, callback) == 0; + return DinoWinToastLibShowMessage(sender, message, image_path, conv_id, callback) == 0; } return false; } - - private bool load() { - library_handle = load_library("DinoWinToastLib.dll"); - if (library_handle == null) { - return false; - } - - FunctionPointer function = get_proc_address(library_handle, "dinoWinToastLibInit"); - if (function == null) { - return false; - } - library_init = (DinoWinToastLibInitType)function; - - function = get_proc_address(library_handle, "dinoWinToastLibShowMessage"); - if (function == null) { - return false; - } - library_show_message = (DinoWinToastLibShowMessageType)function; - return true; - } } } \ No newline at end of file