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:
parent
0a046bf936
commit
5812f54877
@ -9,17 +9,29 @@ from PySide6.QtWidgets import QFileDialog, QWidget
|
|||||||
from ..core.config import IS_WINDOWS
|
from ..core.config import IS_WINDOWS
|
||||||
|
|
||||||
|
|
||||||
|
_gtk_cached: bool | None = None
|
||||||
|
|
||||||
def _use_gtk() -> bool:
|
def _use_gtk() -> bool:
|
||||||
|
global _gtk_cached
|
||||||
if IS_WINDOWS:
|
if IS_WINDOWS:
|
||||||
return False
|
return False
|
||||||
|
if _gtk_cached is not None:
|
||||||
|
return _gtk_cached
|
||||||
try:
|
try:
|
||||||
from ..core.db import Database
|
from ..core.db import Database
|
||||||
db = Database()
|
db = Database()
|
||||||
val = db.get_setting("file_dialog_platform")
|
val = db.get_setting("file_dialog_platform")
|
||||||
db.close()
|
db.close()
|
||||||
return val == "gtk"
|
_gtk_cached = val == "gtk"
|
||||||
except Exception:
|
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(
|
def save_file(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user