From c51108e867741d0fbfea2800079b373bfaf0cb81 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 6 May 2019 18:30:21 +0300 Subject: [PATCH] Entry point 'desktop' for plugins managing desktop environment; desktop_xdg will do it with pyxdg. Fixes: #857 --- setup.py | 8 +++++-- src/bitmessageqt/__init__.py | 43 +++++++++++++++++++++--------------- src/bitmessageqt/settings.py | 7 +++--- src/plugins/desktop_xdg.py | 31 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 24 deletions(-) create mode 100644 src/plugins/desktop_xdg.py diff --git a/setup.py b/setup.py index efb5abfc..7a3bcf6a 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ from src.version import softwareVersion EXTRAS_REQUIRE = { + 'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'], 'gir': ['pygobject'], 'json': ['jsonrpclib'], 'notify2': ['notify2'], @@ -20,8 +21,8 @@ EXTRAS_REQUIRE = { 'qrcode': ['qrcode'], 'sound;platform_system=="Windows"': ['winsound'], 'tor': ['stem'], - 'xml': ['defusedxml'], - 'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'] + 'xdg': ['pyxdg'], + 'xml': ['defusedxml'] } @@ -153,6 +154,9 @@ if __name__ == "__main__": 'libmessaging =' 'pybitmessage.plugins.indicator_libmessaging [gir]' ], + 'bitmessage.desktop': [ + 'freedesktop = pybitmessage.plugins.desktop_xdg [xdg]' + ], 'bitmessage.proxyconfig': [ 'stem = pybitmessage.plugins.proxyconfig_stem [tor]' ], diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 25f5cb8d..38bed4f2 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -640,8 +640,6 @@ class MyForm(settingsmixin.SMainWindow): BMConfigParser().remove_section(addressInKeysFile) BMConfigParser().save() - self.updateStartOnLogon() - self.change_translation() # e.g. for editing labels @@ -826,6 +824,7 @@ class MyForm(settingsmixin.SMainWindow): self.sqlInit() self.indicatorInit() self.notifierInit() + self.updateStartOnLogon() self.ui.updateNetworkSwitchMenuLabel() @@ -844,26 +843,25 @@ class MyForm(settingsmixin.SMainWindow): self._contact_selected = None def updateStartOnLogon(self): - # Configure Bitmessage to start on startup (or remove the - # configuration) based on the setting in the keys.dat file + """ + Configure Bitmessage to start on startup (or remove the + configuration) based on the setting in the keys.dat file + """ + startonlogon = BMConfigParser().safeGetBoolean( + 'bitmessagesettings', 'startonlogon') if 'win32' in sys.platform or 'win64' in sys.platform: # Auto-startup for Windows RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" - self.settings = QtCore.QSettings( + settings = QtCore.QSettings( RUN_PATH, QtCore.QSettings.NativeFormat) # In case the user moves the program and the registry entry is # no longer valid, this will delete the old registry entry. - self.settings.remove("PyBitmessage") - if BMConfigParser().getboolean( - 'bitmessagesettings', 'startonlogon' - ): - self.settings.setValue("PyBitmessage", sys.argv[0]) - elif 'darwin' in sys.platform: - # startup for mac - pass - elif 'linux' in sys.platform: - # startup for linux - pass + if startonlogon: + settings.setValue("PyBitmessage", sys.argv[0]) + else: + settings.remove("PyBitmessage") + elif self.desktop: + self.desktop.adjust_startonlogon(startonlogon) def updateTTL(self, sliderPosition): TTL = int(sliderPosition ** 3.199 + 3600) @@ -1423,12 +1421,21 @@ class MyForm(settingsmixin.SMainWindow): def sqlInit(self): register_adapter(QtCore.QByteArray, str) - # Try init the distro specific appindicator, - # for example the Ubuntu MessagingMenu def indicatorInit(self): + """ + Try init the distro specific appindicator, + for example the Ubuntu MessagingMenu + """ def _noop_update(*args, **kwargs): pass + # get desktop plugin if any + if 'win' not in sys.platform: + try: + self.desktop = get_plugin('desktop')() + except TypeError: + self.desktop = False + try: self.indicatorUpdate = get_plugin('indicator')(self) except (NameError, TypeError): diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index f1c1a11f..6a93e2f0 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -119,9 +119,6 @@ class SettingsDialog(QtGui.QDialog): self.checkBoxPortableMode.setDisabled(True) if 'darwin' in sys.platform: - self.checkBoxStartOnLogon.setDisabled(True) - self.checkBoxStartOnLogon.setText(_translate( - "MainWindow", "Start-on-login not yet supported on your OS.")) self.checkBoxMinimizeToTray.setDisabled(True) self.checkBoxMinimizeToTray.setText(_translate( "MainWindow", @@ -130,10 +127,12 @@ class SettingsDialog(QtGui.QDialog): self.checkBoxShowTrayNotifications.setText(_translate( "MainWindow", "Tray notifications not yet supported on your OS.")) - elif 'linux' in sys.platform: + + if 'win' not in sys.platform and not self.parent.desktop: self.checkBoxStartOnLogon.setDisabled(True) self.checkBoxStartOnLogon.setText(_translate( "MainWindow", "Start-on-login not yet supported on your OS.")) + # On the Network settings tab: self.lineEditTCPPort.setText(str( config.get('bitmessagesettings', 'port'))) diff --git a/src/plugins/desktop_xdg.py b/src/plugins/desktop_xdg.py new file mode 100644 index 00000000..3dbd212f --- /dev/null +++ b/src/plugins/desktop_xdg.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import os + +from xdg import BaseDirectory, Menu + + +class DesktopXDG(object): + """pyxdg Freedesktop desktop implementation""" + def __init__(self): + menu_entry = Menu.parse().getMenu('Office').getMenuEntry( + 'pybitmessage.desktop') + self.desktop = menu_entry.DesktopEntry if menu_entry else None + + def adjust_startonlogon(self, autostart=False): + """Configure autostart according to settings""" + if not self.desktop: + return + + autostart_path = os.path.join( + BaseDirectory.xdg_config_home, 'autostart', 'pybitmessage.desktop') + if autostart: + self.desktop.write(autostart_path) + else: + try: + os.remove(autostart_path) + except OSError: + pass + + +connect_plugin = DesktopXDG