Initial notification support

This commit is contained in:
LAGonauta 2020-10-24 19:05:35 -03:00
parent 3dd19fad71
commit 1d4bb774a5
7 changed files with 183 additions and 1 deletions

View file

@ -13,7 +13,7 @@ endif ()
# Prepare Plugins
set(DEFAULT_PLUGINS omemo;openpgp;http-files;ice;rtp)
if (WIN32)
set(DEFAULT_PLUGINS ${DEFAULT_PLUGINS};win32-fonts)
set(DEFAULT_PLUGINS ${DEFAULT_PLUGINS};win32-fonts;windows-notification)
endif (WIN32)
foreach (plugin ${DEFAULT_PLUGINS})
if ("$CACHE{DINO_PLUGIN_ENABLED_${plugin}}" STREQUAL "")

View file

@ -28,6 +28,10 @@ if(DINO_PLUGIN_ENABLED_notification-sound)
add_subdirectory(notification-sound)
endif(DINO_PLUGIN_ENABLED_notification-sound)
if(DINO_PLUGIN_ENABLED_windows-notification)
add_subdirectory(windows-notification)
endif(DINO_PLUGIN_ENABLED_windows-notification)
if(DINO_PLUGIN_ENABLED_win32-fonts)
add_subdirectory(win32-fonts)
endif(DINO_PLUGIN_ENABLED_win32-fonts)

View file

@ -0,0 +1,53 @@
find_packages(WINDOWS_NOTIFICATION_PACKAGES REQUIRED
Gee
GLib
GModule
GObject
GTK3
)
vala_precompile(WINDOWS_NOTIFICATION_VALA_C
SOURCES
src/plugin.vala
src/register_plugin.vala
CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
${CMAKE_BINARY_DIR}/exports/dino.vapi
${CMAKE_BINARY_DIR}/exports/qlite.vapi
#${CMAKE_CURRENT_SOURCE_DIR}/vapi/openal.vapi
PACKAGES
${WINDOWS_NOTIFICATION_PACKAGES}
)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/wintoast.h
COMMAND
cp ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.h ${CMAKE_BINARY_DIR}/exports/wintoast.h
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.h
COMMENT
Copy header file wintoast.h
)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/exports/wintoast.c
COMMAND
cp ${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.c ${CMAKE_BINARY_DIR}/exports/wintoast.c
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/src/wintoast.c
COMMENT
Copy header file wintoast.c
)
add_custom_target(wintoast
DEPENDS
${CMAKE_BINARY_DIR}/exports/wintoast.h
${CMAKE_BINARY_DIR}/exports/wintoast.c
)
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_dependencies(windows-notification wintoast)
set_target_properties(windows-notification PROPERTIES PREFIX "")
set_target_properties(windows-notification PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins/)
install(TARGETS windows-notification ${PLUGIN_INSTALL})

View file

@ -0,0 +1,65 @@
using Gee;
using Dino.Entities;
namespace Dino.Plugins.WindowsNotification {
public class Plugin : RootInterface, Object {
public Dino.Application app;
// private class ConvData {
// public int ReadUpToId;
// public int Timestamp;
// }
// private int interval = 0;
// private HashMap<int, ConvData> conv_data = new HashMap<int, ConvData>();
[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 = "uninit", cheader_filename = "wintoast.h")]
private static extern void uninit();
[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;
init(onclick_callback);
app.stream_interactor.get_module(NotificationEvents.IDENTITY).notify_content_item.connect((item, conversation) => {
if (item.type_ == "message") {
// key: conversation.id value: { conversation.read_up_to.id, last-time-notification-send }
// var conv = conv_data.get(conversation.id);
// if (conv.ReadUpToId == conversation.read_up_to.id) {
// if (now < conv.Timestamp + interval) {
// return;
// }
// }
var message_item = (MessageItem)item;
//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);
}
});
}
public void shutdown() {
uninit();
}
}
}

View file

@ -0,0 +1,3 @@
public Type register_plugin(Module module) {
return typeof (Dino.Plugins.WindowsNotification.Plugin);
}

View file

@ -0,0 +1,49 @@
#include <stdio.h>
#include <libloaderapi.h>
#include "wintoast.h"
void(*callback)(void*) = 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;
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_init) {
library_init(notification_click_callback);
}
}
void uninit() {
if (library_handle) {
FreeLibrary(library_handle);
}
}
void 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);
}
}

View file

@ -0,0 +1,8 @@
#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);
#endif