脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-Nodejs扩展,实现消息弹窗,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
模块的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
static void Init(Handle
HandleScope scope;
Local
GtkNotify::persistent_function_template = Persistent
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
HandleScope scope;
GtkNotify* instance = new GtkNotify();
instance->title = Node.js;
instance->icon = terminal;
instance->Wrap(args.This());
return args.This();
}
static Handle
HandleScope scope;
GtkNotify* instance = node::ObjectWrap::Unwrap
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
GtkNotify* instance = node::ObjectWrap::Unwrap
return String::New(instance->title.c_str());
}
static Handle
GtkNotify* instance = node::ObjectWrap::Unwrap
return String::New(instance->icon.c_str());
}
static void SetTitle(Local
GtkNotify* instance = node::ObjectWrap::Unwrap
String::Utf8Value v8str(value);
instance->title = *v8str;
}
static void SetIcon(Local
GtkNotify* instance = node::ObjectWrap::Unwrap
String::Utf8Value v8str(value);
instance->icon = *v8str;
}
};
Persistent
extern C{
static void init(Handle
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
运行效果
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-Nodejs扩展,实现消息弹窗全部内容,希望文章能够帮你解决javascript代码实例教程-Nodejs扩展,实现消息弹窗所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。