Use VAPI and generate template in-app
This commit is contained in:
parent
931f09504d
commit
eae628758c
|
@ -16,6 +16,8 @@ CUSTOM_VAPIS
|
||||||
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
|
${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi
|
||||||
${CMAKE_BINARY_DIR}/exports/dino.vapi
|
${CMAKE_BINARY_DIR}/exports/dino.vapi
|
||||||
${CMAKE_BINARY_DIR}/exports/qlite.vapi
|
${CMAKE_BINARY_DIR}/exports/qlite.vapi
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vapi/DinoWinToastLib.vapi
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vapi/DinoWinToastTemplate.vapi
|
||||||
PACKAGES
|
PACKAGES
|
||||||
${WINDOWS_NOTIFICATION_PACKAGES}
|
${WINDOWS_NOTIFICATION_PACKAGES}
|
||||||
)
|
)
|
||||||
|
@ -29,8 +31,26 @@ COMMENT
|
||||||
Copy header file DinoWinToastLib.h
|
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_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)
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
set(WINTOASTLIB "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib_AMD64.lib")
|
set(WINTOASTLIB "${CMAKE_CURRENT_SOURCE_DIR}/src/DinoWinToastLib_AMD64.lib")
|
||||||
|
|
11
plugins/windows-notification/src/DinoWinToastDllExport.h
Normal file
11
plugins/windows-notification/src/DinoWinToastDllExport.h
Normal file
|
@ -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
|
|
@ -1,27 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef _WIN32
|
#include "DinoWinToastDllExport.h"
|
||||||
#ifdef DINOWINTOASTLIB_EXPORTS
|
#include "DinoWinToastTemplate.h"
|
||||||
#define DINOWINTOASTLIB_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define DINOWINTOASTLIB_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define DINOWINTOASTLIB_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
int DINOWINTOASTLIB_API dinoWinToastLibInit();
|
typedef void(*dinoWinToastLibNotificationCallback)(int conv_id, void* userdata);
|
||||||
#ifdef __cplusplus
|
DINOWINTOASTLIB_API int dinoWinToastLibInit();
|
||||||
} // extern "C"
|
DINOWINTOASTLIB_API int dinoWinToastLibShowMessage(dino_wintoasttemplate templ, int conv_id, dinoWinToastLibNotificationCallback click_callback, void* callback_target);
|
||||||
#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);
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
Binary file not shown.
Binary file not shown.
54
plugins/windows-notification/src/DinoWinToastTemplate.h
Normal file
54
plugins/windows-notification/src/DinoWinToastTemplate.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#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
|
|
@ -1,23 +1,26 @@
|
||||||
|
using DinoWinToast;
|
||||||
|
|
||||||
namespace Dino.Plugins.WindowsNotification {
|
namespace Dino.Plugins.WindowsNotification {
|
||||||
public class WinToast {
|
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 bool valid { get; private set; }
|
||||||
|
|
||||||
public WinToast() {
|
public WinToast() {
|
||||||
valid = DinoWinToastLibInit() == 0;
|
valid = Init() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool show_message(string sender, string message, string? image_path, int conv_id, NotificationCallback callback) {
|
public bool show_message(string sender, string message, string? image_path, int conv_id, NotificationCallback callback) {
|
||||||
if (valid) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
13
plugins/windows-notification/vapi/DinoWinToastLib.vapi
Normal file
13
plugins/windows-notification/vapi/DinoWinToastLib.vapi
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
65
plugins/windows-notification/vapi/DinoWinToastTemplate.vapi
Normal file
65
plugins/windows-notification/vapi/DinoWinToastTemplate.vapi
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue