/
desktop_xdg.py
33 lines (26 loc) · 1004 Bytes
/
desktop_xdg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
import os
from xdg import BaseDirectory, Menu, Exceptions
class DesktopXDG(object):
"""pyxdg Freedesktop desktop implementation"""
def __init__(self):
try:
self.desktop = Menu.parse().getMenu('Office').getMenuEntry(
'pybitmessage.desktop').DesktopEntry
except (AttributeError, Exceptions.ParsingError):
raise TypeError # TypeError disables startonlogon
appimage = os.getenv('APPIMAGE')
if appimage:
self.desktop.set('Exec', appimage)
def adjust_startonlogon(self, autostart=False):
"""Configure autostart according to settings"""
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