Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Now uses it's own menu with changing icon
Browse files Browse the repository at this point in the history
This seems to just make more sense, plus it avoids using a hack to check the battery menu visibility and allows for a dynamic icon to check status easily
  • Loading branch information
Mystro256 committed Mar 5, 2012
1 parent 391d1c2 commit 478af0b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Gnome Shell Extension Inhibit Applet is a gnome shell extension that gives you t

This was forked from Raphael Kimmig's Gnome-Presentation-Mode, in hopes to improve it and add more translations. I don't take an credit for the work that he has done on this extension so far.

![Screenshot1](https://github.com/Mystro256/gnome-shell-extension-inhibit-applet/raw/master/Screenshot power.png)![Screenshot2](https://github.com/Mystro256/gnome-shell-extension-inhibit-applet/raw/master/Screenshot a11y.png)
![Screenshot](https://github.com/Mystro256/gnome-shell-extension-inhibit-applet/raw/master/Screenshot.png)

## Installation instructions:
Go onto https://extensions.gnome.org and find the extension. It's much easier to install it through that website than manually.
Expand Down
Binary file removed Screenshot a11y.png
Binary file not shown.
Binary file removed Screenshot power.png
Binary file not shown.
Binary file added Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 51 additions & 53 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Lang = imports.lang;
const St = imports.gi.St;

const Main = imports.ui.main;
const Mainloop = imports.mainloop;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const GnomeSession = imports.misc.gnomeSession;
const UserMenu = imports.ui.userMenu;
Expand All @@ -19,69 +19,67 @@ const SessionIface = {
{ name: "Uninhibit", inSignature: "u", outSignature: "" }
]
};

let SessionProxy = DBus.makeProxyClass(SessionIface);
let indicationmenu;

//Icon variables for easy editing/customization:
let DisabledIcon = 'preferences-desktop-screensaver-symbolic';
let EnabledIcon = 'system-run-symbolic';
////An alternative icon could be:
//let EnabledIcon = 'action-unavailable-symbolic';

function init(extensionMeta) {
parentMenu = undefined; //Initialize to undefined
imports.gettext.bindtextdomain("gnome-shell-extension-inhibitapplet",
extensionMeta.path + "/locale");
}

function InhibitMenu() {
this._init.apply(this, arguments);
}

function enable() {
if(parentMenu == undefined){ //Hack to fix issue #1, refresh after 5 seconds
Mainloop.timeout_add_seconds(5, Lang.bind(this, function() {
this.disable();
this.enable();}));
}
//Check if battery menu is invisible
if(!Main.panel._statusArea.battery.actor.get_paint_visibility())
{ //check for no battery or power device, i.e. no battery menu
if(Main.panel._statusArea.a11y != null)
{ //check for no a11y (such as from noa11y extension)
parentMenu = Main.panel._statusArea.a11y;
}
else { //else wise, resort to using the user menu
parentMenu = Main.panel._statusArea.userMenu;
}
}
else { //If all else is good, the battery menu is fine
parentMenu = Main.panel._statusArea.battery;
}
//Add the Inhibit Option
parentMenu._itemSeparator = new PopupMenu.PopupSeparatorMenuItem();
parentMenu.menu.addMenuItem(parentMenu._itemSeparator);
parentMenu._inhibitswitch = new PopupMenu.PopupSwitchMenuItem(_("Inhibit Suspend"), false);
parentMenu.menu.addMenuItem(parentMenu._inhibitswitch);
parentMenu._inhibit = undefined;
parentMenu._sessionProxy = new SessionProxy(DBus.session, 'org.gnome.SessionManager', '/org/gnome/SessionManager');
indicationmenu = new InhibitMenu();
Main.panel.addToStatusArea('inhibit-menu', indicationmenu);
}

parentMenu._onInhibit = function(cookie) {
parentMenu._inhibit = cookie;
};
InhibitMenu.prototype = {
__proto__: PanelMenu.SystemStatusButton.prototype,

parentMenu._inhibitswitch.connect('toggled', Lang.bind(parentMenu, function() {
if(parentMenu._inhibit) {
parentMenu._sessionProxy.UninhibitRemote(parentMenu._inhibit);
parentMenu._inhibit = undefined;
} else {
try {
parentMenu._sessionProxy.InhibitRemote("inhibitor",
0,
"inhibit mode",
9,
Lang.bind(parentMenu, parentMenu._onInhibit));
} catch(e) {
//
_init: function() {
PanelMenu.SystemStatusButton.prototype._init.call(this, DisabledIcon);

//Add the Inhibit Option
this._inhibitswitch = new PopupMenu.PopupSwitchMenuItem(_("Inhibit Suspend"), false);
this.menu.addMenuItem(this._inhibitswitch);
this._inhibit = undefined;
this._sessionProxy = new SessionProxy(DBus.session, 'org.gnome.SessionManager', '/org/gnome/SessionManager');

this._onInhibit = function(cookie) {
this._inhibit = cookie;
};

this._inhibitswitch.connect('toggled', Lang.bind(this, function() {
if(this._inhibit) {
this._sessionProxy.UninhibitRemote(this._inhibit);
this._inhibit = undefined;
this.setIcon(DisabledIcon);
} else {
try {
this._sessionProxy.InhibitRemote("inhibitor",
0,
"inhibit mode",
9,
Lang.bind(this, this._onInhibit));
this.setIcon(EnabledIcon);
} catch(e) {
//
}
}
}
}));
}
}));
},
};

function disable() {
parentMenu._inhibitswitch.destroy();
parentMenu._itemSeparator.destroy();
if(parentMenu._inhibit) {
parentMenu._sessionProxy.UninhibitRemote(parentMenu._inhibit);
parentMenu._inhibit = undefined;
}
indicationmenu.destroy();
}
3 changes: 2 additions & 1 deletion [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"uuid": "[email protected]",
"name": "Inhibit Applet",
"description": "Adds the ability to inhibit suspend/screensaver",
"url": "https://github.com/Mystro256/gnome-shell-extension-inhibit-applet"
"url": "https://github.com/Mystro256/gnome-shell-extension-inhibit-applet",
"version": 5
}

0 comments on commit 478af0b

Please sign in to comment.