From 96103a97e30263d39aafa6a66fb46f62ee0a8a2c Mon Sep 17 00:00:00 2001 From: Manu Date: Sat, 8 Dec 2018 18:08:23 +0800 Subject: [PATCH] Implement selecting update channel (appcast.xml). --- src/vorta/models.py | 4 ++-- src/vorta/notifications.py | 18 ++++++++++-------- src/vorta/updater.py | 22 +++++++++++++++++++--- vorta.spec | 2 +- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/vorta/models.py b/src/vorta/models.py index 82e40813..44b65860 100644 --- a/src/vorta/models.py +++ b/src/vorta/models.py @@ -197,7 +197,7 @@ def init_db(con): if sys.platform == 'darwin': settings += [ {'key': 'autostart', 'value': False, 'type': 'checkbox', - 'label': 'Add Vorta to Login Items in Preferences > Users and Groups > Login Items. (not implemented)'}, + 'label': 'Add Vorta to Login Items in Preferences > Users and Groups > Login Items.'}, {'key': 'enable_notifications', 'value': True, 'type': 'checkbox', 'label': 'Display notifications when background tasks fail.'}, {'key': 'check_for_updates', 'value': True, 'type': 'checkbox', @@ -206,7 +206,7 @@ def init_db(con): 'label': 'Include pre-release versions when checking for updates.'}, ] - for setting in settings: # Create missing settings and update labels. + for setting in settings: # Create missing settings and update labels. Leave setting values untouched. s, created = SettingsModel.get_or_create(key=setting['key'], defaults=setting) s.label = setting['label'] s.save() diff --git a/src/vorta/notifications.py b/src/vorta/notifications.py index f47d87db..60c200ea 100644 --- a/src/vorta/notifications.py +++ b/src/vorta/notifications.py @@ -1,4 +1,5 @@ import sys +from vorta.models import SettingsModel class VortaNotifications: @@ -20,15 +21,16 @@ class VortaNotifications: class DarwinNotifications(VortaNotifications): def deliver(self, title, text): - from Foundation import NSUserNotification - from Foundation import NSUserNotificationCenter + if SettingsModel.get(key='enable_notifications').value: + from Foundation import NSUserNotification + from Foundation import NSUserNotificationCenter - notification = NSUserNotification.alloc().init() - notification.setTitle_(title) - notification.setInformativeText_(text) - center = NSUserNotificationCenter.defaultUserNotificationCenter() - if center is not None: # Only works when run from app bundle. - center.deliverNotification_(notification) + notification = NSUserNotification.alloc().init() + notification.setTitle_(title) + notification.setInformativeText_(text) + center = NSUserNotificationCenter.defaultUserNotificationCenter() + if center is not None: # Only works when run from app bundle. + center.deliverNotification_(notification) class LinuxNotifications(VortaNotifications): diff --git a/src/vorta/updater.py b/src/vorta/updater.py index 5867918b..0ba3ebda 100644 --- a/src/vorta/updater.py +++ b/src/vorta/updater.py @@ -5,14 +5,30 @@ from vorta.models import SettingsModel def get_updater(): if sys.platform == 'darwin' and getattr(sys, 'frozen', False): - # Use sparkle framework on macOS. - # Examples: https://programtalk.com/python-examples/objc.loadBundle/ + """ + Use Sparkle framework on macOS. + + Settings: https://sparkle-project.org/documentation/customization/ + Examples: https://programtalk.com/python-examples/objc.loadBundle/ + + To debug: + $ defaults read com.borgbase.client.macos + """ + import objc + import Cocoa bundle_path = os.path.join(os.path.dirname(sys.executable), os.pardir, 'Frameworks', 'Sparkle.framework') objc.loadBundle('Sparkle', globals(), bundle_path) sparkle = SUUpdater.sharedUpdater() # noqa: F821 + + # A default Appcast URL is set in vorta.spec, when setting it here it's saved to defaults, + # so we need both cases. if SettingsModel.get(key='updates_include_beta').value: - sparkle.SharedUpdater.FeedURL = 'https://borgbase.github.io/vorta/appcast-pre.xml' + appcast_nsurl = Cocoa.NSURL.URLWithString_('https://borgbase.github.io/vorta/appcast-pre.xml') + else: + appcast_nsurl = Cocoa.NSURL.URLWithString_('https://borgbase.github.io/vorta/appcast.xml') + + sparkle.setFeedURL_(appcast_nsurl) if SettingsModel.get(key='check_for_updates').value: sparkle.setAutomaticallyChecksForUpdates_(True) diff --git a/vorta.spec b/vorta.spec index 63b7deec..9d3de6fa 100644 --- a/vorta.spec +++ b/vorta.spec @@ -46,7 +46,7 @@ app = BUNDLE(exe, 'CFBundleShortVersionString': '0.5.4', 'CFBundleVersion': '0.5.4', 'NSAppleEventsUsageDescription': 'Please allow', - 'SUFeedURL': 'https://borgbase.github.io/vorta/appcast-pre.xml' + 'SUFeedURL': 'https://borgbase.github.io/vorta/appcast.xml' }, ) if False: