Permalink
Browse files

Merge pull request #4 from freehaha/gyp

use node-gyp and libnotify
  • Loading branch information...
olalonde committed Feb 15, 2015
2 parents 9757ac2 + 895dfe7 commit 1e2e1ae99e32f2d4ae652f6ebce1fda116437704
Showing with 53 additions and 12 deletions.
  1. +13 −5 README.md
  2. +14 −0 binding.gyp
  3. +2 −2 package.json
  4. +24 −5 src/node_gtknotify.cpp
View
@@ -5,25 +5,33 @@ This is a follow up to [How to roll out your own Javascript API with V8](http://
## Install ##
-Dependencies(Ubuntu 11.04):
+Dependencies(Debian, Ubuntu):
- sudo apt-get install libnotifymm-dev
+ sudo apt-get install libnotify-dev
Using npm:
npm install notify
Manually:
- node-waf configure && node-waf build
+ node-gyp configure && node-gyp build
## Usage ##
- var notify = require("notify"); // or "../build/default/gtknotify.node" if you build manually
+ var notify = require("notify"); // or "../build/Release/gtknotify.node" if you build manually
var notification = new notify.notification();
notification.title = "Notification title";
notification.icon = "emblem-default"; // see /usr/share/icons/gnome/16x16
- notification.send("Notification message");
+ notification.send("Notification message"); // using libnotify's default timeout
+
+To send notification with a timeout:
+
+ notification.send("Notification message", 3000); // 3 sec timeout
+ // or
+ notification.send("Notification message", 0); // lasts forever
+ notification.close(); // closes it
+
## References ##
View
@@ -0,0 +1,14 @@
+{
+ "targets": [
+ {
+ "target_name": "gtknotify",
+ "sources": [ "src/node_gtknotify.cpp" ],
+ "include_dirs": [
+ "<!@(pkg-config libnotify --cflags-only-I | sed s/-I//g)"
+ ],
+ "libraries": [
+ "<!@(pkg-config libnotify --libs)"
+ ]
+ }
+ ]
+}
View
@@ -13,8 +13,8 @@
, "url" : "https://github.com/olalonde/node-notify.git"
}
, "scripts" : {
- "preinstall" : "node-waf configure && node-waf build"
+ "preinstall" : "node-gyp configure && node-gyp build"
, "preuninstall" : "rm -rf build/*"
}
- , "main" : "build/default/gtknotify.node"
+ , "main" : "build/Release/gtknotify.node"
}
View
@@ -3,10 +3,10 @@
//
#include <v8.h>
#include <node.h>
+#include <node_object_wrap.h>
// We need those two libraries for the GTK+ notification
#include <string>
-#include <gtkmm.h>
-#include <libnotifymm.h>
+#include <libnotify/notify.h>
/*
@@ -46,6 +46,7 @@ using namespace v8;
class Gtknotify : node::ObjectWrap {
private:
+ NotifyNotification *n;
public:
Gtknotify() {}
~Gtknotify() {}
@@ -88,9 +89,11 @@ class Gtknotify : node::ObjectWrap {
// @Node.js macro to help bind C++ methods to Javascript methods (see https://github.com/joyent/node/blob/v0.2.0/src/node.h#L34)
// Arguments: our constructor function, Javascript method name, C++ method
NODE_SET_PROTOTYPE_METHOD(Gtknotify::persistent_function_template, "send", Send);
+ NODE_SET_PROTOTYPE_METHOD(Gtknotify::persistent_function_template, "close", Close);
// Set the "notification" property to the target and assign it to our constructor function
target->Set(String::NewSymbol("notification"), Gtknotify::persistent_function_template->GetFunction());
+ notify_init("node-notify");
}
// new Notification();
@@ -101,6 +104,7 @@ class Gtknotify : node::ObjectWrap {
// Set some default values
gtknotify_instance->title = "Node.js";
gtknotify_instance->icon = "terminal";
+ gtknotify_instance->n = notify_notification_new(gtknotify_instance->title.c_str(), "", gtknotify_instance->icon.c_str());
// Wrap our C++ object as a Javascript object
gtknotify_instance->Wrap(args.This());
@@ -115,21 +119,36 @@ class Gtknotify : node::ObjectWrap {
// This is a method part of the constructor function's prototype
static v8::Handle<Value> Send(const Arguments& args) {
v8::HandleScope scope;
+ gint timeout = NOTIFY_EXPIRES_DEFAULT;
// Extract C++ object reference from "this" aka args.This() argument
Gtknotify* gtknotify_instance = node::ObjectWrap::Unwrap<Gtknotify>(args.This());
// Convert first argument to V8 String
v8::String::Utf8Value v8str(args[0]);
+ if(args.Length() > 1) {
+ if(!args[1]->IsNumber()) {
+ return v8::Undefined();
+ }
+ timeout = args[1]->ToUint32()->Value();
+ }
// see http://library.gnome.org/devel/libnotify/0.7/NotifyNotification.html
- Notify::init("Basic");
// Args: title, content, icon
- Notify::Notification n(gtknotify_instance->title.c_str(), *v8str, gtknotify_instance->icon.c_str()); // *v8str points to the C string
// Display notification
- n.show();
+ notify_notification_update(gtknotify_instance->n, gtknotify_instance->title.c_str(), *v8str, gtknotify_instance->icon.c_str()); // *v8str points to the C string
+ notify_notification_set_timeout(gtknotify_instance->n, timeout);
+ notify_notification_show(gtknotify_instance->n, NULL);
+ // n.show();
// Return value
return v8::Boolean::New(true);
}
+
+ static v8::Handle<Value> Close(const Arguments& args) {
+ v8::HandleScope scope;
+ Gtknotify* gtknotify_instance = node::ObjectWrap::Unwrap<Gtknotify>(args.This());
+ notify_notification_close(gtknotify_instance->n, NULL);
+ return v8::Undefined();
+ }
// notification.title
static v8::Handle<Value> GetTitle(v8::Local<v8::String> property, const v8::AccessorInfo& info) {

0 comments on commit 1e2e1ae

Please sign in to comment.