mirror of https://github.com/borgbase/vorta
Refactor Linux autostart (#568)
This commit is contained in:
parent
976e3dae83
commit
3d7d97fc40
|
@ -1,19 +1,10 @@
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
LINUX_STARTUP_FILE = """\
|
AUTOSTART_DELAY = """StartupNotify=false
|
||||||
[Desktop Entry]
|
|
||||||
Name=Vorta
|
|
||||||
GenericName=Backup Software
|
|
||||||
Exec={} --daemonize
|
|
||||||
Terminal=false
|
|
||||||
Icon=com.borgbase.Vorta
|
|
||||||
Categories=Utility
|
|
||||||
Type=Application
|
|
||||||
StartupNotify=false
|
|
||||||
X-GNOME-Autostart-enabled=true
|
X-GNOME-Autostart-enabled=true
|
||||||
X-GNOME-Autostart-Delay=20
|
X-GNOME-Autostart-Delay=20"""
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
def open_app_at_startup(enabled=True):
|
def open_app_at_startup(enabled=True):
|
||||||
|
@ -42,20 +33,33 @@ def open_app_at_startup(enabled=True):
|
||||||
LSSharedFileListItemRemove(login_items, new_item)
|
LSSharedFileListItemRemove(login_items, new_item)
|
||||||
|
|
||||||
elif sys.platform.startswith('linux'):
|
elif sys.platform.startswith('linux'):
|
||||||
autostart_path = Path.home() / '.config' / 'autostart'
|
is_flatpak = Path('/.flatpak-info').exists()
|
||||||
|
|
||||||
if not autostart_path.exists():
|
with open(os.path.join(os.path.dirname(__file__),
|
||||||
autostart_path.mkdir()
|
"assets/metadata/com.borgbase.Vorta.desktop")) as desktop_file:
|
||||||
|
desktop_file_text = desktop_file.read()
|
||||||
|
|
||||||
autostart_file_path = autostart_path / 'vorta.desktop'
|
# Find XDG_CONFIG_HOME unless when running in flatpak
|
||||||
|
if is_flatpak:
|
||||||
if enabled:
|
autostart_path = Path.home() / '.config' / 'autostart'
|
||||||
if Path('/.flatpak-info').exists():
|
|
||||||
# Vorta runs as flatpak
|
|
||||||
autostart_file_path.write_text(LINUX_STARTUP_FILE.format('flatpak run com.borgbase.Vorta'))
|
|
||||||
else:
|
else:
|
||||||
autostart_file_path.write_text(LINUX_STARTUP_FILE.format('vorta'))
|
autostart_path = Path(os.environ.get(
|
||||||
|
"XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart")
|
||||||
|
|
||||||
else:
|
if not autostart_path.exists():
|
||||||
if autostart_file_path.exists():
|
autostart_path.mkdir()
|
||||||
autostart_file_path.unlink()
|
|
||||||
|
autostart_file_path = autostart_path / 'vorta.desktop'
|
||||||
|
|
||||||
|
if enabled:
|
||||||
|
# Replace to for flatpak if appropriate and start in background
|
||||||
|
desktop_file_text = desktop_file_text.replace(
|
||||||
|
"Exec=vorta", "Exec=flatpak run com.borgbase.Vorta --daemonize" if is_flatpak
|
||||||
|
else "Exec=vorta --daemonize")
|
||||||
|
# Add autostart delay
|
||||||
|
desktop_file_text += (AUTOSTART_DELAY)
|
||||||
|
|
||||||
|
autostart_file_path.write_text(desktop_file_text)
|
||||||
|
else:
|
||||||
|
if autostart_file_path.exists():
|
||||||
|
autostart_file_path.unlink()
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
from PyQt5 import QtCore
|
||||||
|
from PyQt5.QtWidgets import QCheckBox
|
||||||
|
from pathlib import Path
|
||||||
|
import pytest
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.platform != 'linux', reason="Autostart files only generated in Linux")
|
||||||
|
def test_linux_autostart(qapp, qtbot):
|
||||||
|
main = qapp.main_window
|
||||||
|
main.tabWidget.setCurrentIndex(4)
|
||||||
|
tab = main.miscTab
|
||||||
|
|
||||||
|
for x in range(0, tab.checkboxLayout.count()):
|
||||||
|
checkbox = tab.checkboxLayout.itemAt(x).widget()
|
||||||
|
checkbox.__class__ = QCheckBox
|
||||||
|
if checkbox.text().startswith("Automatically"):
|
||||||
|
# Have to use pos to click checkbox correctly
|
||||||
|
# https://stackoverflow.com/questions/19418125/pysides-qtest-not-checking-box/24070484#24070484
|
||||||
|
qtbot.mouseClick(checkbox, QtCore.Qt.LeftButton, pos=QtCore.QPoint(2, checkbox.height() / 2))
|
||||||
|
break
|
||||||
|
|
||||||
|
autostart_path = Path(os.environ.get(
|
||||||
|
"XDG_CONFIG_HOME", os.path.expanduser("~") + '/.config') + "/autostart") / "vorta.desktop"
|
||||||
|
qtbot.waitUntil(lambda: autostart_path.exists(), timeout=5000)
|
||||||
|
|
||||||
|
with open(autostart_path) as desktop_file:
|
||||||
|
desktop_file_text = desktop_file.read()
|
||||||
|
|
||||||
|
assert(desktop_file_text.startswith("[Desktop Entry]"))
|
Loading…
Reference in New Issue