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 @@ from dateutil import parser
import subprocess
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 .borg_thread import BorgThread
@ -78,6 +78,7 @@ class BorgCreateThread(BorgThread):
ret['message'] = trans_late('messages', 'Add some folders to back up first.')
return ret
network_status_monitor = get_network_status_monitor()
current_wifi = network_status_monitor.get_current_wifi()
if current_wifi is not None:
wifi_is_disallowed = WifiSettingModel.select().where(

View File

@ -29,12 +29,20 @@ QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True) # use highdpi i
keyring = VortaKeyring.get_keyring()
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()
_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():
"""
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
system_wifis = network_status_monitor.get_known_wifis()
system_wifis = get_network_status_monitor().get_known_wifis()
if system_wifis is None:
# Don't show any networks if we can't get the current list
return []

View File

@ -5,7 +5,7 @@ from PyQt5.QtGui import QKeySequence
from vorta.borg.borg_thread import BorgThread
from vorta.i18n import trans_late
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.partials.loading_button import LoadingButton
@ -79,7 +79,7 @@ class MainWindow(MainWindowBase, MainWindowUI):
self.profileAddButton.clicked.connect(self.profile_add_action)
# 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.
self.scheduleTab.wifiListLabel.hide()
self.scheduleTab.wifiListWidget.hide()