forked from Boria138/PortProtonQt
Revert "fix: eliminate blocking calls causing startup freezes and UI hangs"
This reverts commit b2a1046f9d.
This commit is contained in:
@@ -39,19 +39,7 @@ def main():
|
|||||||
if start_sh is None:
|
if start_sh is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Run the initial command asynchronously to avoid blocking startup
|
subprocess.run(start_sh + ["cli", "--initial"])
|
||||||
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()
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
app.setWindowIcon(QIcon.fromTheme(__app_id__))
|
app.setWindowIcon(QIcon.fromTheme(__app_id__))
|
||||||
|
|||||||
@@ -416,20 +416,14 @@ class PortProtonAPI:
|
|||||||
self._topics_data = []
|
self._topics_data = []
|
||||||
|
|
||||||
self.downloader.download_async(self.topics_url, cache_tar, timeout=5, callback=process_tar)
|
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
|
# Wait for async download to complete if called synchronously
|
||||||
# The actual data will be loaded asynchronously for future calls
|
while self._topics_data is None:
|
||||||
if hasattr(self, '_topics_data') and self._topics_data is not None:
|
time.sleep(0.1)
|
||||||
return self._topics_data
|
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 []
|
|
||||||
|
|
||||||
def get_forum_topic_slug(self, game_name: str) -> str:
|
def get_forum_topic_slug(self, game_name: str) -> str:
|
||||||
"""Get the forum topic slug or search URL for a given game name."""
|
"""Get the forum topic slug or search URL for a given game name."""
|
||||||
topics = self._load_topics_data()
|
topics = self._load_topics_data()
|
||||||
if topics: # Only search if topics were loaded
|
|
||||||
normalized_name = normalize_name(game_name)
|
normalized_name = normalize_name(game_name)
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
if topic["normalized_title"] == normalized_name:
|
if topic["normalized_title"] == normalized_name:
|
||||||
|
|||||||
@@ -91,11 +91,9 @@ class VirtualKeyboard(QFrame):
|
|||||||
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||||
|
|
||||||
def run_shell_command(self, cmd: str) -> str | None:
|
def run_shell_command(self, cmd: str) -> str | None:
|
||||||
"""Synchronous shell command execution - kept for backward compatibility"""
|
|
||||||
process = QProcess(self)
|
process = QProcess(self)
|
||||||
process.start("sh", ["-c", cmd])
|
process.start("sh", ["-c", cmd])
|
||||||
# Use a reasonable timeout instead of indefinite wait
|
process.waitForFinished(-1)
|
||||||
if process.waitForFinished(5000): # 5 second timeout
|
|
||||||
if process.exitCode() == 0:
|
if process.exitCode() == 0:
|
||||||
output_bytes = process.readAllStandardOutput().data()
|
output_bytes = process.readAllStandardOutput().data()
|
||||||
if isinstance(output_bytes, memoryview):
|
if isinstance(output_bytes, memoryview):
|
||||||
@@ -103,30 +101,9 @@ class VirtualKeyboard(QFrame):
|
|||||||
else:
|
else:
|
||||||
output_str = output_bytes.decode('utf-8').strip()
|
output_str = output_bytes.decode('utf-8').strip()
|
||||||
return output_str
|
return output_str
|
||||||
|
else:
|
||||||
return None
|
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)
|
|
||||||
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])
|
|
||||||
|
|
||||||
def get_layouts_setxkbmap(self) -> list[str]:
|
def get_layouts_setxkbmap(self) -> list[str]:
|
||||||
"""Получаем раскладки, которые используются в системе, возвращаем список вида ['us', 'ru'] и т.п."""
|
"""Получаем раскладки, которые используются в системе, возвращаем список вида ['us', 'ru'] и т.п."""
|
||||||
cmd = r'''localectl status | awk -F: '/X11 Layout/ {gsub(/^[ \t]+/, "", $2); print $2}' '''
|
cmd = r'''localectl status | awk -F: '/X11 Layout/ {gsub(/^[ \t]+/, "", $2); print $2}' '''
|
||||||
|
|||||||
Reference in New Issue
Block a user