Live multi-machine sync: watch files, reconcile, alert on conflicts
Both machines now reflect each other's changes within a couple seconds, and
genuine Syncthing conflicts auto-merge with a backup and an alert.
- sync_watcher.py: QFileSystemWatcher (debounced, re-arms after atomic renames)
emits a single `changed`; the manager decides if it was external.
- library_manager: `reload_from_disk()` re-reads and reconciles disk into memory
(max play/skip counts, newest edit wins, playlist membership unioned), keeping
local unsaved edits and object identity so open views stay valid, then refreshes
the UI without touching the player. `flush()` records each file's (mtime, size)
so our own writes are never mistaken for an external change. New signals
library_reloaded / conflict_resolved.
- conflict_resolver: back up BOTH sides into .resolved/<ts>/{original,incoming}/
before merging, return list[ConflictSummary], add restore_backup(); runs at
startup and live.
- gui/conflict_dialog.py: modeless summary with Open/Restore backup; main_window
shows it from a status-bar notice and preserves scroll+selection on reload.
Tests: tests/test_round16.py (9) + full suite green (225).
This commit is contained in:
+8
-1
@@ -105,8 +105,9 @@ def run_gui(data_dir: Path, files: list[Path], qt_args: list[str] | None = None)
|
||||
from lintunes.gui.main_window import MainWindow
|
||||
from lintunes.gui.track_table import ClickToJumpScrollStyle
|
||||
from lintunes.mpris import setup_mpris
|
||||
from lintunes.sync_watcher import LibrarySyncWatcher
|
||||
|
||||
resolve_conflicts(data_dir)
|
||||
startup_conflicts = resolve_conflicts(data_dir)
|
||||
library = load_library(data_dir)
|
||||
|
||||
app = QApplication([sys.argv[0]] + (qt_args or []))
|
||||
@@ -130,7 +131,13 @@ def run_gui(data_dir: Path, files: list[Path], qt_args: list[str] | None = None)
|
||||
mpris = setup_mpris(window.player, window) # noqa: F841 — keep alive
|
||||
app.aboutToQuit.connect(manager.flush)
|
||||
|
||||
# Watch the data dir so another machine's synced-in changes appear live.
|
||||
watcher = LibrarySyncWatcher(data_dir, window) # noqa: F841 — kept alive by parent
|
||||
watcher.changed.connect(manager.check_for_external_changes)
|
||||
|
||||
window.show()
|
||||
if startup_conflicts:
|
||||
window.show_conflict_summary(startup_conflicts)
|
||||
if files:
|
||||
window.import_files(files)
|
||||
sys.exit(app.exec())
|
||||
|
||||
Reference in New Issue
Block a user