Nodejs扩展,实现消息弹窗
參考https://github.com/olalonde/node-notify的实现
模块的C++代码 node_gtknotify.cc
#include <v8.h>
#include <node.h>
#include <string>
#include <gtkmm-3.0/gtkmm.h>
#include <libnotifymm.h>
using namespace v8;
class GtkNotify : node::ObjectWrap{
public:
GtkNotify(){}
~GtkNotify(){}
std::string title;
std::string icon;
static Persistent<FunctionTemplate> persistent_function_template;
static void Init(Handle<Object> target){
HandleScope scope;
Local<FunctionTemplate> local_function_template = FunctionTemplate::New(New);
GtkNotify::persistent_function_template = Persistent<FunctionTemplate>::New(local_function_template);
GtkNotify::persistent_function_template->InstanceTemplate()->SetInternalFieldCount(1);
GtkNotify::persistent_function_template->SetClassName(String::NewSymbol("Notification"));
GtkNotify::persistent_function_template->InstanceTemplate()->SetAccessor(String::New("title"), GetTitle, SetTitle);
GtkNotify::persistent_function_template->InstanceTemplate()->SetAccessor(String::New("icon"), GetIcon, SetIcon);
NODE_SET_PROTOTYPE_METHOD(GtkNotify::persistent_function_template, "send", Send);
target->Set(String::NewSymbol("notification"), GtkNotify::persistent_function_template->GetFunction());
}
static Handle<Value> New(const Arguments& args){
HandleScope scope;
GtkNotify* instance = new GtkNotify();
instance->title = "Node.js";
instance->icon = "terminal";
instance->Wrap(args.This());
return args.This();
}
static Handle<Value> Send(const Arguments& args){
HandleScope scope;
GtkNotify* instance = node::ObjectWrap::Unwrap<GtkNotify>(args.This());
String::Utf8Value v8str(args[0]);
//弹出消息框
Notify::init("Basic");
Notify::Notification n(instance->title.c_str(), *v8str, instance->icon.c_str());
n.show();
return Boolean::New(true);
}
static Handle<Value> GetTitle(Local<String> property, const AccessorInfo& info){
GtkNotify* instance = node::ObjectWrap::Unwrap<GtkNotify>(info.Holder());
return String::New(instance->title.c_str());
}
static Handle<Value> GetIcon(Local<String> property, const AccessorInfo& info){
GtkNotify* instance = node::ObjectWrap::Unwrap<GtkNotify>(info.Holder());
return String::New(instance->icon.c_str());
}
static void SetTitle(Local<String> property, Local<Value> value, const AccessorInfo& info) {
GtkNotify* instance = node::ObjectWrap::Unwrap<GtkNotify>(info.Holder());
String::Utf8Value v8str(value);
instance->title = *v8str;
}
static void SetIcon(Local<String> property, Local<Value> value, const AccessorInfo& info) {
GtkNotify* instance = node::ObjectWrap::Unwrap<GtkNotify>(info.Holder());
String::Utf8Value v8str(value);
instance->icon = *v8str;
}
};
Persistent<FunctionTemplate> GtkNotify::persistent_function_template;
extern "C"{
static void init(Handle<Object> target){
GtkNotify::Init(target);
}
NODE_MODULE(node_gtknotify, init);
}
node-gyp配置文件 binding.gyp
{
"targets": [
{
"target_name": "node_gtknotify",
"sources": [ "src/node_gtknotify.cc" ]
}
]
}
文件夹结构
执行命令
node-gyp configure
node-gyp build
假设没有安装对应的库/路径找不到。中间会出现头文件找不到的错误;
笨拙的解决方法。在build以下的Makefile中加入
CXXFLAGS += -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/giomm-2.4 -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairomm-1.0 -I/usr/include/freetype2 -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/atkmm-1.6 -I/usr/include/atk-1.0 -I/usr/include/libnotifymm-1.0
上述的库是依据错误提示进行安装的
Javascript測试代码
var notify = require("./build/Release/node_gtknotify");
var notification = new notify.notification();
notification.title = "Notification title";
notification.icon = "emblem-default"; // see /usr/share/icons/gnome/16x16
notification.send("hello,world");
注意,执行时可能有错误提示:**符号找不到,这是由于没有加入对应的共享链接库
解决方法:在build/node_gtknotify.target.mk中加入
LIBS := -lglibmm-2.4 -lnotify -lnotifymm-1.0
执行效果
转载于:https://www.cnblogs.com/gccbuaa/p/7252475.html
Nodejs扩展,实现消息弹窗相关推荐
- Qt 实现桌面右下角消息弹窗提示
简单的做了一个类似QQ消息提示的消息弹窗提示的小模块,便于在系统后台程序提示检测的信息,使用Qt开发,设计整体思路是做一个无框架的widget,自己实现标题栏和内容栏,添加了向上移出,自动消隐退出效果 ...
- PyQt5中的QMessageBox消息弹窗使用示例
前言 PyQt是Python语言环境的GUI编程解决方案之一,另外还有PyGTK.wxPython等也较为常用.PyQt作为Qt语言的Python扩展,可以用来方便快速的开发界面应用. PyQt5中的 ...
- 【WPF】对话框/消息弹窗
非模式对话框 需求:弹窗是非模式对话框,即可以多个弹窗弹出,且弹窗后面的窗体可以被操作,不会被锁定. 自定义的窗体Window实现以下步骤: 在C#代码中弹出窗体时,使用 window.Show() ...
- vue实现消息badge 标记_Vue $mount实战之实现消息弹窗组件
之前的项目一直在使用Element-UI框架,element中的Notification.Message组件使用时不需要在html写标签,而是使用js调用.那时就很疑惑,为什么element ui使用 ...
- html qq消息弹窗提醒,能不能让QQ消息不再讨厌 QQ HD mini消息弹窗提醒的优化方案...
随着用户对体验的要求越来越高,手机QQ消息的弹窗似乎对用户有着隐形的骚扰,手机QQ现在已经是一款很成熟的产品了. 但是在使用时,你一定有这样的感觉:不想错过某人的消息,但又有其他的消息在干扰,一遍又一 ...
- 揭秘新推广渠道::利用腾讯文档做QQ消息弹窗
圈内营销大佬推广又搞出了新路子,利用腾讯文档做QQ微信消息弹窗推广,折腾出了一种新的推广方式! 在之前,很多站长估计之前都没有仔细观察注腾讯文档这个产品,都是用来在线编辑文档办公用,很多人没想到是,最 ...
- Vue消息弹窗不重复弹出,只弹出一次
消息弹窗不重复弹出,只弹出一次 文章借鉴:让ElementUI Message消息提示每次只弹出一次 1.在utils里新建一个message.js 文件 /*** 重置message,防止重复点击重 ...
- windows如何实现微信新消息弹窗
在 Windows 上实现微信新消息弹窗可以使用第三方工具,例如 "微信助手" 或 "微信桌面版".这些工具可以帮助您收到微信新消息的弹窗提醒.
- python中的消息弹窗
在写python代码中,经常要弹窗提示一下消息情况,因为有时候我同时用了多个ui框架,比如tkinter,pyqt等,经常找不到合适的弹窗模块.因此梳理了一下几种弹窗方案. 一.采用windows自带 ...
- 纯js消息弹窗组件Message
js消息弹窗组件 文章目录 js消息弹窗组件 1. js部分代码 2.使用方法 3.演示效果 写组件上瘾,今天写一个纯js消息弹窗组件,复制即可使用,css也写在了js之中,用js生成,代码若是存在不 ...
最新文章
- 佳能80d有人脸识别吗_国家地理2020年旅行者最推荐相机Top10,有你喜欢的吗?
- HTML5 file api读取文件的MD5码工具
- centos7.0搭建svn服务器
- C++(3)--编译、gdb调试
- java 项目启动初始化_Spring Boot解决项目启动时初始化资源的方法
- 浅谈音视频网络通信中的延时优化
- dicom传图像故障
- 30+简约和平铺的WordPress复古主题
- Python 爬取必应翻译
- Unity编辑器汉化教程
- 个人项目集 - Oliver Chu
- 代码对比工具Sublime——Sublimerge
- 如何将网页保存为PDF文件
- 深度学习入门学习路线及好课推荐
- oracle创建用户ORA-01045:user lacks CREATE SESSION privilege;logon denied..的问题
- Markdown常用快捷键
- 光栅图形学-中点画线法
- 不积跬步无以至千里,反思
- 树梅派应用38:树莓派 SAKS 扩展板挑战应用 之 PM2.5 指示灯
- Latex 多图片排版--排版代码生成器
热门文章
- Scala集合:reduce(化简)方法使用示例
- Hexo搭建个人博客常用命令
- Python 内建函数 max/min的高级用法
- 8086指令(II)
- GitHub清除commit记录
- 机器人学一些概念2——四元数,D-H 参数
- mqtt服务器性能H3,运用 MQTT-JMeter 插件测试 MQTT 服务器性能
- c语言 宏教程 pdf,C语言之详解_ifdef等宏.pdf
- 小牛照片恢复软件_电脑移动硬盘U盘数据恢复SD卡照片文件软件修复开盘远程维修服务...
- 2.1.1 物理层接口特性、数据通信模型、物理层基本概念(数据、信号、码元 、信源、信道、信宿 、速率、波特、带宽)