Advertisement
Guest User

[GJS] LibNotify example /w GApplication

a guest
Nov 25th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env gjs
  2.  
  3. /*
  4.  * Example showing how to make notifications.
  5.  * The use of Gio.Application is to keep the program alive.
  6.  */
  7.  
  8. const Notify = imports.gi.Notify;
  9. const GLib = imports.gi.GLib;
  10. const Gio = imports.gi.Gio;
  11.  
  12.  
  13. const Lang = imports.lang;
  14.  
  15. Notify.init ("Test app");
  16.  
  17. const Application = new Lang.Class ({
  18.   Name: "TestApp",
  19.   Extends: Gio.Application,
  20.  
  21.   _init : function () {
  22.     this.parent ({
  23.       application_id: "org.gego.test.notify"
  24.     });
  25.   },
  26.  
  27.   vfunc_activate : function () {
  28.     this.n = new Notify.Notification ({"summary" : "Something",
  29.                                  "body" : "What do you want to say?",
  30.                                  "icon-name" :"dialog-warning-symbolic"});
  31.    
  32.     this.n.connect ("closed", Lang.bind (this, function () {
  33.       let r = this.n.get_closed_reason (); // The reason never seem to change.
  34.       print ("close reason: " + r + "\n");
  35.       this.quit ();
  36.     }));
  37.    
  38.     this.n.add_action ("say_hello", "Say Hello", Lang.bind (this, function () {
  39.       print ("Hello\n");
  40.     }));
  41.  
  42.     this.n.add_action ("say_hi", "Say Hi!", Lang.bind (this, function () {
  43.       print ("Hi!\n");
  44.     }));
  45.    
  46.     this.n.show ();
  47.    
  48.     this.hold ();
  49.   }
  50.  
  51. });
  52.  
  53.  
  54. function main (argv) {
  55.   var app = new Application ();
  56.   return app.run(argv);
  57. }
  58.  
  59. main (ARGV);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement