From 8f5953b3b49add59b79d4b2f0fbacfcd460b5385 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Fri, 3 May 2019 20:57:05 +0200 Subject: [PATCH] Make Flatpak Ready 1) Change socket-file path so that Flatpaks has access 2) Change autostart function so that it detects if it is run as Flatpak --- src/vorta/application.py | 10 ++++++---- src/vorta/autostart.py | 20 +++++++++++++++----- src/vorta/config.py | 4 ++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index c9d75341..fe595f9d 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -1,8 +1,12 @@ +import os import sys import qdarkstyle from PyQt5 import QtCore + import sip +from vorta.borg.version import BorgVersionThread +from vorta.config import STATE_DIR from .borg.create import BorgCreateThread from .i18n import init_translations, translate @@ -10,12 +14,10 @@ from .qt_single_application import QtSingleApplication from .scheduler import VortaScheduler from .tray_menu import TrayMenu -from .utils import parse_args, set_tray_icon, borg_compat +from .utils import borg_compat, parse_args, set_tray_icon from .views.main_window import MainWindow -from vorta.borg.version import BorgVersionThread - -APP_ID = "vorta" +APP_ID = os.path.join(STATE_DIR, "socket") class VortaApp(QtSingleApplication): diff --git a/src/vorta/autostart.py b/src/vorta/autostart.py index f0bc20a1..fb7fc567 100644 --- a/src/vorta/autostart.py +++ b/src/vorta/autostart.py @@ -1,18 +1,18 @@ import sys from pathlib import Path -from PyQt5 import QtCore LINUX_STARTUP_FILE = """\ [Desktop Entry] Name=Vorta GenericName=Backup Software -Exec=vorta +Exec={} Terminal=false Icon=vorta Categories=Utility Type=Application StartupNotify=false X-GNOME-Autostart-enabled=true +X-GNOME-Autostart-Delay=20 """ @@ -41,10 +41,20 @@ def open_app_at_startup(enabled=True): LSSharedFileListItemRemove(login_items, new_item) elif sys.platform.startswith('linux'): - config_path = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.ConfigLocation) - autostart_file_path = Path(config_path) / 'autostart' / 'vorta.desktop' + autostart_path = Path.home() / '.config' / 'autostart' + + if not autostart_path.exists(): + autostart_path.mkdir() + + autostart_file_path = autostart_path / 'vorta.desktop' + if enabled: - autostart_file_path.write_text(LINUX_STARTUP_FILE) + if Path('/.flatpak-info').exists(): + # Vorta runs as flatpak + autostart_file_path.write_text(LINUX_STARTUP_FILE.format('flatpak run com.borgbase.vorta')) + else: + autostart_file_path.write_text(LINUX_STARTUP_FILE.format('vorta')) + else: if autostart_file_path.exists(): autostart_file_path.unlink() diff --git a/src/vorta/config.py b/src/vorta/config.py index 01ec8006..f4e1371a 100644 --- a/src/vorta/config.py +++ b/src/vorta/config.py @@ -6,9 +6,13 @@ dirs = appdirs.AppDirs(APP_NAME, APP_AUTHOR) SETTINGS_DIR = dirs.user_data_dir LOG_DIR = dirs.user_log_dir +STATE_DIR = dirs.user_state_dir if not os.path.exists(SETTINGS_DIR): os.makedirs(SETTINGS_DIR) if not os.path.exists(LOG_DIR): os.makedirs(LOG_DIR) + +if not os.path.exists(STATE_DIR): + os.makedirs(STATE_DIR)