Port to GDBus 2

The GDBus bindings in gjs have been updated to leverage metaclasses
and gobject inheritance, which should result in cleaner and more
maintainable code.
This commit is contained in:
Giovanni Campagna
2011-12-10 14:54:39 +01:00
parent aef9b733e5
commit a6b4d68a1d
20 changed files with 543 additions and 286 deletions

View File

@ -1,6 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Clutter = imports.gi.Clutter;
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const St = imports.gi.St;
@ -200,19 +201,17 @@ const CalendarServerIface = <interface name="org.gnome.Shell.CalendarServer">
<signal name="Changed" />
</interface>;
const CalendarServerInfo = Gio.DBusInterfaceInfo.new_for_xml(CalendarServerIface);
const CalendarServer = new Gio.DBusProxyClass({
Name: 'CalendarServer',
Interface: CalendarServerIface,
function CalendarServer() {
var self = new Gio.DBusProxy({ g_connection: Gio.DBus.session,
g_interface_name: CalendarServerInfo.name,
g_interface_info: CalendarServerInfo,
g_name: 'org.gnome.Shell.CalendarServer',
g_object_path: '/org/gnome/Shell/CalendarServer',
g_flags: Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES });
self.init(null);
return self;
}
_init: function() {
this.parent({ g_bus_type: Gio.BusType.SESSION,
g_name: 'org.gnome.Shell.CalendarServer',
g_object_path: '/org/gnome/Shell/CalendarServer',
g_flags: Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES });
}
});
function _datesEqual(a, b) {
if (a < b)
@ -240,6 +239,7 @@ const DBusEventSource = new Lang.Class({
this._resetCache();
this._dbusProxy = new CalendarServer();
this._dbusProxy.init(null);
this._dbusProxy.connectSignal('Changed', Lang.bind(this, this._onChanged));
this._dbusProxy.connect('notify::g-name-owner', Lang.bind(this, function() {
@ -270,38 +270,48 @@ const DBusEventSource = new Lang.Class({
this._loadEvents(false);
},
_onEventsReceived: function(results, error) {
let newEvents = [];
let appointments = results ? results[0] : null;
if (appointments != null) {
for (let n = 0; n < appointments.length; n++) {
let a = appointments[n];
let date = new Date(a[4] * 1000);
let end = new Date(a[5] * 1000);
let summary = a[1];
let allDay = a[3];
let event = new CalendarEvent(date, end, summary, allDay);
newEvents.push(event);
}
newEvents.sort(function(event1, event2) {
return event1.date.getTime() - event2.date.getTime();
});
_onEventsReceived: function(proxy, result) {
let appointments;
try {
[appointments] = proxy.call_finish(result).deep_unpack();
} catch(e if e instanceof GLib.Error) {
// ignore errors coming from DBus
appointments = [];
}
let newEvents = [];
for (let n = 0; n < appointments.length; n++) {
let a = appointments[n];
let date = new Date(a[4] * 1000);
let end = new Date(a[5] * 1000);
let summary = a[1];
let allDay = a[3];
let event = new CalendarEvent(date, end, summary, allDay);
newEvents.push(event);
}
newEvents.sort(function(event1, event2) {
return event1.date.getTime() - event2.date.getTime();
});
this._events = newEvents;
this.emit('changed');
},
_loadEvents: function(forceReload) {
if (this._curRequestBegin && this._curRequestEnd){
/* Can't use GetEventsRemote because we need to pass the
flags here */
let callFlags = Gio.DBusCallFlags.NO_AUTO_START;
if (forceReload)
callFlags = Gio.DBusCallFlags.NONE;
this._dbusProxy.GetEventsRemote(this._curRequestBegin.getTime() / 1000,
this._curRequestEnd.getTime() / 1000,
forceReload,
Lang.bind(this, this._onEventsReceived),
callFlags);
callFlags = Gio.DBusCallFlags.NONE;
this._dbusProxy.call("GetEvents",
GLib.Variant.new("(xxb)", [this._curRequestBegin.getTime() / 1000,
this._curRequestEnd.getTime() / 1000,
forceReload]),
callFlags,
-1,
null,
Lang.bind(this, this._onEventsReceived));
}
},

View File

@ -2,6 +2,7 @@
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const St = imports.gi.St;
const LoginManager = imports.misc.loginManager;
@ -82,12 +83,16 @@ const HotplugSnifferIface = <interface name="org.gnome.Shell.HotplugSniffer">
</method>
</interface>;
const HotplugSnifferProxy = Gio.DBusProxy.makeProxyWrapper(HotplugSnifferIface);
function HotplugSniffer() {
return new HotplugSnifferProxy(Gio.DBus.session,
'org.gnome.Shell.HotplugSniffer',
'/org/gnome/Shell/HotplugSniffer');
}
const HotplugSniffer = new Gio.DBusProxyClass({
Name: 'HotplugSnifferProxy',
Interface: HotplugSnifferIface,
_init: function() {
this.parent({ g_bus_type: Gio.BusType.SESSION,
g_name: 'org.gnome.Shell.HotplugSniffer',
g_object_path: '/org/gnome/Shell/HotplugSniffer' });
}
});
const ContentTypeDiscoverer = new Lang.Class({
Name: 'ContentTypeDiscoverer',
@ -127,10 +132,14 @@ const ContentTypeDiscoverer = new Lang.Class({
let root = mount.get_root();
let hotplugSniffer = new HotplugSniffer();
hotplugSniffer.SniffURIRemote(root.get_uri(),
Lang.bind(this, function([contentTypes]) {
this._emitCallback(mount, contentTypes);
}));
hotplugSniffer.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(proxy, result) {
proxy.init_finish(result);
proxy.SniffURIRemote(root.get_uri(), null, Lang.bind(this, function(proxy, result) {
let [contentTypes] = proxy.SniffURIFinish(result);
this._emitCallback(mount, contentTypes);
}));
}));
}
},

View File

@ -218,6 +218,34 @@ function init() {
_endSessionDialog = new EndSessionDialog();
}
const EndSessionExporter = new Gio.DBusImplementerClass({
Name: 'EndSessionExporter',
Interface: EndSessionDialogIface,
_init: function() {
this.parent();
this.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
},
OpenAsync: function(parameters, invocation) {
this.emit('open', parameters, invocation);
},
close: function() {
this.emit_signal('Closed');
},
cancel: function() {
this.emit_signal('Canceled');
},
confirm: function(type) {
this.emit_signal(type);
},
});
Signals.addSignalMethods(EndSessionExporter.prototype);
const EndSessionDialog = new Lang.Class({
Name: 'EndSessionDialog',
Extends: ModalDialog.ModalDialog,
@ -295,8 +323,8 @@ const EndSessionDialog = new Lang.Class({
scrollView.hide();
}));
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(EndSessionDialogIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/SessionManager/EndSessionDialog');
this._exporter = new EndSessionExporter();
this._exporter.connect('open', Lang.bind(this, this._onOpenRequest));
},
_onDestroy: function() {
@ -387,19 +415,19 @@ const EndSessionDialog = new Lang.Class({
close: function() {
this.parent();
this._dbusImpl.emit_signal('Closed', null);
this._exporter.close();
},
cancel: function() {
this._stopTimer();
this._dbusImpl.emit_signal('Canceled', null);
this._exporter.cancel();
this.close(global.get_current_time());
},
_confirm: function(signal) {
this._fadeOutDialog();
this._stopTimer();
this._dbusImpl.emit_signal(signal, null);
this._exporter.confirm(signal);
},
_onOpened: function() {
@ -452,7 +480,7 @@ const EndSessionDialog = new Lang.Class({
this._updateContent();
},
OpenAsync: function(parameters, invocation) {
_onOpenRequest: function(exporter, parameters, invocation) {
let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
this._totalSecondsToStayOpen = totalSecondsToStayOpen;
this._inhibitors = [];
@ -466,7 +494,10 @@ const EndSessionDialog = new Lang.Class({
}
for (let i = 0; i < inhibitorObjectPaths.length; i++) {
let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i], Lang.bind(this, function(proxy, error) {
let inhibitor = new GnomeSession.Inhibitor(inhibitorObjectPaths[i]);
inhibitor.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(proxy, result) {
proxy.init_finish(result);
this._onInhibitorLoaded(proxy);
}));

View File

@ -2,7 +2,6 @@
const Caribou = imports.gi.Caribou;
const Clutter = imports.gi.Clutter;
const DBus = imports.dbus;
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
@ -191,13 +190,14 @@ const Key = new Lang.Class({
}
});
const Keyboard = new Lang.Class({
const Keyboard = new Gio.DBusImplementerClass({
// HACK: we can't set Name, because it collides with Name dbus property
// Name: 'Keyboard',
Interface: CaribouKeyboardIface,
_init: function () {
this._impl = Gio.DBusExportedObject.wrapJSObject(CaribouKeyboardIface, this);
this._impl.export(Gio.DBus.session, '/org/gnome/Caribou/Keyboard');
this.parent();
this.export(Gio.DBus.session, '/org/gnome/Caribou/Keyboard');
this.actor = null;
this._focusInTray = false;

View File

@ -96,14 +96,15 @@ const ZoomRegionIface = <interface name={ZOOM_SERVICE_NAME}>
// '/org/gnome/Magnifier/ZoomRegion/zoomer1', etc.
let _zoomRegionInstanceCount = 0;
const ShellMagnifier = new Lang.Class({
const ShellMagnifier = new Gio.DBusImplementerClass({
Name: 'ShellMagnifier',
Interface: MagnifierIface,
_init: function() {
this._zoomers = {};
this.parent();
this.export(Gio.DBus.session, MAG_SERVICE_PATH);
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(MagnifierIface, this);
this._dbusImpl.export(Gio.DBus.session, MAG_SERVICE_PATH);
this._zoomers = {};
},
/**
@ -332,14 +333,15 @@ const ShellMagnifier = new Lang.Class({
* @zoomerObjectPath: String that is the path to a DBus ZoomRegion.
* @zoomRegion: The actual zoom region associated with the object path.
*/
const ShellMagnifierZoomRegion = new Lang.Class({
const ShellMagnifierZoomRegion = new Gio.DBusImplementerClass({
Name: 'ShellMagnifierZoomRegion',
Interface: ZoomRegionIface,
_init: function(zoomerObjectPath, zoomRegion) {
this._zoomRegion = zoomRegion;
this.parent();
this.export(Gio.DBus.session, zoomerObjectPath);
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ZoomRegionIface, this);
this._dbusImpl.export(Gio.DBus.session, zoomerObjectPath);
this._zoomRegion = zoomRegion;
},
/**
@ -417,6 +419,6 @@ const ShellMagnifierZoomRegion = new Lang.Class({
},
destroy: function() {
this._dbusImpl.unexport();
this.unexport();
}
});

View File

@ -1365,13 +1365,16 @@ const MessageTray = new Lang.Class({
Name: 'MessageTray',
_init: function() {
this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) {
this._presence = new GnomeSession.Presence();
this._presence.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(proxy, result) {
proxy.init_finish(result);
this._onStatusChanged(proxy.status);
this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
this._onStatusChanged(status);
}));
}));
this._busy = false;
this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
this._onStatusChanged(status);
}));
this.actor = new St.Widget({ name: 'message-tray',
reactive: true,

View File

@ -25,10 +25,16 @@ const BusIface = <interface name="org.freedesktop.DBus">
</method>
</interface>;
var BusProxy = Gio.DBusProxy.makeProxyWrapper(BusIface);
function Bus() {
return new BusProxy(Gio.DBus.session, 'org.freedesktop.DBus', '/org/freedesktop/DBus');
}
const Bus = new Gio.DBusProxyClass({
Name: 'SessionBusProxy',
Interface: BusIface,
_init: function() {
this.parent({ g_bus_type: Gio.BusType.SESSION,
g_name: 'org.freedesktop.DBus',
g_object_path: '/org/freedesktop/DBus' });
}
});
const NotificationDaemonIface = <interface name="org.freedesktop.Notifications">
<method name="Notify">
@ -103,17 +109,19 @@ const STANDARD_TRAY_ICON_IMPLEMENTATIONS = {
'ibus-ui-gtk': 'keyboard'
};
const NotificationDaemon = new Lang.Class({
const NotificationDaemon = new Gio.DBusImplementerClass({
Name: 'NotificationDaemon',
Interface: NotificationDaemonIface,
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(NotificationDaemonIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/freedesktop/Notifications');
this.parent();
this.export(Gio.DBus.session, '/org/freedesktop/Notifications');
this._sources = [];
this._senderToPid = {};
this._notifications = {};
this._busProxy = new Bus();
this._busProxy.init(null);
this._trayManager = new Shell.TrayManager();
this._trayIconAddedId = this._trayManager.connect('tray-icon-added', Lang.bind(this, this._onTrayIconAdded));
@ -316,18 +324,20 @@ const NotificationDaemon = new Lang.Class({
return invocation.return_value(GLib.Variant.new('(u)', [id]));;
}
this._busProxy.GetConnectionUnixProcessIDRemote(sender, Lang.bind(this, function (result, excp) {
this._busProxy.GetConnectionUnixProcessIDRemote(sender, null, Lang.bind(this, function (proxy, result) {
// The app may have updated or removed the notification
ndata = this._notifications[id];
if (!ndata)
return;
if (excp) {
let pid;
try {
[pid] = proxy.GetConnectionUnixProcessIDFinish(result);
} catch(excp) {
logError(excp, 'Call to GetConnectionUnixProcessID failed');
return;
}
let [pid] = result;
source = this._getSource(appName, pid, ndata, sender, null);
// We only store sender-pid entries for persistent sources.
@ -487,13 +497,11 @@ const NotificationDaemon = new Lang.Class({
},
_emitNotificationClosed: function(id, reason) {
this._dbusImpl.emit_signal('NotificationClosed',
GLib.Variant.new('(uu)', [id, reason]));
this.emit_signal('NotificationClosed', id, reason);
},
_emitActionInvoked: function(id, action) {
this._dbusImpl.emit_signal('ActionInvoked',
GLib.Variant.new('(us)', [id, action]));
this.emit_signal('ActionInvoked', id, action);
},
_onTrayIconAdded: function(o, icon) {

View File

@ -29,8 +29,15 @@ const SearchProviderIface = <interface name="org.gnome.Shell.SearchProvider">
</method>
</interface>;
var SearchProviderProxy = Gio.DBusProxy.makeProxyWrapper(SearchProviderIface);
var SearchProviderProxy = new Gio.DBusProxyClass({
Name: 'SearchProviderProxy',
Interface: SearchProviderIface,
_init: function(params) {
params.g_bus_type = Gio.BusType.SESSION;
this.parent(params);
}
});
function loadRemoteSearchProviders(addProviderCallback) {
let dataDirs = GLib.get_system_data_dirs();
@ -107,8 +114,9 @@ const RemoteSearchProvider = new Lang.Class({
Extends: Search.SearchProvider,
_init: function(title, icon, dbusName, dbusPath) {
this._proxy = new SearchProviderProxy(Gio.DBus.session,
dbusName, dbusPath);
this._proxy = new SearchProviderProxy({ g_name: dbusName,
g_object_path: dbusPath });
this._proxy.init(null);
this.parent(title.toUpperCase());
this._cancellable = new Gio.Cancellable();
@ -131,10 +139,17 @@ const RemoteSearchProvider = new Lang.Class({
icon_size: size });
},
_getResultsFinished: function(results, error) {
if (error)
return;
this.searchSystem.pushResults(this, results[0]);
_getResultsFinished: function(proxy, result) {
try {
// We rely on a small implementation detail of the
// GDBus bindings here: all *Finish are equal
let [results] = proxy.GetInitialResultSetFinish(result);
this.searchSystem.pushResults(this, results);
} catch(e) {
if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
log('Received error from search provider %s: %s'.format(this.title, String(e)));
}
},
getInitialResultSet: function(terms) {
@ -142,8 +157,8 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetInitialResultSetRemote(terms,
Lang.bind(this, this._getResultsFinished),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultsFinished));
} catch(e) {
log('Error calling GetInitialResultSet for provider %s: %s'.format( this.title, e.toString()));
this.searchSystem.pushResults(this, []);
@ -155,30 +170,30 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetSubsearchResultSetRemote(previousResults, newTerms,
Lang.bind(this, this._getResultsFinished),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultsFinished))
} catch(e) {
log('Error calling GetSubsearchResultSet for provider %s: %s'.format(this.title, e.toString()));
this.searchSystem.pushResults(this, []);
}
},
_getResultMetasFinished: function(results, error, callback) {
if (error) {
_getResultMetasFinished: function(proxy, result, callback) {
try {
let [metas] = results.GetResultMetasFinish(result);
let resultMetas = [];
for (let i = 0; i < metas.length; i++) {
for (let prop in metas[i])
metas[i][prop] = metas[i][prop].deep_unpack();
resultMetas.push({ id: metas[i]['id'],
name: metas[i]['name'],
createIcon: Lang.bind(this,
this.createIcon, metas[i]) });
}
callback(resultMetas);
} catch(e) {
callback([]);
return;
}
let metas = results[0];
let resultMetas = [];
for (let i = 0; i < metas.length; i++) {
for (let prop in metas[i])
metas[i][prop] = metas[i][prop].deep_unpack();
resultMetas.push({ id: metas[i]['id'],
name: metas[i]['name'],
createIcon: Lang.bind(this,
this.createIcon, metas[i]) });
}
callback(resultMetas);
},
getResultMetas: function(ids, callback) {
@ -186,8 +201,8 @@ const RemoteSearchProvider = new Lang.Class({
this._cancellable.reset();
try {
this._proxy.GetResultMetasRemote(ids,
Lang.bind(this, this._getResultMetasFinished, callback),
this._cancellable);
this._cancellable,
Lang.bind(this, this._getResultMetasFinished, callback));
} catch(e) {
log('Error calling GetResultMetas for provider %s: %s'.format(this.title, e.toString()));
callback([]);
@ -195,7 +210,7 @@ const RemoteSearchProvider = new Lang.Class({
},
activateResult: function(id) {
this._proxy.ActivateResultRemote(id);
this._proxy.ActivateResultRemote(id, null, null);
}
});

View File

@ -80,15 +80,23 @@ const PerfHelperIface = <interface name="org.gnome.Shell.PerfHelper">
<method name="DestroyWindows" />
</interface>;
var PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface);
function PerfHelper() {
return new PerfHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
}
const PerfHelper = new Gio.DBusProxyClass({
Name: 'PerfHelperProxy',
Interface: PerfHelperIface,
_init: function() {
this.parent({ g_bus_type: Gio.BusType.SESSION,
g_name: 'org.gnome.Shell.PerfHelper',
g_object_path: '/org/gnome/Shell/PerfHelper' });
}
});
let _perfHelper = null;
function _getPerfHelper() {
if (_perfHelper == null)
if (_perfHelper == null) {
_perfHelper = new PerfHelper();
_perfHelper.init(null);
}
return _perfHelper;
}
@ -111,7 +119,8 @@ function createTestWindow(width, height, alpha, maximized) {
let perfHelper = _getPerfHelper();
perfHelper.CreateWindowRemote(width, height, alpha, maximized,
function(result, excp) {
null,
function(proxy, result) {
if (cb)
cb();
});
@ -131,7 +140,7 @@ function waitTestWindows() {
let cb;
let perfHelper = _getPerfHelper();
perfHelper.WaitWindowsRemote(function(result, excp) {
perfHelper.WaitWindowsRemote(null, function(proxy, result) {
if (cb)
cb();
});
@ -154,7 +163,7 @@ function destroyTestWindows() {
let cb;
let perfHelper = _getPerfHelper();
perfHelper.DestroyWindowsRemote(function(result, excp) {
perfHelper.DestroyWindowsRemote(null, function(proxy, result) {
if (cb)
cb();
});

View File

@ -67,14 +67,16 @@ const ScreenSaverIface = <interface name="org.gnome.ScreenSaver">
</signal>
</interface>;
const GnomeShell = new Lang.Class({
const GnomeShell = new Gio.DBusImplementerClass({
Name: 'GnomeShellDBus',
Interface: GnomeShellIface,
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell');
this.parent();
this._extensionsSerivce = new GnomeShellExtensions();
this.export(Gio.DBus.session, '/org/gnome/Shell');
this._extensionsService = new GnomeShellExtensions();
},
/**
@ -236,12 +238,14 @@ const GnomeShellExtensionsIface = <interface name="org.gnome.Shell.Extensions">
<property name="ShellVersion" type="s" access="read" />
</interface>;
const GnomeShellExtensions = new Lang.Class({
const GnomeShellExtensions = new Gio.DBusImplementerClass({
Name: 'GnomeShellExtensionsDBus',
Interface: GnomeShellExtensionsIface,
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellExtensionsIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/Shell');
this.parent();
this.export(Gio.DBus.session, '/org/gnome/Shell');
ExtensionSystem.connect('extension-state-changed',
Lang.bind(this, this._extensionStateChanged));
},
@ -335,25 +339,23 @@ const GnomeShellExtensions = new Lang.Class({
ShellVersion: Config.PACKAGE_VERSION,
_extensionStateChanged: function(_, newState) {
this._dbusImpl.emit_signal('ExtensionStatusChanged',
GLib.Variant.new('(sis)', [newState.uuid, newState.state, newState.error]));
this.emit_signal('ExtensionStatusChanged', newState.uuid, newState.state, newState.error);
}
});
const ScreenSaverDBus = new Lang.Class({
const ScreenSaverDBus = new Gio.DBusImplementerClass({
Name: 'ScreenSaverDBus',
Interface: ScreenSaverIface,
_init: function(screenShield) {
this.parent();
this._screenShield = screenShield;
screenShield.connect('lock-status-changed', Lang.bind(this, function(shield) {
this._dbusImpl.emit_signal('ActiveChanged', GLib.Variant.new('(b)', [shield.locked]));
this.emit_signal('ActiveChanged', shield.locked);
}));
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(ScreenSaverIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gnome/ScreenSaver');
this.export(Gio.DBus.session, '/org/gnome/ScreenSaver');
Gio.DBus.session.own_name('org.gnome.ScreenSaver', Gio.BusNameOwnerFlags.REPLACE, null, null);
},

View File

@ -554,14 +554,16 @@ const ShellMountOperationType = {
SHOW_PROCESSES: 3
};
const GnomeShellMountOpHandler = new Lang.Class({
const GnomeShellMountOpHandler = new Gio.DBusImplementerClass({
Name: 'GnomeShellMountOpHandler',
Interface: GnomeShellMountOpIface,
_init: function() {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(GnomeShellMountOpIface, this);
this._dbusImpl.export(Gio.DBus.session, '/org/gtk/MountOperationHandler');
Gio.bus_own_name_on_connection(Gio.DBus.session, 'org.gtk.MountOperationHandler',
Gio.BusNameOwnerFlags.REPLACE, null, null);
this.parent();
this.export(Gio.DBus.session, '/org/gtk/MountOperationHandler');
Gio.DBus.session.own_name('org.gtk.MountOperationHandler',
Gio.BusNameOwnerFlags.REPLACE, null, null);
this._dialog = null;
this._volumeMonitor = Gio.VolumeMonitor.get();

View File

@ -1,6 +1,7 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const St = imports.gi.St;
@ -45,7 +46,16 @@ const PowerManagerInterface = <interface name="org.gnome.SettingsDaemon.Power">
<property name="Icon" type="s" access="read" />
</interface>;
const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface);
const PowerManagerProxy = new Gio.DBusProxyClass({
Name: 'PowerManagerProxy',
Interface: PowerManagerInterface,
_init: function() {
this.parent({ g_bus_type: Gio.BusType.SESSION,
g_name: BUS_NAME,
g_object_path: OBJECT_PATH });
}
});
const Indicator = new Lang.Class({
Name: 'PowerIndicator',
@ -54,7 +64,7 @@ const Indicator = new Lang.Class({
_init: function() {
this.parent('battery-missing-symbolic', _("Battery"));
this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
this._proxy = new PowerManagerProxy();
this._deviceItems = [ ];
this._hasPrimary = false;
@ -73,18 +83,26 @@ const Indicator = new Lang.Class({
this._proxy.connect('g-properties-changed',
Lang.bind(this, this._devicesChanged));
this._devicesChanged();
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(proxy, result) {
proxy.init_finish(result);
this._devicesChanged();
}));
},
_readPrimaryDevice: function() {
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
if (error) {
this._proxy.GetPrimaryDeviceRemote(null, Lang.bind(this, function(proxy, result) {
let device_id, device_type, icon, percentage, state, seconds;
try {
[[device_id, device_type, icon, percentage, state, seconds]] =
proxy.GetPrimaryDeviceFinish(result);
} catch(e) {
this._hasPrimary = false;
this._primaryDeviceId = null;
this._batteryItem.actor.hide();
return;
}
let [[device_id, device_type, icon, percentage, state, seconds]] = result;
if (device_type == UPDeviceType.BATTERY) {
this._hasPrimary = true;
let time = Math.round(seconds / 60);
@ -121,16 +139,18 @@ const Indicator = new Lang.Class({
},
_readOtherDevices: function() {
this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
this._proxy.GetDevicesRemote(null, Lang.bind(this, function(proxy, result) {
this._deviceItems.forEach(function(i) { i.destroy(); });
this._deviceItems = [];
if (error) {
let devices;
try {
[devices] = proxy.GetDevicesFinish(result);
} catch(e) {
return;
}
let position = 0;
let [devices] = result;
for (let i = 0; i < devices.length; i++) {
let [device_id, device_type] = devices[i];
if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId)

View File

@ -195,8 +195,12 @@ const IMStatusChooserItem = new Lang.Class({
Lang.bind(this, this._changeIMStatus));
this._presence = new GnomeSession.Presence();
this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
this._sessionStatusChanged(status);
this._presence.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(obj, result) {
obj.init_finish(result);
this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
this._sessionStatusChanged(status);
}));
}));
this._sessionPresenceRestored = false;
@ -480,8 +484,19 @@ const UserMenuButton = new Lang.Class({
this._userManager = AccountsService.UserManager.get_default();
this._user = this._userManager.get_user(GLib.get_user_name());
this._presence = new GnomeSession.Presence();
this._presence.init_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(proxy, result) {
proxy.init_finish(result);
this._updateSwitch(this._presence.status);
this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) {
this._updateSwitch(status);
}));
}));
this._session = new GnomeSession.SessionManager();
this._session.init(null);
this._haveShutdown = true;
this._haveSuspend = true;
@ -533,11 +548,6 @@ const UserMenuButton = new Lang.Class({
this._createSubMenu();
this._updateSwitch(this._presence.status);
this._presence.connectSignal('StatusChanged', Lang.bind(this, function (proxy, senderName, [status]) {
this._updateSwitch(status);
}));
this._userManager.connect('notify::is-loaded',
Lang.bind(this, this._updateMultiUser));
this._userManager.connect('notify::has-multiple-users',
@ -637,14 +647,16 @@ const UserMenuButton = new Lang.Class({
},
_updateHaveShutdown: function() {
this._session.CanShutdownRemote(Lang.bind(this,
function(result, error) {
if (!error) {
this._haveShutdown = result[0];
this._updateInstallUpdates();
this._updateSuspendOrPowerOff();
}
}));
this._session.CanShutdownRemote(null, Lang.bind(this, function(proxy, result) {
try {
[this._haveShutdown] = proxy.CanShutdownFinish(result);
} catch(e) {
this._haveShutdown = false;
}
this._updateInstallUpdates();
this._updateSuspendOrPowerOff();
}));
},
_updateHaveSuspend: function() {
@ -837,7 +849,7 @@ const UserMenuButton = new Lang.Class({
_onQuitSessionActivate: function() {
Main.overview.hide();
this._session.LogoutRemote(0);
this._session.LogoutRemote(0, null, null);
},
_onInstallUpdatesActivate: function() {
@ -852,7 +864,7 @@ const UserMenuButton = new Lang.Class({
if (this._haveShutdown &&
this._suspendOrPowerOffItem.state == PopupMenu.PopupAlternatingMenuItemState.DEFAULT) {
this._session.ShutdownRemote();
this._session.ShutdownRemote(null, null);
} else {
if (this._screenSaverSettings.get_boolean(LOCK_ENABLED_KEY)) {
let tmpId = Main.screenShield.connect('lock-screen-shown', Lang.bind(this, function() {