dialogs: cache _use_gtk result instead of creating Database per call

_use_gtk() created a fresh Database instance on every file dialog
open just to read one setting. Now caches the result at module level
after first check. reset_gtk_cache() clears it when the setting
changes.
This commit is contained in:
pax 2026-04-11 22:19:36 -05:00
parent 0a046bf936
commit 5812f54877

View File

@ -9,17 +9,29 @@ from PySide6.QtWidgets import QFileDialog, QWidget
from ..core.config import IS_WINDOWS
_gtk_cached: bool | None = None
def _use_gtk() -> bool:
global _gtk_cached
if IS_WINDOWS:
return False
if _gtk_cached is not None:
return _gtk_cached
try:
from ..core.db import Database
db = Database()
val = db.get_setting("file_dialog_platform")
db.close()
return val == "gtk"
_gtk_cached = val == "gtk"
except Exception:
return False
_gtk_cached = False
return _gtk_cached
def reset_gtk_cache() -> None:
"""Called after settings change so the next dialog picks up the new value."""
global _gtk_cached
_gtk_cached = None
def save_file(