/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */

const DBus = imports.dbus;
const Lang = imports.lang;
const Mainloop = imports.mainloop;

const BUS_NAME = 'org.gnome.SettingsDaemon'
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Power';

const PowerManagerInterface = {
    name: 'org.gnome.SettingsDaemon.Power',
    methods: [ ],
    signals: [
        { name: 'Changed', inSignature: '' },
        ],
    properties: [
        { name: 'Icon', signature: 's', access: 'read' },
        ]
};
let PowerManagerProxy = DBus.makeProxyClass(PowerManagerInterface);

function Indicator() {
    this._init();
}

Indicator.prototype = {
    _init: function() {
        this._proxy = new PowerManagerProxy(DBus.session, BUS_NAME, OBJECT_PATH);

        this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
        this._devicesChanged();
        print('end power init');
    },
    _devicesChanged: function() {
        print('_devicesChanged');
        this._proxy.GetRemote('Icon', Lang.bind(this, function(icon, error) {
            if (icon) {
                print('icon: ' + icon);
            } else {
                print('no icon');
            }
        }));
    }
};

let indicator = new Indicator();

Mainloop.run('test');
