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

Commit

Permalink
Finish new Inhibition method and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mystro256 committed May 17, 2012
1 parent e73d6ac commit acf2fbe
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ const UserMenu = imports.ui.userMenu;

const Gettext = imports.gettext.domain('gnome-shell-extension-inhibitapplet');
const _ = Gettext.gettext;
const POWER_SCHEMA = 'org.gnome.settings-daemon.plugins.power';

const POWER_SCHEMA = 'org.gnome.settings-daemon.plugins.power';
const POWER_KEY = 'active';
let indicationmenu;
const SCREEN_SCHEMA = 'org.gnome.desktop.screensaver';
const SCREEN_KEY = 'idle-activation-enabled';

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';
////An alternative icon could be 'action-unavailable-symbolic'

function init(extensionMeta) {
imports.gettext.bindtextdomain("gnome-shell-extension-inhibitapplet",
Expand All @@ -42,15 +44,25 @@ InhibitMenu.prototype = {
_init: function() {
PanelMenu.SystemStatusButton.prototype._init.call(this, DisabledIcon);

//Add the Inhibit Option
///Power Setting
InhibitMenu._powerSettings = new Gio.Settings({ schema: POWER_SCHEMA });
var powerManagementFlag = InhibitMenu._powerSettings.get_boolean(POWER_KEY);
///ScreenSaver Setting
InhibitMenu._screenSettings = new Gio.Settings({ schema: SCREEN_SCHEMA });
//Add the Inhibit Option
this._inhibitswitch = new PopupMenu.PopupSwitchMenuItem(_("Inhibit Suspend"), !powerManagementFlag);
this.menu.addMenuItem(this._inhibitswitch);
//Make sure the screensaver enable is synchronized
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, powerManagementFlag);
//Change Icon if necessary
if(!powerManagementFlag) {
this.setIcon(EnabledIcon);
}

this._inhibitswitch.connect('toggled', Lang.bind(this, function() {
var powerManagementFlag = InhibitMenu._powerSettings.get_boolean(POWER_KEY);
InhibitMenu._powerSettings.set_boolean(POWER_KEY, !powerManagementFlag);
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, !powerManagementFlag);
if(powerManagementFlag) {
this.setIcon(EnabledIcon);
} else {
Expand All @@ -63,6 +75,9 @@ InhibitMenu.prototype = {
function disable() {
indicationmenu.destroy();
if (InhibitMenu._powerSettings) {
InhibitMenu._powerSettings.set_boolean(POWER_KEY, false);
InhibitMenu._powerSettings.set_boolean(POWER_KEY, true);
}
if (InhibitMenu._screenSettings) {
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, true);
}
}

0 comments on commit acf2fbe

Please sign in to comment.