Skip to content

Commit

Permalink
Move pyobjc imports to module level II
Browse files Browse the repository at this point in the history
  • Loading branch information
m3nu committed Apr 17, 2023
1 parent 7302bfa commit 278cf43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/vorta/autostart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

try:
from Cocoa import NSURL, NSBundle
from CoreFoundation import kCFAllocatorDefault
Expand Down Expand Up @@ -27,7 +28,7 @@ def open_app_at_startup(enabled=True):
On macOS, this function adds/removes the current app bundle from Login items
while on Linux it adds a .desktop file at ~/.config/autostart
"""
if sys.platform == 'darwin':
if sys.platform == 'darwinxx':
app_path = NSBundle.mainBundle().bundlePath()
url = NSURL.alloc().initFileURLWithPath_(app_path)
login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
Expand Down
7 changes: 3 additions & 4 deletions src/vorta/keyring/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"""
import logging
import sys
from ctypes import c_char
import objc
from Foundation import NSBundle
from .abc import VortaKeyring

logger = logging.getLogger(__name__)
Expand All @@ -23,8 +26,6 @@ def _set_keychain(self):
"""
Lazy import to avoid conflict with pytest-xdist.
"""
import objc
from Foundation import NSBundle

Security = NSBundle.bundleWithIdentifier_('com.apple.security')

Expand Down Expand Up @@ -121,7 +122,5 @@ def is_system(self):


def _resolve_password(password_length, password_buffer):
from ctypes import c_char

s = (c_char * password_length).from_address(password_buffer.__pointer__)[:]
return s.decode()
7 changes: 5 additions & 2 deletions src/vorta/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from PyQt6 import QtCore, QtDBus
from vorta.store.models import SettingsModel

try:
from Foundation import NSUserNotification, NSUserNotificationCenter
except ImportError:
pass

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -50,8 +55,6 @@ def deliver(self, title, text, level='info'):
if self.notifications_suppressed(level):
return

from Foundation import NSUserNotification, NSUserNotificationCenter

notification = NSUserNotification.alloc().init()
notification.setTitle_(title)
notification.setInformativeText_(text)
Expand Down

0 comments on commit 278cf43

Please sign in to comment.