Add callback support
This commit is contained in:
parent
642ed6ab1b
commit
8553a7cd86
|
@ -8,18 +8,13 @@ public class Plugin : RootInterface, Object {
|
||||||
private ulong signal_handler = 0;
|
private ulong signal_handler = 0;
|
||||||
private WinToast toaster;
|
private WinToast toaster;
|
||||||
|
|
||||||
private void onclick_callback() {
|
private void onclick_callback(int conv_id) {
|
||||||
// TODO:
|
this.app.activate_action("open-conversation", conv_id);
|
||||||
// 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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registered(Dino.Application app) {
|
public void registered(Dino.Application app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.toaster = new WinToast(onclick_callback);
|
this.toaster = new WinToast();
|
||||||
if (toaster.valid) {
|
if (toaster.valid) {
|
||||||
signal_handler = app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect(on_notify);
|
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_manager = app.stream_interactor.get_module(AvatarManager.IDENTITY);
|
||||||
var avatar = avatar_manager.get_avatar_filepath(conversation.account, conversation.counterpart);
|
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.");
|
stderr.printf("Error sending notification.");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ namespace Dino.Plugins.WindowsNotification {
|
||||||
[CCode (has_target = false)]
|
[CCode (has_target = false)]
|
||||||
private delegate void FunctionPointer();
|
private delegate void FunctionPointer();
|
||||||
|
|
||||||
[CCode (has_target = false)]
|
[CCode (has_target = true)]
|
||||||
public delegate void NotificationCallback(void* conv);
|
public delegate void NotificationCallback(int conv_id);
|
||||||
|
|
||||||
[CCode (has_target = false)]
|
[CCode (has_target = false)]
|
||||||
private delegate int PidginWinToastLibInitType(NotificationCallback callback);
|
private delegate int DinoWinToastLibInitType();
|
||||||
|
|
||||||
[CCode (has_target = false)]
|
[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")]
|
[CCode (cname = "LoadLibrary", cheader_filename = "libloaderapi.h")]
|
||||||
private static extern void* load_library(char* lib_name);
|
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 static extern FunctionPointer get_proc_address(void* lib_handle, char* func_name);
|
||||||
|
|
||||||
private void* library_handle = null;
|
private void* library_handle = null;
|
||||||
private PidginWinToastLibInitType library_init = null;
|
private DinoWinToastLibInitType library_init = null;
|
||||||
private PidginWinToastLibShowMessageType library_show_message = null;
|
private DinoWinToastLibShowMessageType library_show_message = null;
|
||||||
|
|
||||||
public bool valid { get; private set; }
|
public bool valid { get; private set; }
|
||||||
|
|
||||||
public WinToast(NotificationCallback callback) {
|
public WinToast() {
|
||||||
valid = load();
|
valid = load();
|
||||||
if (valid) {
|
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) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool load() {
|
private bool load() {
|
||||||
library_handle = load_library("PidginWinToastLib.dll");
|
library_handle = load_library("DinoWinToastLib.dll");
|
||||||
if (library_handle == null) {
|
if (library_handle == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPointer function = get_proc_address(library_handle, "pidginWinToastLibInit");
|
FunctionPointer function = get_proc_address(library_handle, "dinoWinToastLibInit");
|
||||||
if (function == null) {
|
if (function == null) {
|
||||||
return false;
|
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) {
|
if (function == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
library_show_message = (PidginWinToastLibShowMessageType)function;
|
library_show_message = (DinoWinToastLibShowMessageType)function;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue