Entry point 'desktop' for plugins managing desktop environment;

desktop_xdg will do it with pyxdg. Fixes: #857
This commit is contained in:
Dmitri Bogomolov 2019-05-06 18:30:21 +03:00
parent 74e039de5d
commit c51108e867
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
4 changed files with 65 additions and 24 deletions

View File

@ -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]'
],

View File

@ -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):

View File

@ -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')))

View File

@ -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