Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Main = imports.ui.main
  2. const PanelMenu = imports.ui.panelMenu
  3. const PopupMenu = imports.ui.popupMenu
  4. const St = imports.gi.St
  5. const Lang = imports.lang
  6. const Meta = imports.gi.Meta
  7. const Shell = imports.gi.Shell
  8. const Util = imports.misc.util
  9. const ExtensionUtils = imports.misc.extensionUtils;
  10.  
  11. /*Menu Functions \/*/
  12.     function _aboutThisPoppy() {
  13.         Util.spawn(['gnome-control-center', 'info'])
  14.     }
  15.  
  16.     function _softwareUpdate() {
  17.         Util.spawn(['update-manager'])
  18.     }
  19.  
  20.     function _appStore() {
  21.         Util.spawn(['gnome-software'])
  22.     }
  23.  
  24.     function _missionControl() {
  25.         Main.overview.toggle();
  26.     }
  27.  
  28.     function _systemPreferences() {
  29.         Util.spawn(['gnome-control-center', '--overview'])
  30.     }
  31.  
  32.     function _forceQuit() {
  33.         Util.spawn(['xkill'])
  34.     }
  35.  
  36.     function _sleep() {
  37.         Util.spawn(['systemctl', 'suspend'])
  38.     }
  39.  
  40.     function _restart() {
  41.         Util.spawn(['systemctl', 'reboot'])
  42.     }
  43.  
  44.     function _shutdown() {
  45.         Util.spawn(['systemctl', 'poweroff'])
  46.     }
  47.  
  48.     function _logOut() {
  49.         Util.spawn(['gnome-session-quit', '--no-prompt'])
  50.     }
  51. /*Menu Functions /\*/
  52.  
  53. /*Poppy Button Class \/*/
  54.     /*
  55.     function _hover() {
  56.         button.actor.remove_actor(icon)
  57.  
  58.         const icon_hover = new St.Icon({
  59.             style_class: 'poppy-button-hover'
  60.         })
  61.    
  62.         button.actor.add_actor(icon_hover)
  63.     }
  64.     */
  65.  
  66.     const PoppyButton = new Lang.Class({
  67.         Name: "PoppyButton",
  68.         Extends: PanelMenu.Button,
  69.  
  70.         _init: function () {
  71.         this.parent(null, "PoppyButton")
  72.  
  73.         // Icon
  74.         this.icon = new St.Icon({
  75.             reactive: true,
  76.             track_hover: true,
  77.             style_class: 'poppy-button'
  78.         })
  79.         this.actor.add_actor(this.icon)
  80.  
  81.         // Menu
  82.         this.item1 = new PopupMenu.PopupMenuItem('About This Poppy')
  83.         this.item2 = new PopupMenu.PopupMenuItem('Software Update...')
  84.         this.item3 = new PopupMenu.PopupMenuItem('App Store...')
  85.         this.item4 = new PopupMenu.PopupSeparatorMenuItem()
  86.         this.item5 = new PopupMenu.PopupMenuItem('Mission Control...')
  87.         this.item6 = new PopupMenu.PopupMenuItem('System Preferences...')
  88.         this.item7 = new PopupMenu.PopupSeparatorMenuItem()
  89.         this.item8 = new PopupMenu.PopupMenuItem('Force Quit...')
  90.         this.item9 = new PopupMenu.PopupSeparatorMenuItem()
  91.         this.item10 = new PopupMenu.PopupMenuItem('Sleep')
  92.         this.item11 = new PopupMenu.PopupMenuItem('Restart...')
  93.         this.item12 = new PopupMenu.PopupMenuItem('Shut Down...')
  94.         this.item13 = new PopupMenu.PopupSeparatorMenuItem()
  95.         this.item14 = new PopupMenu.PopupMenuItem('Log Out...')
  96.  
  97.         this.item1.connect('activate', Lang.bind(this, _aboutThisPoppy))
  98.         this.item2.connect('activate', Lang.bind(this, _softwareUpdate))
  99.         this.item3.connect('activate', Lang.bind(this, _appStore))
  100.         this.item5.connect('activate', Lang.bind(this, _missionControl))
  101.         this.item6.connect('activate', Lang.bind(this, _systemPreferences))
  102.         this.item8.connect('activate', Lang.bind(this, _forceQuit))
  103.         this.item10.connect('activate', Lang.bind(this, _sleep))
  104.         this.item11.connect('activate', Lang.bind(this, _restart))
  105.         this.item12.connect('activate', Lang.bind(this, _shutdown))
  106.         this.item14.connect('activate', Lang.bind(this, _logOut))
  107.  
  108.         this.menu.addMenuItem(this.item1)
  109.         this.menu.addMenuItem(this.item2)
  110.         this.menu.addMenuItem(this.item3)
  111.         this.menu.addMenuItem(this.item4)
  112.         this.menu.addMenuItem(this.item5)
  113.         this.menu.addMenuItem(this.item6)
  114.         this.menu.addMenuItem(this.item7)
  115.         this.menu.addMenuItem(this.item8)
  116.         this.menu.addMenuItem(this.item9)
  117.         this.menu.addMenuItem(this.item10)
  118.         this.menu.addMenuItem(this.item11)
  119.         this.menu.addMenuItem(this.item12)
  120.         this.menu.addMenuItem(this.item13)
  121.         this.menu.addMenuItem(this.item14)
  122.         }
  123.     })
  124. /*Poppy Button Class /\*/
  125.  
  126. /*Disable all HotCorners Function \/*/
  127.     let _id;
  128.  
  129.     function _disable_hot_corners() {
  130.       Main.layoutManager.hotCorners.forEach(function(hot_corner) {
  131.         if (!hot_corner) {
  132.           return;
  133.         }
  134.  
  135.         hot_corner._toggleOverview = function() {};
  136.         hot_corner._pressureBarrier._trigger = function() {};
  137.       });
  138.     }
  139. /*Disable all HotCorners Function /\*/
  140.  
  141. function init() {
  142. }
  143.  
  144. function enable() {
  145.     /*Hide activities button \/*/
  146.         const activitiesButton = Main.panel.statusArea['activities']
  147.         if (activitiesButton) {
  148.             activitiesButton.container.hide()
  149.         }
  150.     /*Hide activities button /\*/
  151.  
  152.     /*Create Poppy button \/*/
  153.         let indicator = new PoppyButton()
  154.         Main.panel.addToStatusArea('poppyButton', indicator, 0, 'left')
  155.  
  156.         // change icon
  157.         //Main.panel.statusArea['poppyButton'].icon.icon_name = "appointment-soon-symbolic"
  158.  
  159.         // show
  160.         Main.panel.statusArea['poppyButton'].actor.visible = true
  161.     /*Create Poppy button /\*/
  162.  
  163.     /*Disable all HotCorners \/*/
  164.         _disable_hot_corners();
  165.         // Hot corners may be re-created afterwards (for example, If there's a monitor change).
  166.         // So we catch all changes.
  167.         _id = Main.layoutManager.connect('hot-corners-changed', _disable_hot_corners);
  168.     /*Disable all HotCorners /\*/
  169. }
  170.  
  171. function disable() {
  172.     /*Show activities button \/*/
  173.         const activitiesButton = Main.panel.statusArea['activities']
  174.         if (activitiesButton) {
  175.             activitiesButton.container.show()
  176.         }
  177.     /*Show activities button /\*/
  178.  
  179.     /*Delete Poppy button \/*/
  180.         Main.panel.statusArea['poppyButton'].destroy()
  181.     /*Delete Poppy button /\*/
  182.  
  183.     /*Enable all HotCorners \/*/
  184.         // Disconnects the callback and re-creates the hot corners
  185.         Main.layoutManager.disconnect(_id);
  186.         Main.layoutManager._updateHotCorners();
  187.     /*Enable all HotCorners /\*/
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement