From 8553a7cd863a4232871d573d8d07bb4d0399c731 Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Sun, 25 Oct 2020 11:09:46 -0300 Subject: [PATCH] Add callback support --- plugins/windows-notification/src/plugin.vala | 13 +++----- .../windows-notification/src/wintoast.vala | 30 +++++++++---------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/plugins/windows-notification/src/plugin.vala b/plugins/windows-notification/src/plugin.vala index 7dba54fa..d7203758 100644 --- a/plugins/windows-notification/src/plugin.vala +++ b/plugins/windows-notification/src/plugin.vala @@ -8,18 +8,13 @@ public class Plugin : RootInterface, Object { private ulong signal_handler = 0; private WinToast toaster; - private void onclick_callback() { - // TODO: - // This callback should: - // * Open Dino - // * Open Conversation from notification - // * Go to line - // The callback will probably need to receive at least one parameter more. Not difficult to do. + private void onclick_callback(int conv_id) { + this.app.activate_action("open-conversation", conv_id); } public void registered(Dino.Application app) { this.app = app; - this.toaster = new WinToast(onclick_callback); + this.toaster = new WinToast(); if (toaster.valid) { signal_handler = app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect(on_notify); } @@ -64,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, this)) { + if (!toaster.show_message(display_name, text, avatar, conversation.id, this, onclick_callback)) { stderr.printf("Error sending notification."); }; } diff --git a/plugins/windows-notification/src/wintoast.vala b/plugins/windows-notification/src/wintoast.vala index 013fc50b..35e77f3d 100644 --- a/plugins/windows-notification/src/wintoast.vala +++ b/plugins/windows-notification/src/wintoast.vala @@ -3,14 +3,14 @@ namespace Dino.Plugins.WindowsNotification { [CCode (has_target = false)] private delegate void FunctionPointer(); - [CCode (has_target = false)] - public delegate void NotificationCallback(void* conv); + [CCode (has_target = true)] + public delegate void NotificationCallback(int conv_id); [CCode (has_target = false)] - private delegate int PidginWinToastLibInitType(NotificationCallback callback); + private delegate int DinoWinToastLibInitType(); [CCode (has_target = false)] - private delegate int PidginWinToastLibShowMessageType(char* sender, char* message, char* image_path, char* protocolName, void *conv); + 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); @@ -22,15 +22,15 @@ namespace Dino.Plugins.WindowsNotification { private static extern FunctionPointer get_proc_address(void* lib_handle, char* func_name); private void* library_handle = null; - private PidginWinToastLibInitType library_init = null; - private PidginWinToastLibShowMessageType library_show_message = null; + private DinoWinToastLibInitType library_init = null; + private DinoWinToastLibShowMessageType library_show_message = null; public bool valid { get; private set; } - public WinToast(NotificationCallback callback) { + public WinToast() { valid = load(); if (valid) { - valid = library_init(callback) == 0; + valid = library_init() == 0; } } @@ -40,30 +40,30 @@ namespace Dino.Plugins.WindowsNotification { } } - public bool show_message(string sender, string message, string image_path, void *conv) { + 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, null, conv) == 0; + return library_show_message(sender, message, image_path, conv_id, class_obj, callback) == 0; } return false; } private bool load() { - library_handle = load_library("PidginWinToastLib.dll"); + library_handle = load_library("DinoWinToastLib.dll"); if (library_handle == null) { return false; } - FunctionPointer function = get_proc_address(library_handle, "pidginWinToastLibInit"); + FunctionPointer function = get_proc_address(library_handle, "dinoWinToastLibInit"); if (function == null) { return false; } - library_init = (PidginWinToastLibInitType)function; + library_init = (DinoWinToastLibInitType)function; - function = get_proc_address(library_handle, "pidginWinToastLibShowMessage"); + function = get_proc_address(library_handle, "dinoWinToastLibShowMessage"); if (function == null) { return false; } - library_show_message = (PidginWinToastLibShowMessageType)function; + library_show_message = (DinoWinToastLibShowMessageType)function; return true; } }