Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def save_setting(self, key, new_value):
setting = SettingsModel.get(key=key)
setting.value = bool(new_value)
setting.save()
if key == 'autostart':
open_app_at_startup(new_value)
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 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
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'
def set_tray_icon(tray, active=False):
from vorta.models import SettingsModel
use_light_style = SettingsModel.get(key='use_light_icon').value
icon_name = f"icons/hdd-o{'-active' if active else ''}-{'light' if use_light_style else 'dark'}.png"
icon = QIcon(get_asset(icon_name))
tray.setIcon(icon)