Skip to content

Commit

Permalink
Merge branch 'release/version-23'
Browse files Browse the repository at this point in the history
  • Loading branch information
BigE committed Apr 26, 2017
2 parents 15ee5d5 + 5fe6a72 commit 7fc9ef7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 51 deletions.
82 changes: 44 additions & 38 deletions [email protected]/deskchanger/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class Daemon(Gio.Application):
__version__ = '2.3.0'
__version__ = '2.3.1'

def __init__(self, **kwargs):
Gio.Application.__init__(self, **kwargs)
Expand Down Expand Up @@ -70,6 +70,8 @@ def change(self, reverse=False):
update_lockscreen = self._settings.get_boolean('update-lockscreen')
current = self._background.get_string('picture-uri')
wallpaper = getattr(self._desktop_profile, func)(current)
if wallpaper is False:
return False
# only update the lock screen if the lock screen profile is not a thing
if update_lockscreen and self._lockscreen_profile is None:
self._screensaver.set_string('picture-uri', wallpaper)
Expand Down Expand Up @@ -113,19 +115,25 @@ def do_dbus_register(self, connection, object_path):
"""
logger.debug('::dbus_register')
Gio.Application.do_dbus_register(self, connection, object_path)
failure = False
try:
self._dbus_id = connection.register_object(
object_path,
DeskChangerDaemonDBusInterface.interfaces[0],
self._handle_dbus_call,
None,
None
self._handle_dbus_get,
self._handle_dbus_set
)
except TypeError:
# TODO - Handle this failure correctly.
failure = True
except GLib.Error as e:
logger.debug(e.args)
finally:
if self._dbus_id is None or self._dbus_id == 0:
logger.critical('failed to register DBus name %s', object_path)
if failure:
logger.error('possibly unsupported version of glib')
return False

logger.info('successfully registered DBus name %s', object_path)
Expand Down Expand Up @@ -164,7 +172,7 @@ def do_startup(self):
try:
self.load_profile(self._settings.get_string('current-profile'), False, False)
if self._settings.get_string('lockscreen-profile') != "":
self.load_profile(self._settings.get_string('lockstring-profile'), True, False)
self.load_profile(self._settings.get_string('lockscreen-profile'), True, False)
except ValueError as e:
# If we failed to load the profile, its bad
logger.error('failed to load profiles on startup: %s', e.message)
Expand Down Expand Up @@ -296,39 +304,7 @@ def _emit_preview(self, uri):

def _handle_dbus_call(self, connection, sender, object_path, interface_name, method_name, parameters, invocation):
logger.debug('[DBUS] %s:%s', interface_name, method_name)
if interface_name == 'org.freedesktop.DBus.Properties':
if method_name == 'GetAll':
values = {
'history': GLib.Variant('as', self.history),
'queue': GLib.Variant('as', self.queue),
}
invocation.return_value(GLib.Variant('(a{sv})', (values,)))
elif method_name == 'Get':
interface_name, property_name = parameters.unpack()
if property_name == 'history':
invocation.return_value(GLib.Variant('(v)', (GLib.Variant('as', self.history),)))
elif property_name == 'queue':
invocation.return_value(GLib.Variant('(v)', (GLib.Variant('as', self.queue),)))
else:
invocation.return_dbus_error('org.freedesktop.DBus.Error.InvalidArgs',
'Unknown property %s for interface %s' % (
property_name, interface_name))
logger.warning('[DBUS] Unkown propety %s for interface %s', property_name, interface_name)
elif method_name == 'Set':
interface_name, property_name, value = parameters.unpack()
if property_name == 'lockscreen':
self._lockscreen = bool(value)
invocation.return_value(GLib.Variant('()', tuple()))
logger.info('extension is in %s mode', 'lockscreen' if self._lockscreen else 'desktop')
else:
invocation.return_dbus_error('org.freedesktop.DBus.Error.InvalidArgs',
'Unknown property %s for interface %s' % (
property_name, interface_name))
logger.warning('[DBUS] Unknown property for interface %s', property_name, interface_name)
else:
logger.warning('Missed call from %s for method %s', interface_name, method_name)
return
elif interface_name != self.get_application_id():
if interface_name != self.get_application_id():
logger.warning('received invalid dbus request for interface %s', interface_name)
return

Expand All @@ -351,7 +327,15 @@ def _handle_dbus_call(self, connection, sender, object_path, interface_name, met
invocation.return_dbus_error(self.get_application_id() + '.Next', str(e.args))
elif method_name == 'Prev':
try:
invocation.return_value(GLib.Variant('(s)', (self.change(True),)))
wallpaper = self.change(True)
if wallpaper is False:
logger.critical('no more wallpapers available in history')
invocation.return_dbus_error(
self.get_application_id() + '.Prev',
'No more wallpapers available in history'
)
else:
invocation.return_value(GLib.Variant('(s)', (wallpaper,)))
except ValueError as e:
invocation.return_dbus_error(self.get_application_id() + '.Prev', str(e.args))
else:
Expand All @@ -360,6 +344,28 @@ def _handle_dbus_call(self, connection, sender, object_path, interface_name, met
'Method %s in %s does not exist' % (method_name, interface_name))
return

def _handle_dbus_get(self, connection, sender, object_path, interface_name, property_name):
try:
value = {
"history": GLib.Variant('as', getattr(self, 'history')),
"queue": GLib.Variant('as', getattr(self, 'queue')),
}[property_name]
logger.debug('[DBUS]::Get(%s)', property_name)
except Exception:
logger.warning('[DBUS] Unknown property for interface %s', property_name, interface_name)
raise Exception("failed to get %s::%s" % (interface_name, property_name))
return value

def _handle_dbus_set(self, connection, sender, object_path, interface_name, property_name, value):
if property_name == "lockscreen":
logger.debug('[DBUS]::Set(%s, %s)', property_name, value)
self._lockscreen = bool(value)
logger.info('extension is in %s mode', 'lockscreen' if self._lockscreen else 'desktop')
else:
logger.warning('[DBUS] Unknown property for interface %s', property_name, interface_name)
raise Exception("failed to set %s::%s" % (interface_name, property_name))
return True

def _handle_preview(self, obj, uri):
if isinstance(obj, LockscreenProfile) and not self._lockscreen:
logger.debug('ignoring preview %s::preview in desktop mode', str(obj))
Expand Down
2 changes: 1 addition & 1 deletion [email protected]/deskchanger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def info(message, *args):

def log(level, message, *args):
message = str(message) % args
GLib.log_default_handler(None, level, message, None)
GLib.log_default_handler("", level, message, 0)


def warning(message, *args):
Expand Down
4 changes: 3 additions & 1 deletion [email protected]/deskchanger/wallpapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def next(self, current=None):
wallpaper = self._queue.pop(0)
if current:
self._history.append(current)
if not self._settings.get_boolean('random'):
self._position += 1
self._load_next()
self.emit('preview', self._queue[0])
return wallpaper
Expand Down Expand Up @@ -131,7 +133,7 @@ def restore_state(self):
return
self._queue = list(states[self.name])
if not self._settings.get_boolean('random'):
self._position = self._wallpapers.index(self._queue[0])
self._position = self._wallpapers.index(self._queue[len(self._queue) - 1])
del states[self.name]
self._settings.set_value('profile-state', GLib.Variant('a{s(ss)}', states))

Expand Down
10 changes: 7 additions & 3 deletions [email protected]/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ const DeskChangerControls = new Lang.Class({

next: function () {
debug('next');
this._dbus.NextSync();
this._dbus.NextRemote(function (result, error) {
if (error) {
Main.notifyError('Desk Changer', error);
}
});
},

prev: function() {
debug('prev');
this._dbus.PrevRemote(function (result) {
if (result[0].length == 0) {
this._dbus.PrevRemote(function (result, error) {
if (error) {
Main.notifyError('Desk Changer', 'Unable to go back any further, no history available');
}
});
Expand Down
9 changes: 1 addition & 8 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
"description": "Simple wallpaper changer with multiple profile support. Supports integration into the system menu or its own panel icon. The daemon is written in Python and runs independently of the extension.",
"name": "Desk Changer",
"shell-version": [
"3.8",
"3.10",
"3.11.90",
"3.11.92",
"3.12",
"3.14",
"3.16",
"3.18",
"3.20",
"3.21.91",
Expand All @@ -17,5 +10,5 @@
],
"url": "https://github.com/BigE/desk-changer/",
"uuid": "[email protected]",
"version": "22"
"version": "23"
}

0 comments on commit 7fc9ef7

Please sign in to comment.