Advertisement
gbc921

applet.js

Mar 13th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. //System Shutdown and Restart Applet by Shelley
  2. // Edited to use systemd to suspend, restart, hibernate and poweroff by Gabriel (gbc921)
  3.  
  4. const Cinnamon = imports.gi.Cinnamon;
  5. const Applet = imports.ui.applet;
  6. const Main = imports.ui.main;
  7. const Lang = imports.lang;
  8. const St = imports.gi.St;
  9. const PopupMenu = imports.ui.popupMenu;
  10. const Util = imports.misc.util;
  11. const GLib = imports.gi.GLib;
  12. const ModalDialog = imports.ui.modalDialog;
  13.  
  14. function ConfirmDialog(){
  15.     this._init();
  16. }
  17.  
  18. function MyApplet(orientation) {
  19.     this._init(orientation);
  20. }
  21.  
  22. MyApplet.prototype = {
  23.     __proto__: Applet.IconApplet.prototype,
  24.  
  25.     _init: function(orientation) {        
  26.         Applet.IconApplet.prototype._init.call(this, orientation);
  27.        
  28.         try {        
  29.             this.set_applet_icon_symbolic_name("system-shutdown");
  30.             this.set_applet_tooltip(_("Shutdown"));          
  31.             this.menuManager = new PopupMenu.PopupMenuManager(this);
  32.             this.menu = new Applet.AppletPopupMenu(this, orientation);
  33.             this.menuManager.addMenu(this.menu);                                                                    
  34.             this._contentSection = new PopupMenu.PopupMenuSection();
  35.             this.menu.addMenuItem(this._contentSection);      
  36.                                                                                        
  37.         this.menu.addAction(_("Screen Lock"), function(event) {
  38.                 Util.spawnCommandLine("dbus-send --session --type=method_call --print-reply --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock");
  39.             });                                                                        
  40.  
  41.             this.menu.addAction(_("Suspend"), function(event) {
  42.                 Util.spawnCommandLine("systemctl suspend");
  43.             });
  44.        
  45.               this.menu.addAction(_("Hibernate"), function(event) {
  46.                 Util.spawnCommandLine("systemctl hibernate");
  47.             });  
  48.            
  49.              this.menu.addAction(_("Restart"), function(event) {
  50.                 Util.spawnCommandLine("systemctl reboot");
  51.             });  
  52.            
  53.         this.menu.addAction(_("Log Out"), function(event) {
  54.                 Util.spawnCommandLine("dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1");
  55.             });
  56.            
  57.          this.menu.addAction(_("Shutdown"), function(event) {
  58.                 Util.spawnCommandLine("systemctl poweroff");
  59.             });                        
  60.         }
  61.         catch (e) {
  62.             global.logError(e);
  63.         }
  64.     },
  65.     on_applet_clicked: function(event) {
  66.         this.menu.toggle();        
  67.     },
  68. };
  69. function main(metadata, orientation) {  
  70.     let myApplet = new MyApplet(orientation);
  71.     return myApplet;      
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement