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

Commit

Permalink
Merge pull request #25 from RaphaelKimmig/experimental
Browse files Browse the repository at this point in the history
Use GSettings to inhibit instead, should fix #13 and #18
  • Loading branch information
Mystro256 committed May 17, 2012
2 parents d691733 + acf2fbe commit c99aa6c
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const DBus = imports.dbus;
const Lang = imports.lang;
const St = imports.gi.St;
const Gio = imports.gi.Gio;

const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
Expand All @@ -12,22 +13,16 @@ const UserMenu = imports.ui.userMenu;
const Gettext = imports.gettext.domain('gnome-shell-extension-inhibitapplet');
const _ = Gettext.gettext;

const SessionIface = {
name: "org.gnome.SessionManager",
methods: [
{ name: "Inhibit", inSignature: "susu", outSignature: "u" },
{ name: "Uninhibit", inSignature: "u", outSignature: "" }
]
};
const POWER_SCHEMA = 'org.gnome.settings-daemon.plugins.power';
const POWER_KEY = 'active';
const SCREEN_SCHEMA = 'org.gnome.desktop.screensaver';
const SCREEN_KEY = 'idle-activation-enabled';

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

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

///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"), false);
this._inhibitswitch = new PopupMenu.PopupSwitchMenuItem(_("Inhibit Suspend"), !powerManagementFlag);
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;
};
//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() {
if(this._inhibit) {
this._sessionProxy.UninhibitRemote(this._inhibit);
this._inhibit = undefined;
this.setIcon(DisabledIcon);
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 {
try {
this._sessionProxy.InhibitRemote("inhibitor",
0,
"inhibit mode",
9,
Lang.bind(this, this._onInhibit));
this.setIcon(EnabledIcon);
} catch(e) {
//
}
this.setIcon(DisabledIcon);
}
}));
},
};

function disable() {
indicationmenu.destroy();
if (InhibitMenu._powerSettings) {
InhibitMenu._powerSettings.set_boolean(POWER_KEY, true);
}
if (InhibitMenu._screenSettings) {
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, true);
}
}

0 comments on commit c99aa6c

Please sign in to comment.