Merge pull request #776 from gpodder/ubuntu-extensions
Fix ubuntu/unity extensions
This commit is contained in:
commit
1d5c2c028e
|
@ -114,8 +114,8 @@ def main():
|
|||
|
||||
desktop_session = os.environ.get('DESKTOP_SESSION', 'unknown').lower()
|
||||
xdg_current_desktop = os.environ.get('XDG_CURRENT_DESKTOP', 'unknown').lower()
|
||||
gpodder.ui.unity = (desktop_session in ('ubuntu', 'ubuntu-2d')
|
||||
and xdg_current_desktop == 'unity')
|
||||
gpodder.ui.unity = (desktop_session in ('ubuntu', 'ubuntu-2d', 'unity')
|
||||
and xdg_current_desktop in ('unity', 'unity:unity7:ubuntu'))
|
||||
|
||||
from gpodder import log
|
||||
log.setup(options.verbose)
|
||||
|
|
|
@ -11,7 +11,13 @@ import sys
|
|||
import gpodder
|
||||
from gpodder import util
|
||||
|
||||
import gi # isort:skip
|
||||
gi.require_version('Unity', '7.0') # isort:skip
|
||||
from gi.repository import GObject, Unity # isort:skip
|
||||
|
||||
|
||||
_ = gpodder.gettext
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
__title__ = _('Ubuntu Unity Integration')
|
||||
__description__ = _('Show download progress in the Unity Launcher icon.')
|
||||
|
@ -22,86 +28,35 @@ __mandatory_in__ = 'unity'
|
|||
__disable_in__ = 'win32'
|
||||
|
||||
|
||||
# FIXME: Due to the fact that we do not yet use the GI-style bindings, we will
|
||||
# have to run this module in its own interpreter and send commands to it using
|
||||
# the subprocess module. Once we use GI-style bindings, we can get rid of all
|
||||
# this and still expose the same "interface' (LauncherEntry and its methods)
|
||||
# to our callers.
|
||||
class LauncherEntry:
|
||||
FILENAME = 'gpodder.desktop'
|
||||
|
||||
def __init__(self):
|
||||
self.launcher = Unity.LauncherEntry.get_for_desktop_id(
|
||||
self.FILENAME)
|
||||
|
||||
def set_count(self, count):
|
||||
self.launcher.set_property('count', count)
|
||||
self.launcher.set_property('count_visible', count > 0)
|
||||
|
||||
def set_progress(self, progress):
|
||||
self.launcher.set_property('progress', progress)
|
||||
self.launcher.set_property('progress_visible', 0. <= progress < 1.)
|
||||
|
||||
|
||||
if __name__ != '__main__':
|
||||
logger = logging.getLogger(__name__)
|
||||
class gPodderExtension:
|
||||
FILENAME = 'gpodder.desktop'
|
||||
|
||||
class gPodderExtension:
|
||||
FILENAME = 'gpodder.desktop'
|
||||
def __init__(self, container):
|
||||
self.container = container
|
||||
self.launcher_entry = None
|
||||
|
||||
def __init__(self, container):
|
||||
self.container = container
|
||||
self.process = None
|
||||
def on_load(self):
|
||||
logger.info('Starting Ubuntu Unity Integration.')
|
||||
self.launcher_entry = LauncherEntry()
|
||||
|
||||
def on_load(self):
|
||||
logger.info('Starting Ubuntu Unity Integration.')
|
||||
os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
|
||||
self.process = util.Popen(['python', __file__],
|
||||
stdin=subprocess.PIPE)
|
||||
def on_unload(self):
|
||||
self.launcher_entry = None
|
||||
|
||||
def on_unload(self):
|
||||
logger.info('Killing process...')
|
||||
self.process.terminate()
|
||||
self.process.wait()
|
||||
logger.info('Process killed.')
|
||||
|
||||
def on_download_progress(self, progress):
|
||||
try:
|
||||
self.process.stdin.write('progress %f\n' % progress)
|
||||
self.process.stdin.flush()
|
||||
except Exception as e:
|
||||
logger.debug('Ubuntu progress update failed.', exc_info=True)
|
||||
else:
|
||||
from gi.repository import Unity, GObject
|
||||
from gpodder import util
|
||||
import sys
|
||||
|
||||
class InputReader:
|
||||
def __init__(self, fileobj, launcher):
|
||||
self.fileobj = fileobj
|
||||
self.launcher = launcher
|
||||
|
||||
def read(self):
|
||||
while True:
|
||||
line = self.fileobj.readline()
|
||||
if not line:
|
||||
break
|
||||
|
||||
try:
|
||||
command, value = line.strip().split()
|
||||
if command == 'progress':
|
||||
GObject.idle_add(launcher_entry.set_progress,
|
||||
float(value))
|
||||
except:
|
||||
pass
|
||||
|
||||
class LauncherEntry:
|
||||
FILENAME = 'gpodder.desktop'
|
||||
|
||||
def __init__(self):
|
||||
self.launcher = Unity.LauncherEntry.get_for_desktop_id(
|
||||
self.FILENAME)
|
||||
|
||||
def set_count(self, count):
|
||||
self.launcher.set_property('count', count)
|
||||
self.launcher.set_property('count_visible', count > 0)
|
||||
|
||||
def set_progress(self, progress):
|
||||
self.launcher.set_property('progress', progress)
|
||||
self.launcher.set_property('progress_visible', 0. <= progress < 1.)
|
||||
|
||||
GObject.threads_init()
|
||||
loop = GObject.MainLoop()
|
||||
util.run_in_background(loop.run)
|
||||
|
||||
launcher_entry = LauncherEntry()
|
||||
reader = InputReader(sys.stdin, launcher_entry)
|
||||
reader.read()
|
||||
|
||||
loop.quit()
|
||||
def on_download_progress(self, progress):
|
||||
GObject.idle_add(self.launcher_entry.set_progress, float(value))
|
||||
|
|
Loading…
Reference in a new issue