From eae628758c1ba343ecd72eea979c81daafd404e6 Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Wed, 25 Nov 2020 18:55:33 -0300 Subject: [PATCH] Use VAPI and generate template in-app --- plugins/windows-notification/CMakeLists.txt | 22 +++++- .../src/DinoWinToastDllExport.h | 11 +++ .../src/DinoWinToastLib.h | 23 ++----- .../src/DinoWinToastLib_AMD64.lib | Bin 2196 -> 5186 bytes .../src/DinoWinToastLib_x86.lib | Bin 2198 -> 5238 bytes .../src/DinoWinToastTemplate.h | 54 +++++++++++++++ .../windows-notification/src/wintoast.vala | 25 ++++--- .../vapi/DinoWinToastLib.vapi | 13 ++++ .../vapi/DinoWinToastTemplate.vapi | 65 ++++++++++++++++++ 9 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 plugins/windows-notification/src/DinoWinToastDllExport.h create mode 100644 plugins/windows-notification/src/DinoWinToastTemplate.h create mode 100644 plugins/windows-notification/vapi/DinoWinToastLib.vapi create mode 100644 plugins/windows-notification/vapi/DinoWinToastTemplate.vapi diff --git a/plugins/windows-notification/CMakeLists.txt b/plugins/windows-notification/CMakeLists.txt index acaa36f0..83b94dff 100644 --- a/plugins/windows-notification/CMakeLists.txt +++ b/plugins/windows-notification/CMakeLists.txt @@ -16,6 +16,8 @@ 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/DinoWinToastLib.vapi + ${CMAKE_CURRENT_SOURCE_DIR}/vapi/DinoWinToastTemplate.vapi PACKAGES ${WINDOWS_NOTIFICATION_PACKAGES} ) @@ -29,8 +31,26 @@ COMMENT Copy header file DinoWinToastLib.h ) +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/DinoWinToastTemplate.h" +COMMAND + cp "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastTemplate.h" "${CMAKE_BINARY_DIR}/exports/DinoWinToastTemplate.h" +DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastTemplate.h" +COMMENT + Copy header file DinoWinToastTemplate.h +) + +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/DinoWinToastDllExport.h" +COMMAND + cp "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastDllExport.h" "${CMAKE_BINARY_DIR}/exports/DinoWinToastDllExport.h" +DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastDllExport.h" +COMMENT + Copy header file DinoWinToastDllExport.h +) + add_definitions(${VALA_CFLAGS}) -add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} ${CMAKE_BINARY_DIR}/exports/DinoWinToastLib.h) +add_library(windows-notification SHARED ${WINDOWS_NOTIFICATION_VALA_C} ${CMAKE_BINARY_DIR}/exports/DinoWinToastLib.h ${CMAKE_BINARY_DIR}/exports/DinoWinToastTemplate.h ${CMAKE_BINARY_DIR}/exports/DinoWinToastDllExport.h) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(WINTOASTLIB "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib_AMD64.lib") diff --git a/plugins/windows-notification/src/DinoWinToastDllExport.h b/plugins/windows-notification/src/DinoWinToastDllExport.h new file mode 100644 index 00000000..ee777aaa --- /dev/null +++ b/plugins/windows-notification/src/DinoWinToastDllExport.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef _WIN32 +#ifdef DINOWINTOASTLIB_EXPORTS +#define DINOWINTOASTLIB_API __declspec(dllexport) +#else +#define DINOWINTOASTLIB_API __declspec(dllimport) +#endif +#else +#define DINOWINTOASTLIB_API +#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastLib.h b/plugins/windows-notification/src/DinoWinToastLib.h index b0fe9ace..69723666 100644 --- a/plugins/windows-notification/src/DinoWinToastLib.h +++ b/plugins/windows-notification/src/DinoWinToastLib.h @@ -1,27 +1,14 @@ #pragma once -#ifdef _WIN32 -#ifdef DINOWINTOASTLIB_EXPORTS -#define DINOWINTOASTLIB_API __declspec(dllexport) -#else -#define DINOWINTOASTLIB_API __declspec(dllimport) -#endif -#else -#define DINOWINTOASTLIB_API -#endif +#include "DinoWinToastDllExport.h" +#include "DinoWinToastTemplate.h" #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); + typedef void(*dinoWinToastLibNotificationCallback)(int conv_id, void* userdata); + DINOWINTOASTLIB_API int dinoWinToastLibInit(); + DINOWINTOASTLIB_API int dinoWinToastLibShowMessage(dino_wintoasttemplate templ, int conv_id, dinoWinToastLibNotificationCallback click_callback, void* callback_target); #ifdef __cplusplus } // extern "C" #endif \ No newline at end of file diff --git a/plugins/windows-notification/src/DinoWinToastLib_AMD64.lib b/plugins/windows-notification/src/DinoWinToastLib_AMD64.lib index bca01f66b55aa1414463d08817c5bd87ebd9c66d..c508e807a64cfa9d699c0eba5631c65dea718217 100644 GIT binary patch literal 5186 zcmcIoO>7%Q6n?gYlQ=(hlByCEBqIe;1mwqwoge|Sse`cU{3vnN<9d_bHY+7w%ibvE zL=RE90LPw6g-|b4sstQ3LF`!YL|n|EGoDF8SRFnA7Ns0J{62VnGuD+Ab~ zjNfx*5?hq9aYxSJQj+w6BV)I59AzTw$|1HWXK@i)5`=Vey#w2GG1G&c9hR8_z39JuhvIu*n0($}u3)^@NH z>~FPILTr_HF@EH>e3cMe^pWoy`i>Ti%U6-v()5iT}bYMP18EP0Pv zh#Srg0@Q{8?hFIm7zG$Wxrh8Qi84Os5XeCq;5NQzCjbsn4sc--$B>pF261=}`d|=7 zk!w;g07K9ZNf?Ha!0`mKz*BIHe^?wPb)-Bu!;_1@^mOocmkZr`OtzCCpTg8RQs_pt zn{?@xkT{|Y+4_HG7w0Pxne+am%R%Nj@jUaHcs4k{1bz~mAVtnYawR!Kd0q)L!ucam z$M-~_icepmclLA#$%IueSyskmYN=BDO+TgW?7*})@6l!snVNZHz;hGyA8yCs~L-(obW4g3DPtPJAwj$4S$=B z*dOcc=jzOp4lV*uC+CmQ_yziLAF>WmbbHjqVH1C!is(ZFGZi(GvbjYrlH%~|r`j(+ z+F%K?IFdAH%KPOaX^st2gxqHxx1~sWrV-MOzh6QyfyH{%)0>;ga;KMot6zNn_z`a4 zIA45vl03|@1EV~qJmjAO6j&b4vvJbmf>)GU;pfcZtwva4zIKn!HAqCf*AcedH=6PL@_8s!IiH) o!6ERJ5XyG*@&J`hPUk7-^e|C>_Y|tiY_cqGHB6N@$e@$F=8OO{Za5GC diff --git a/plugins/windows-notification/src/DinoWinToastLib_x86.lib b/plugins/windows-notification/src/DinoWinToastLib_x86.lib index 27e6a12a3ef22250ebcee14a62a41e8b3743abcd..d9a35cbb82ebd46e13b6f9e3493bbf743866fb35 100644 GIT binary patch literal 5238 zcmcInO>7%Q6n<;BapHu;Nh(!pK^Un()0V__{gWb8*@+Wj)%j843T_)GyJ=Q(yso{G z3m0yjIP}ybcPdpXQg2*ZAtb6s6$pU@O1YvSQ2_@|Nael#v1jAiSub@*dOJHaZ{B?K z{`Tz~?^POGJ6EDJad&&?qI>L&686i*M0VDC-G~CfX@H?cfZU9%-M46bALo%Kw{3ccJ<`}ci()C{OUZI^X?10-EEg8m=hup><&`zL zpw;vbv|3rOG>wwB39`I=tyJn}ginreT72dAuPtAd3;A*$cWS$JSytQv*LU>RlGq1)p>6Jwu(Ep7Ry|jBU7UWB>CUSaV@F^P z^TrmBkF?@0`jd||hQ~)5U3F1YtBL>{!y}TWs7<4xf8-^oy)2SZQ(Ip9X(@QdnQdpB zF-$p&Ljbpi0iKKi+!+N(ARSBql#%Af0nQ=Q{TRSLzHd(gJVUyNb19s|bOjQG;5ZzE zAsB@*h{7NYLj(q31YYr+4`X(Cf!xDSEl2YJlg3L!)=Qi4Nlhm>)lzDth7V zDSUd)RBRUYIsJc!8)G(Zx_8-03@vLNDkHscE+PS#ptE}!Jpv5==2 z);69@j8!~&I;qX~8$WX-`S?{kNvG_IZ$u03!eCmdR$->SZq-D7^3ut)T}N$1OHvsA zxpCs~v;>%g%qC4M>gL|{Gwaq6polM@IRm@TL2PbXQz}N~Oww68fiFKI9oiFN>~oNK zVDn|{X&}A`p6Bq`xeE@tNGaA&Bl4<*+h@M%J zLU8x5lixiw!4hQPdXi!;bsmf-U2#20F;*kKpPhl-zZ5O^qS-eQfUkoF)o`Z$A4&g- z6vQRz^Mg}|Q|4_4tpf4rr<0cp0!K#12@H%3=j8R)(?n1~DA-#z56f zU(TORcAtOY-?#p_g6ALiKA%%E@!$mZ3yxo&|DyHVyNG5$jD{)8`hq0Wt(WiTzy4_! zkwpBFn5AD|a5%*f6Df;f^7!u-OYS{iD;aKL+ qkLMqgW#~`U%w65N13k7=DD!{>_Eip!NNMm_!Z9qw(J97xIQ|3MKa_j` delta 265 zcmeySF->rSg^rQ2nF0hPa4|42urn|)ZDL?x`NP1#X2rn3AqK(hbAVEFCL40cO%`Iz zW71cce1S*b!~~(06{vR;69dB^76t|@HU +#include "DinoWinToastDllExport.h" + +#ifdef __cplusplus +extern "C" { +#endif + typedef void* dino_wintoasttemplate; + + typedef enum { + System, + Short, + Long + } dino_wintoasttemplate_duration; + + typedef enum { + Default = 0, + Silent = 1, + Loop = 2 + } dino_wintoasttemplate_audiooption; + + typedef enum { + FirstLine = 0, + SecondLine, + ThirdLine + } dino_wintoasttemplate_textfield; + + typedef enum { + ImageAndText01 = 0, + ImageAndText02, + ImageAndText03, + ImageAndText04, + Text01, + Text02, + Text03, + Text04, + WinToastTemplateTypeCount + } dino_wintoasttemplate_wintoasttemplatetype; + + DINOWINTOASTLIB_API dino_wintoasttemplate dino_wintoasttemplate_new(dino_wintoasttemplate_wintoasttemplatetype templ); + DINOWINTOASTLIB_API void dino_wintoasttemplate_destroy(dino_wintoasttemplate templ); + + DINOWINTOASTLIB_API void dino_wintoasttemplate_setTextField(dino_wintoasttemplate templ, const char* txt, dino_wintoasttemplate_textfield pos); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setImagePath(dino_wintoasttemplate templ, const char* imgPath); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setAudioPath(dino_wintoasttemplate templ, const char* audioPath); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setAttributionText(dino_wintoasttemplate templ, const char* attributionText); + DINOWINTOASTLIB_API void dino_wintoasttemplate_addAction(dino_wintoasttemplate templ, const char* label); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setAudioOption(dino_wintoasttemplate templ, dino_wintoasttemplate_audiooption audioOption); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setDuration(dino_wintoasttemplate templ, dino_wintoasttemplate_duration duration); + DINOWINTOASTLIB_API void dino_wintoasttemplate_setExpiration(dino_wintoasttemplate templ, int64_t millisecondsFromNow); +#ifdef __cplusplus +} // extern C +#endif \ No newline at end of file diff --git a/plugins/windows-notification/src/wintoast.vala b/plugins/windows-notification/src/wintoast.vala index 73c44d70..a4e1b622 100644 --- a/plugins/windows-notification/src/wintoast.vala +++ b/plugins/windows-notification/src/wintoast.vala @@ -1,23 +1,26 @@ +using DinoWinToast; + namespace Dino.Plugins.WindowsNotification { public class WinToast { - [CCode (has_target = true)] - public delegate void NotificationCallback(int conv_id); - - [CCode (cname = "dinoWinToastLibInit", cheader_filename = "DinoWinToastLib.h")] - private static extern int DinoWinToastLibInit(); - - [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 = DinoWinToastLibInit() == 0; + valid = Init() == 0; } public bool show_message(string sender, string message, string? image_path, int conv_id, NotificationCallback callback) { if (valid) { - return DinoWinToastLibShowMessage(sender, message, image_path, conv_id, callback) == 0; + DinoWinToastTemplate template; + if (image_path != null) { + template = new DinoWinToastTemplate(TemplateType.ImageAndText02); + template.setImagePath(image_path); + } else { + template = new DinoWinToastTemplate(TemplateType.Text02); + } + + template.setTextField(sender, TextField.FirstLine); + template.setTextField(message, TextField.SecondLine); + return DinoWinToast.ShowMessage(template, conv_id, callback) == 0; } return false; } diff --git a/plugins/windows-notification/vapi/DinoWinToastLib.vapi b/plugins/windows-notification/vapi/DinoWinToastLib.vapi new file mode 100644 index 00000000..a4c92057 --- /dev/null +++ b/plugins/windows-notification/vapi/DinoWinToastLib.vapi @@ -0,0 +1,13 @@ +[CCode (cheader_filename = "DinoWinToastLib.h")] +namespace DinoWinToast { + + [CCode (cname = "dinoWinToastLibNotificationCallback", has_target = true)] + public delegate void NotificationCallback(int conv_id); + + [CCode (cname = "dinoWinToastLibInit")] + public int Init(); + + [CCode (cname = "dinoWinToastLibShowMessage")] + public int ShowMessage(DinoWinToastTemplate templ, int conv_id, NotificationCallback callback); +} + diff --git a/plugins/windows-notification/vapi/DinoWinToastTemplate.vapi b/plugins/windows-notification/vapi/DinoWinToastTemplate.vapi new file mode 100644 index 00000000..59fc4740 --- /dev/null +++ b/plugins/windows-notification/vapi/DinoWinToastTemplate.vapi @@ -0,0 +1,65 @@ +[CCode (cheader_filename = "DinoWinToastTemplate.h")] +namespace DinoWinToast { + [CCode (cname = "dino_wintoasttemplate_duration", cprefix = "")] + public enum Duration { + System, + Short, + Long + } + + [CCode (cname = "dino_wintoasttemplate_audiooption", cprefix = "")] + public enum AudioOption { + Default, + Silent, + Loop + } + + [CCode (cname = "dino_wintoasttemplate_textfield", cprefix = "")] + public enum TextField { + FirstLine, + SecondLine, + ThirdLine + } + + [CCode (cname = "dino_wintoasttemplate_wintoasttemplatetype", cprefix = "")] + public enum TemplateType { + ImageAndText01, + ImageAndText02, + ImageAndText03, + ImageAndText04, + Text01, + Text02, + Text03, + Text04, + WinToastTemplateTypeCount + } + + [CCode (cname="dino_wintoasttemplate", free_function = "dino_wintoasttemplate_destroy")] + [Compact] + public class DinoWinToastTemplate { + [CCode (cname = "dino_wintoasttemplate_new")] + public DinoWinToastTemplate(TemplateType type = TemplateType.ImageAndText02); + + [CCode (cname = "dino_wintoasttemplate_setTextField")] + public void setTextField(char* txt, TextField pos); + + [CCode (cname = "dino_wintoasttemplate_setImagePath")] + public void setImagePath(char* imgPath); + + [CCode (cname = "dino_wintoasttemplate_setAttributionText")] + public void setAttributionText(char* attributionText); + + [CCode (cname = "dino_wintoasttemplate_addAction")] + public void addAction(char* label); + + [CCode (cname = "dino_wintoasttemplate_setAudioOption")] + public void setAudioOption(AudioOption option); + + [CCode (cname = "dino_wintoasttemplate_setDuration")] + public void setDuration(Duration duration); + + [CCode (cname = "dino_wintoasttemplate_setExpiration")] + public void setExpiration(int64 millisecondsFromNow); + } +} +