1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-01-03 13:45:49 +00:00

Initialize the network status monitor lazily (#634)

This avoids problems with `vorta -d` and fork.
This commit is contained in:
Tomasz Kontusz 2020-09-09 02:22:54 +02:00 committed by GitHub
parent 1b4dea3133
commit 23374876d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View file

@ -4,7 +4,7 @@
import subprocess import subprocess
from vorta.i18n import trans_late from vorta.i18n import trans_late
from vorta.utils import format_archive_name, borg_compat, network_status_monitor from vorta.utils import format_archive_name, borg_compat, get_network_status_monitor
from vorta.models import SourceFileModel, ArchiveModel, WifiSettingModel, RepoModel from vorta.models import SourceFileModel, ArchiveModel, WifiSettingModel, RepoModel
from .borg_thread import BorgThread from .borg_thread import BorgThread
@ -78,6 +78,7 @@ def prepare(cls, profile):
ret['message'] = trans_late('messages', 'Add some folders to back up first.') ret['message'] = trans_late('messages', 'Add some folders to back up first.')
return ret return ret
network_status_monitor = get_network_status_monitor()
current_wifi = network_status_monitor.get_current_wifi() current_wifi = network_status_monitor.get_current_wifi()
if current_wifi is not None: if current_wifi is not None:
wifi_is_disallowed = WifiSettingModel.select().where( wifi_is_disallowed = WifiSettingModel.select().where(

View file

@ -29,12 +29,20 @@
keyring = VortaKeyring.get_keyring() keyring = VortaKeyring.get_keyring()
logger.info('Using %s Keyring implementation.', keyring.__class__.__name__) logger.info('Using %s Keyring implementation.', keyring.__class__.__name__)
network_status_monitor = NetworkStatusMonitor.get_network_status_monitor()
logger.info('Using %s NetworkStatusMonitor implementation.', network_status_monitor.__class__.__name__)
borg_compat = BorgCompatibility() borg_compat = BorgCompatibility()
_network_status_monitor = None
def get_network_status_monitor():
global _network_status_monitor
if _network_status_monitor is None:
_network_status_monitor = NetworkStatusMonitor.get_network_status_monitor()
logger.info('Using %s NetworkStatusMonitor implementation.', _network_status_monitor.__class__.__name__)
return _network_status_monitor
def nested_dict(): def nested_dict():
""" """
Combination of two idioms to quickly build dicts from lists of keys: Combination of two idioms to quickly build dicts from lists of keys:
@ -127,7 +135,7 @@ def get_sorted_wifis(profile):
from vorta.models import WifiSettingModel from vorta.models import WifiSettingModel
system_wifis = network_status_monitor.get_known_wifis() system_wifis = get_network_status_monitor().get_known_wifis()
if system_wifis is None: if system_wifis is None:
# Don't show any networks if we can't get the current list # Don't show any networks if we can't get the current list
return [] return []

View file

@ -5,7 +5,7 @@
from vorta.borg.borg_thread import BorgThread from vorta.borg.borg_thread import BorgThread
from vorta.i18n import trans_late from vorta.i18n import trans_late
from vorta.models import BackupProfileModel, SettingsModel from vorta.models import BackupProfileModel, SettingsModel
from vorta.utils import borg_compat, get_asset, is_system_tray_available, network_status_monitor from vorta.utils import borg_compat, get_asset, is_system_tray_available, get_network_status_monitor
from vorta.views.utils import get_colored_icon from vorta.views.utils import get_colored_icon
from vorta.views.partials.loading_button import LoadingButton from vorta.views.partials.loading_button import LoadingButton
@ -79,7 +79,7 @@ def __init__(self, parent=None):
self.profileAddButton.clicked.connect(self.profile_add_action) self.profileAddButton.clicked.connect(self.profile_add_action)
# OS-specific startup options: # OS-specific startup options:
if not network_status_monitor.is_network_status_available(): if not get_network_status_monitor().is_network_status_available():
# Hide Wifi-rule section in schedule tab. # Hide Wifi-rule section in schedule tab.
self.scheduleTab.wifiListLabel.hide() self.scheduleTab.wifiListLabel.hide()
self.scheduleTab.wifiListWidget.hide() self.scheduleTab.wifiListWidget.hide()