2020-10-24 22:05:35 +00:00
|
|
|
using Gee;
|
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
namespace Dino.Plugins.WindowsNotification {
|
|
|
|
public class Plugin : RootInterface, Object {
|
|
|
|
|
|
|
|
public Dino.Application app;
|
|
|
|
|
|
|
|
[CCode (has_target = false)]
|
|
|
|
private delegate void notification_callback(void* conv);
|
|
|
|
|
2020-10-24 22:30:57 +00:00
|
|
|
[CCode (cname = "load_library", cheader_filename = "wintoast.h")]
|
|
|
|
private static extern int load_library();
|
2020-10-24 22:05:35 +00:00
|
|
|
|
2020-10-24 22:30:57 +00:00
|
|
|
[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();
|
2020-10-24 22:05:35 +00:00
|
|
|
|
|
|
|
[CCode (cname = "show_message", cheader_filename = "wintoast.h")]
|
|
|
|
private static extern int show_message(char* sender, char* message, char* imagePath, char* protocolName, void *conv);
|
|
|
|
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registered(Dino.Application app) {
|
|
|
|
this.app = app;
|
2020-10-24 22:30:57 +00:00
|
|
|
if (load_library() != 1 ||
|
|
|
|
init_library(onclick_callback) != 1) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-24 22:05:35 +00:00
|
|
|
|
|
|
|
app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((item, conversation) => {
|
|
|
|
if (item.type_ == "message") {
|
|
|
|
var message_item = (MessageItem)item;
|
|
|
|
var message = message_item.message.body;
|
|
|
|
var sender = conversation.nickname != null ? conversation.nickname : conversation.counterpart.to_string();
|
2020-10-24 23:23:15 +00:00
|
|
|
var avatar = null;
|
|
|
|
if (show_message(sender, message, avatar, null, this) != 0) {
|
2020-10-24 22:30:57 +00:00
|
|
|
stderr.printf("Error sending notification.");
|
|
|
|
};
|
2020-10-24 22:05:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void shutdown() {
|
2020-10-24 22:30:57 +00:00
|
|
|
uninit_library();
|
2020-10-24 22:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|