Skip to content

Commit

Permalink
check here system in thread to avoid blocking UI
Browse files Browse the repository at this point in the history
Signed-off-by: minff <[email protected]>
  • Loading branch information
minff committed Feb 26, 2024
1 parent a71755a commit 74ee707
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
9 changes: 8 additions & 1 deletion XYZHubConnector/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from qgis.core import QgsProject, QgsApplication
from qgis.core import Qgis, QgsMessageLog

from qgis.PyQt.QtCore import QCoreApplication, Qt
from qgis.PyQt.QtCore import QCoreApplication, Qt, QThreadPool
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtWidgets import QProgressBar
Expand All @@ -36,6 +36,7 @@
make_fun_args,
parse_exception_obj,
ChainInterrupt,
WorkerFun,
)

from .xyz_qgis.loader import (
Expand Down Expand Up @@ -112,8 +113,14 @@ def __init__(self, iface):
self.web_menu = "&{name}".format(name=config.PLUGIN_FULL_NAME)
self.hasGuiInitialized = False
self.init_modules()
self.init_in_thread()
self.obj = self

def init_in_thread(self):
self.pool = QThreadPool()
fn = WorkerFun(utils.is_here_system, self.pool)
fn.call(make_qt_args())

def initGui(self):
"""startup"""

Expand Down
19 changes: 19 additions & 0 deletions XYZHubConnector/xyz_qgis/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Config:
EXTERNAL_LIB_DIR = os.path.join(PLUGIN_DIR, "external")
PYTHON_LOG_FILE = os.path.join(USER_DIR, PLUGIN_NAME, "python.log")

def __init__(self):
self._is_here_system = None

def set_config(self, config):
for k, v in config.items():
setattr(self, k, v)
Expand All @@ -42,3 +45,19 @@ def get_plugin_setting(self, key):
key_prefix = "xyz_qgis/settings"
key_ = f"{key_prefix}/{key}"
return QSettings().value(key_)

def _check_here_system(self):
import socket
from .crypter import decrypt_text

socket.setdefaulttimeout(1)
is_here_domain = decrypt_text("Vi5tWQcgFl88Wzg=") in socket.getfqdn()
return is_here_domain

def is_here_system(self):
if self._is_here_system is None:
try:
self._is_here_system = self._check_here_system()
except Exception as e:
print(e)
return self._is_here_system
6 changes: 1 addition & 5 deletions XYZHubConnector/xyz_qgis/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,4 @@ def get_qml_import_base_path():


def is_here_system():
import socket
from .crypter import decrypt_text

is_here_domain = decrypt_text("Vi5tWQcgFl88Wzg=") in socket.getfqdn()
return is_here_domain
return config.is_here_system()

0 comments on commit 74ee707

Please sign in to comment.