Windows
This commit is contained in:
@@ -127,15 +127,30 @@ class LibraryWatcher:
|
||||
self._full_scan_all()
|
||||
return
|
||||
|
||||
self._observer = Observer()
|
||||
libraries = get_libraries(active_only=True)
|
||||
import sqlite3
|
||||
from local.local_db import DB_PATH
|
||||
conn = sqlite3.connect(str(DB_PATH))
|
||||
conn.row_factory = sqlite3.Row
|
||||
libraries = conn.execute(
|
||||
"SELECT id, path FROM libraries WHERE is_active=1"
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
if not libraries:
|
||||
logger.info("Ingen biblioteker — springer watchdog over")
|
||||
self._running = True
|
||||
return
|
||||
|
||||
# Brug længere poll-interval på Windows for at spare handles
|
||||
import sys
|
||||
poll_interval = 30 if sys.platform == "win32" else 5
|
||||
self._observer = Observer(timeout=poll_interval)
|
||||
|
||||
for lib in libraries:
|
||||
path = Path(lib["path"])
|
||||
if not path.exists():
|
||||
logger.warning(f"Bibliotek findes ikke: {path}")
|
||||
continue
|
||||
|
||||
handler = MusicLibraryHandler(lib["id"], self.on_change)
|
||||
self._observer.schedule(handler, str(path), recursive=True)
|
||||
logger.info(f"Overvåger: {path}")
|
||||
|
||||
@@ -397,13 +397,8 @@ class MainWindow(QMainWindow):
|
||||
from local.file_watcher import get_watcher
|
||||
|
||||
def on_file_change(event_type, path, song_id):
|
||||
# QMetaObject.invokeMethod er den korrekte måde at kalde
|
||||
# en slot fra en ikke-GUI-tråd
|
||||
from PyQt6.QtCore import QMetaObject, Qt
|
||||
QMetaObject.invokeMethod(
|
||||
self._reload_timer, "start",
|
||||
Qt.ConnectionType.QueuedConnection
|
||||
)
|
||||
# Brug signal — den eneste 100% thread-safe metode på Windows
|
||||
self._file_changed_signal.emit()
|
||||
|
||||
watcher = get_watcher(on_change=on_file_change)
|
||||
watcher.start()
|
||||
@@ -436,7 +431,8 @@ class MainWindow(QMainWindow):
|
||||
QTimer.singleShot(200, self._reload_library)
|
||||
|
||||
# Signal til at opdatere biblioteket fra baggrundstråd
|
||||
_library_loaded = __import__('PyQt6.QtCore', fromlist=['pyqtSignal']).pyqtSignal(list)
|
||||
_library_loaded = __import__('PyQt6.QtCore', fromlist=['pyqtSignal']).pyqtSignal(list)
|
||||
_file_changed_signal = __import__('PyQt6.QtCore', fromlist=['pyqtSignal']).pyqtSignal()
|
||||
|
||||
def _reload_library(self):
|
||||
"""Hent sange fra DB i baggrundstråd — thread-safe via signal."""
|
||||
|
||||
Reference in New Issue
Block a user