Nodejs extension to implement message pop-up window

Source: Internet
Author: User

Nodejs extension to implement message pop-up window

 

 

Module C ++ code node_gtknotify.cc

# Include

# Include

# Include

# Include

# Include

 

Using namespace v8;

 

Class GtkNotify: node: ObjectWrap {

Public:

Gtknotted (){}

~ Gtknotted (){}

 

Std: string title;

Std: string icon;

 

Static Persistent Persistent_function_template;

 

Static void Init (HandleTarget ){

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;

Gtknotted * instance = new gtknotted ();

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]);

// Pop-up message box

Y: init (Basic );

Condition Y: 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 (HandleTarget ){

Gtknotted: Init (target );

}

NODE_MODULE (Node_gtknotify, Init );

}

 

Node-gyp configuration file binding. gyp

{

Targets :[

{

Target_name:Node_gtknotify,

Sources: [src/node_gtknotify.cc]

}

]

}

 

Directory structure

 

Run commands

Node-gyp configure

Node-gyp build

 

If the corresponding Library/path is not installed, the header file cannot be found;

Clumsy solution, add in Makefile under build

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/include-I/usr/include/gtkmm-3.0-I/usr /include/atk-1.0-I/usr/include/libnotifymm-1.0

 

The above libraries are installed according to the error prompt

 

Javascript test code

Var require y = require (./Build/Release/node_gtknotted);

Var notification = new every Y. notification ();

Notification. title = Notification title;

Notification. icon = emblem-default; // see/usr/share/icons/gnome/16x16

Notification. send (hello, world );

 

Note: The ** symbol cannot be found because the corresponding shared link library is not added.

 

 

Solution: In build/node_gtknotify.target.mk, add

LIBS: =-lglibmm-2.4-lnotify-lnotifymm-1.0

 

Running Effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.