Revert "fix: eliminate blocking calls causing startup freezes and UI hangs"

This reverts commit b2a1046f9d.
This commit is contained in:
2025-11-22 11:21:25 +05:00
parent 873e8b050e
commit 30606c7ec1
3 changed files with 18 additions and 59 deletions

View File

@@ -39,19 +39,7 @@ def main():
if start_sh is None:
return
# Run the initial command asynchronously to avoid blocking startup
import threading
def run_initial_command():
try:
subprocess.run(start_sh + ["cli", "--initial"], timeout=10) # Add timeout to prevent hanging
except subprocess.TimeoutExpired:
logger.warning("Initial command timed out after 10 seconds")
except Exception as e:
logger.warning(f"Initial command failed: {e}")
# Start the initial command in a background thread to not block UI startup
initial_thread = threading.Thread(target=run_initial_command, daemon=True)
initial_thread.start()
subprocess.run(start_sh + ["cli", "--initial"])
app = QApplication(sys.argv)
app.setWindowIcon(QIcon.fromTheme(__app_id__))

View File

@@ -416,24 +416,18 @@ class PortProtonAPI:
self._topics_data = []
self.downloader.download_async(self.topics_url, cache_tar, timeout=5, callback=process_tar)
# Instead of blocking, return cached data if available, or empty list
# The actual data will be loaded asynchronously for future calls
if hasattr(self, '_topics_data') and self._topics_data is not None:
return self._topics_data
else:
# Return empty list as fallback to prevent blocking
# The topics data will be loaded asynchronously in the background
logger.warning("Returning empty topics data, async loading in progress")
return []
# Wait for async download to complete if called synchronously
while self._topics_data is None:
time.sleep(0.1)
return self._topics_data
def get_forum_topic_slug(self, game_name: str) -> str:
"""Get the forum topic slug or search URL for a given game name."""
topics = self._load_topics_data()
if topics: # Only search if topics were loaded
normalized_name = normalize_name(game_name)
for topic in topics:
if topic["normalized_title"] == normalized_name:
return topic["slug"]
normalized_name = normalize_name(game_name)
for topic in topics:
if topic["normalized_title"] == normalized_name:
return topic["slug"]
logger.debug("No forum topic found for game: %s, redirecting to search", game_name)
encoded_name = urllib.parse.quote(f"#ppdb {game_name}")
return f"search?q={encoded_name}"

View File

@@ -91,41 +91,18 @@ class VirtualKeyboard(QFrame):
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
def run_shell_command(self, cmd: str) -> str | None:
"""Synchronous shell command execution - kept for backward compatibility"""
process = QProcess(self)
process.start("sh", ["-c", cmd])
# Use a reasonable timeout instead of indefinite wait
if process.waitForFinished(5000): # 5 second timeout
if process.exitCode() == 0:
output_bytes = process.readAllStandardOutput().data()
if isinstance(output_bytes, memoryview):
output_str = output_bytes.tobytes().decode('utf-8').strip()
else:
output_str = output_bytes.decode('utf-8').strip()
return output_str
return None
def run_shell_command_async(self, cmd: str, callback=None):
"""
Run a shell command asynchronously and optionally call a callback with the result.
"""
def on_process_finished(exit_code, exit_status):
if exit_code == 0:
output_bytes = process.readAllStandardOutput().data()
if isinstance(output_bytes, memoryview):
output_str = output_bytes.tobytes().decode('utf-8').strip()
else:
output_str = output_bytes.decode('utf-8').strip()
if callback:
callback(output_str)
process.waitForFinished(-1)
if process.exitCode() == 0:
output_bytes = process.readAllStandardOutput().data()
if isinstance(output_bytes, memoryview):
output_str = output_bytes.tobytes().decode('utf-8').strip()
else:
if callback:
callback(None)
process = QProcess(self)
# Connect the finished signal to handle the result
process.finished.connect(on_process_finished)
process.start("sh", ["-c", cmd])
output_str = output_bytes.decode('utf-8').strip()
return output_str
else:
return None
def get_layouts_setxkbmap(self) -> list[str]:
"""Получаем раскладки, которые используются в системе, возвращаем список вида ['us', 'ru'] и т.п."""