模块的C++代码 node_gtknotify.cc

#include

#include

#include

#include

#include

using namespace v8;

class GtkNotify : node::ObjectWrap{

public:

GtkNotify(){}

~GtkNotify(){}

std::string title;

std::string icon;

static Persistent persistent_function_template;

static void Init(Handle target){

HandleScope scope;

Local local_function_template = FunctionTemplate::New(New);

GtkNotify::persistent_function_template = Persistent::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 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 Send(const Arguments& args){

HandleScope scope;

GtkNotify* instance = node::ObjectWrap::Unwrap(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 GetTitle(Local property, const AccessorInfo& info){

GtkNotify* instance = node::ObjectWrap::Unwrap(info.Holder());

return String::New(instance->title.c_str());

}

static Handle GetIcon(Local property, const AccessorInfo& info){

GtkNotify* instance = node::ObjectWrap::Unwrap(info.Holder());

return String::New(instance->icon.c_str());

}

static void SetTitle(Local property, Local value, const AccessorInfo& info) {

GtkNotify* instance = node::ObjectWrap::Unwrap(info.Holder());

String::Utf8Value v8str(value);

instance->title = *v8str;

}

static void SetIcon(Local property, Local value, const AccessorInfo& info) {

GtkNotify* instance = node::ObjectWrap::Unwrap(info.Holder());

String::Utf8Value v8str(value);

instance->icon = *v8str;

}

};

Persistent GtkNotify::persistent_function_template;

extern "C"{

static void init(Handle 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

执行效果

html弹窗代码y\/n,Nodejs扩展,实现消息弹窗(示例代码)相关推荐

  1. python qq自动发消息软件_Python之qq自动发消息的示例代码

    准备:pip install win32gui 可能遇到的麻烦: No module named 'win32gui' 的解决方法(踩坑之旅) 源码: import win32gui import w ...

  2. 企业微信机器人脚本python_python实现企业微信定时发送文本消息的示例代码

    企业微信定时发送文本消息 使用工具:企业微信机器人+python可执行文件+计算机管理中的任务计划程序 第一步:创建群机器人 选择群聊,单击鼠标右键,添加群机器人. 建立群机器人后,右键查看机器人,如 ...

  3. 父爱动画代码python_pygame用blit()实现动画效果的示例代码

    pygame的的实现动画的方法有很多,但是都是围绕着表面进行的,也就是说实现动画的方式不同,但是本质其实都是对表面的不同处理方式而已. 原理其实很简单,有点像我们做地铁的时候隧道里的广告一样.我们设置 ...

  4. python代码翻译-用python实现百度翻译的示例代码

    用python实现百度翻译,分享给大家,具体如下: 首先,需要简单的了解一下爬虫,尽可能简单快速的上手,其次,需要了解的是百度的API的接口,搞定这个之后,最后,按照官方给出的demo,然后写自己的一 ...

  5. python基础代码事例-数据科学Python基础(附示例代码和练习题目)

    翻译 | AI科技大本营 参与 | 王珂凝 审校 | reason_W [AI科技大本营导读]Python的强大和灵活相信已经毋庸置疑了.那么数据科学中,我们又需要掌握哪些基础知识点才能满足使用需求呢 ...

  6. python简单目标检测代码_Python Opencv实现单目标检测的示例代码

    一 简介 目标检测即为在图像中找到自己感兴趣的部分,将其分割出来进行下一步操作,可避免背景的干扰.以下介绍几种基于opencv的单目标检测算法,算法总体思想先尽量将目标区域的像素值全置为1,背景区域全 ...

  7. udp服务器php代码例子,Java客户端PHP服务器UDP穿孔示例代码

    我正在一个需要pe2p服务器的项目中工作,但是我还没有找到任何Java客户端php服务器示例代码.我了解udp打孔工作原理的概念,但是我无法在代码中工作. 我尝试过的 TheSocket.java p ...

  8. python代码翻译器-用python实现百度翻译的示例代码

    用python实现百度翻译,分享给大家,具体如下: 首先,需要简单的了解一下爬虫,尽可能简单快速的上手,其次,需要了解的是百度的API的接口,搞定这个之后,最后,按照官方给出的demo,然后写自己的一 ...

  9. c语言图形学画扇形代码,利用CSS绘制任意角度的扇形示例代码

    前言 扇形制作原理,底部一个纯色原形,里面2个相同颜色的半圆,可以是白色,内部半圆按一定角度变化,就可以产生出扇形效果 效果图 示例代码: 扇形绘制 } .sx1{ position: absolut ...

最新文章

  1. 网络工程师技能图谱 | 网络技术的理论知识和操作技能
  2. CopyOnWrite容器
  3. 如何正确刷题计算机考研,2020考研:4个方法教你数学如何正确刷题!
  4. 创建WebSocket服务器
  5. Search Engine —— Regular Expression(Spider)
  6. 诡异的select *语句报错事件
  7. 2020年,朋友圈的正确打开方式!
  8. 【转】UML基础: 第 2 部分 - 对象图 (Object Diagram)
  9. [单选题]?php echo ceil(2.1/0.7); ?
  10. C++新特性探究(三):=default、=delete
  11. 排序专题之C++中的sort函数调用
  12. 实习笔记(数据库相关)-2014
  13. 深度学习自学(二十八):Altas人脸SDK实现之-回调函数
  14. 计算机导论以python为舟_计算机科学导论
  15. Firefox的下载处理器:FlashGot v1.0 Final颁发
  16. Mysql 新增分区,删除分区,合并分区
  17. 如何注册微信个人公众号,教程来啦!怎样注册微信个人公众订阅号
  18. 支持多线程编程的Web Workers
  19. [5.1] 架构与思想:Phal Api核心设计和思想解读
  20. Docker_学习笔记

热门文章

  1. 与时俱进:在JAX-RS API中采用OpenAPI v3.0.0
  2. neo4j cypher_优化Neo4j Cypher查询
  3. Spring Boot –使用执行器端点在运行时配置日志级别
  4. 使用jstat的JVM统计信息
  5. antlr_ANTLR –语义谓词
  6. HotSpot的-XshowSettings标志的简单性和价值
  7. 为什么应始终将连接池与Oracle XE一起使用
  8. 将非事务性资源绑定到JTA事务中的几种模式
  9. 在Spring中使用Netflix Hystrix批注
  10. 自定义Cassandra数据类型