From ef297bbf4b1d0dffa88d5c689927fd1331b63bb1 Mon Sep 17 00:00:00 2001 From: Manu <3916435+m3nu@users.noreply.github.com> Date: Fri, 20 Jan 2023 12:25:58 +0100 Subject: [PATCH] Avoid autostart warning when autostart disabled (#1549) --- .github/workflows/test.yml | 10 +++------- Makefile | 8 ++++++++ setup.cfg | 6 +++--- src/vorta/autostart.py | 17 ++++++++++++++--- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ae3c875..af09dbf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,10 +24,7 @@ jobs: pip install . pip install -r requirements.d/dev.txt - name: Test formatting with Flake8, isort and Black - run: | - flake8 - isort --check-only . - black --check . + run: make lint # - name: Run PyLint (info only) # run: pylint --rcfile=setup.cfg src --exit-zero @@ -85,11 +82,10 @@ jobs: if: runner.os == 'Linux' run: | xvfb-run --server-args="-screen 0 1024x768x24+32" \ - -a dbus-run-session -- pytest --cov=vorta + -a dbus-run-session -- make test - name: Test with pytest (macOS) if: runner.os == 'macOS' - run: | - pytest --cov=vorta + run: make test - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 diff --git a/Makefile b/Makefile index 92b394bb..d1d793e2 100644 --- a/Makefile +++ b/Makefile @@ -56,5 +56,13 @@ flatpak-install: translations-to-qm install -D package/icon-symbolic.svg ${FLATPAK_DEST}/share/icons/hicolor/symbolic/apps/com.borgbase.Vorta-symbolic.svg install -D src/vorta/assets/metadata/com.borgbase.Vorta.desktop ${FLATPAK_DEST}/share/applications/com.borgbase.Vorta.desktop +lint: + flake8 + isort --check-only . + black --check . + +test: + pytest --cov=vorta + help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' diff --git a/setup.cfg b/setup.cfg index 31c752e4..cf827994 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,9 +46,9 @@ install_requires = psutil setuptools secretstorage; sys_platform != 'darwin' - pyobjc-core<9.0; sys_platform == 'darwin' - pyobjc-framework-Cocoa<9.0; sys_platform == 'darwin' - pyobjc-framework-LaunchServices<9.0; sys_platform == 'darwin' + pyobjc-core; sys_platform == 'darwin' + pyobjc-framework-Cocoa; sys_platform == 'darwin' + pyobjc-framework-LaunchServices; sys_platform == 'darwin' tests_require = pytest pytest-qt diff --git a/src/vorta/autostart.py b/src/vorta/autostart.py index 65aaec68..096d13b3 100644 --- a/src/vorta/autostart.py +++ b/src/vorta/autostart.py @@ -17,11 +17,14 @@ def open_app_at_startup(enabled=True): # CF = CDLL(find_library('CoreFoundation')) from LaunchServices import ( + LSSharedFileListCopySnapshot, LSSharedFileListCreate, LSSharedFileListInsertItemURL, LSSharedFileListItemRemove, + LSSharedFileListItemResolve, kLSSharedFileListItemHidden, kLSSharedFileListItemLast, + kLSSharedFileListNoUserInteraction, kLSSharedFileListSessionLoginItems, ) @@ -30,9 +33,17 @@ def open_app_at_startup(enabled=True): login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None) props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden) - new_item = LSSharedFileListInsertItemURL(login_items, kLSSharedFileListItemLast, None, None, url, props, None) - if not enabled: - LSSharedFileListItemRemove(login_items, new_item) + if enabled: + LSSharedFileListInsertItemURL(login_items, kLSSharedFileListItemLast, None, None, url, props, None) + else: + # From https://github.com/pudquick/pyLoginItems/blob/master/pyLoginItems.py + list_ref = LSSharedFileListCreate(None, kLSSharedFileListSessionLoginItems, None) + login_items, _ = LSSharedFileListCopySnapshot(list_ref, None) + flags = kLSSharedFileListNoUserInteraction + kLSSharedFileListNoUserInteraction + for i in login_items: + err, a_CFURL, a_FSRef = LSSharedFileListItemResolve(i, flags, None, None) + if 'Vorta.app' in str(a_CFURL): + LSSharedFileListItemRemove(list_ref, i) elif sys.platform.startswith('linux'): from pathlib import Path