From 60903c2515391384b67f9d3a7c6d5c810db0e946 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 27 Mar 2018 13:31:12 +0200 Subject: [refactor] move autostart code into core All the logic to autostart bitmask should not be vpn dependent. --- src/leap/bitmask/core/autostart.py | 45 +++++++++++++++++++++++++++++++++++++ src/leap/bitmask/core/dispatcher.py | 3 +++ 2 files changed, 48 insertions(+) create mode 100644 src/leap/bitmask/core/autostart.py (limited to 'src/leap/bitmask/core') diff --git a/src/leap/bitmask/core/autostart.py b/src/leap/bitmask/core/autostart.py new file mode 100644 index 00000000..1c361d82 --- /dev/null +++ b/src/leap/bitmask/core/autostart.py @@ -0,0 +1,45 @@ +import os +import os.path + +from leap.bitmask.system import IS_LINUX, IS_MAC +from leap.bitmask.util import STANDALONE +from leap.common.config import get_path_prefix + +if IS_LINUX: + AUTOSTART = r"""[Desktop Entry] +Name=Bitmask +Type=Application +Exec=bitmask +Terminal=false +""" + config = get_path_prefix(standalone=False) + autostart_file = os.path.join(config, 'autostart', 'bitmask.desktop') + + def autostart_app(status): + """ + Leave an autostart file in the user's autostart path. + + The bundle could in principle find its own path and add + the path to the bitmaskd binary in the Exec entry. + But for now it's simpler to do autostart only for the debian packages + or any other method that puts bitmask in the path. + On the other hand, we want to reduce the modifications that the bundle + leaves behind. + """ + if not STANDALONE: + if status == 'on': + _dir = os.path.split(autostart_file)[0] + if not os.path.isdir(_dir): + os.makedirs(_dir) + with open(autostart_file, 'w') as f: + f.write(AUTOSTART) + elif status == 'off': + try: + os.unlink(autostart_file) + except OSError: + pass + +if IS_MAC: + + def autostart_app(status): + pass diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index 20c0615b..a4b8ce39 100644 --- a/src/leap/bitmask/core/dispatcher.py +++ b/src/leap/bitmask/core/dispatcher.py @@ -33,6 +33,7 @@ from leap.common.events import unregister_async as unregister from leap.common.events import catalog from .api import APICommand, register_method +from .autostart import autostart_app log = Logger() @@ -196,11 +197,13 @@ class VPNCmd(SubCommand): except IndexError: provider = None d = vpn.start_vpn(provider) + autostart_app('on') return d @register_method('dict') def do_STOP(self, vpn, *parts): d = vpn.stop_vpn() + autostart_app('off') return d @register_method('dict') -- cgit v1.2.3