Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def notifications_suppressed(self, level):
"""Decide if notification is sent or not based on settings and level."""
if not SettingsModel.get(key='enable_notifications').value:
logger.debug('notifications suppressed')
return True
if level == 'info' and not SettingsModel.get(key='enable_notifications_success').value:
logger.debug('success notifications suppressed')
return True
logger.debug('notification not suppressed')
return False
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:
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)
sparkle.checkForUpdatesInBackground()
sparkle.setAutomaticallyDownloadsUpdates_(False)
return sparkle
else: # TODO: implement for Linux
return None
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(parent)
self.versionLabel.setText(__version__)
self.logLink.setText(f"<a>Log</a>")
for setting in SettingsModel.select().where(SettingsModel.type == 'checkbox'):
x = filter(lambda s: s['key'] == setting.key, get_misc_settings())
if not list(x): # Skip settings that aren't specified in vorta.models.
continue
b = QCheckBox(translate('settings', setting.label))
b.setCheckState(setting.value)
b.setTristate(False)
b.stateChanged.connect(lambda v, key=setting.key: self.save_setting(key, v))
self.checkboxLayout.addWidget(b)
def get_theme_class():
"""
Choose a package to import collection_rc from.
light = white icons, dark = black icons.
Defaults to dark icons (light theme) if DB isn't initialized yet.
"""
if SettingsModel._meta.database.obj is None:
return 'vorta.views.dark'
else:
use_light_icon = SettingsModel.get(key='use_dark_theme').value
return 'vorta.views.light' if use_light_icon else 'vorta.views.dark'